Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_arm64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 29 | #include "linker/arm64/relative_patcher_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 32 | #include "lock_word.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 33 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 34 | #include "thread.h" |
| 35 | #include "utils/arm64/assembler_arm64.h" |
| 36 | #include "utils/assembler.h" |
| 37 | #include "utils/stack_checks.h" |
| 38 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 39 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 40 | using vixl::ExactAssemblyScope; |
| 41 | using vixl::CodeBufferCheckScope; |
| 42 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 43 | |
| 44 | #ifdef __ |
| 45 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 46 | #endif |
| 47 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | namespace art { |
| 49 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 50 | template<class MirrorType> |
| 51 | class GcRoot; |
| 52 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace arm64 { |
| 54 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 55 | using helpers::ARM64EncodableConstantOrRegister; |
| 56 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 57 | using helpers::CPURegisterFrom; |
| 58 | using helpers::DRegisterFrom; |
| 59 | using helpers::FPRegisterFrom; |
| 60 | using helpers::HeapOperand; |
| 61 | using helpers::HeapOperandFrom; |
| 62 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 63 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 64 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 65 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 66 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 67 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::LocationFrom; |
| 70 | using helpers::OperandFromMemOperand; |
| 71 | using helpers::OutputCPURegister; |
| 72 | using helpers::OutputFPRegister; |
| 73 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 74 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 75 | using helpers::RegisterFrom; |
| 76 | using helpers::StackOperandFrom; |
| 77 | using helpers::VIXLRegCodeFromART; |
| 78 | using helpers::WRegisterFrom; |
| 79 | using helpers::XRegisterFrom; |
| 80 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 81 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 82 | // 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] | 83 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 84 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 85 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 86 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 87 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 88 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 89 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 90 | // the offset explicitly. |
| 91 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 92 | |
| 93 | // 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] | 94 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 95 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 96 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 97 | |
| 98 | // Some instructions have special requirements for a temporary, for example |
| 99 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 100 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 101 | // loads with large offsets need a fixed register to limit the number of link-time |
| 102 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 103 | // register that's neither callee-save nor an argument register. We choose x15. |
| 104 | inline Location FixedTempLocation() { |
| 105 | return Location::RegisterLocation(x15.GetCode()); |
| 106 | } |
| 107 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 108 | inline Condition ARM64Condition(IfCondition cond) { |
| 109 | switch (cond) { |
| 110 | case kCondEQ: return eq; |
| 111 | case kCondNE: return ne; |
| 112 | case kCondLT: return lt; |
| 113 | case kCondLE: return le; |
| 114 | case kCondGT: return gt; |
| 115 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 116 | case kCondB: return lo; |
| 117 | case kCondBE: return ls; |
| 118 | case kCondA: return hi; |
| 119 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 120 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 121 | LOG(FATAL) << "Unreachable"; |
| 122 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 125 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 126 | // The ARM64 condition codes can express all the necessary branches, see the |
| 127 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 128 | // There is no dex instruction or HIR that would need the missing conditions |
| 129 | // "equal or unordered" or "not equal". |
| 130 | switch (cond) { |
| 131 | case kCondEQ: return eq; |
| 132 | case kCondNE: return ne /* unordered */; |
| 133 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 134 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 135 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 136 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 137 | default: |
| 138 | LOG(FATAL) << "UNREACHABLE"; |
| 139 | UNREACHABLE(); |
| 140 | } |
| 141 | } |
| 142 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 143 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 144 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 145 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 146 | // but we use the exact registers for clarity. |
| 147 | if (return_type == Primitive::kPrimFloat) { |
| 148 | return LocationFrom(s0); |
| 149 | } else if (return_type == Primitive::kPrimDouble) { |
| 150 | return LocationFrom(d0); |
| 151 | } else if (return_type == Primitive::kPrimLong) { |
| 152 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 153 | } else if (return_type == Primitive::kPrimVoid) { |
| 154 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 155 | } else { |
| 156 | return LocationFrom(w0); |
| 157 | } |
| 158 | } |
| 159 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 160 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 161 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 164 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 165 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 166 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 167 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 168 | // Calculate memory accessing operand for save/restore live registers. |
| 169 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 170 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 171 | int64_t spill_offset, |
| 172 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 173 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 174 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 175 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 176 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 177 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 178 | codegen->GetNumberOfFloatingPointRegisters())); |
| 179 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 180 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 181 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 182 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 183 | |
| 184 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 185 | UseScratchRegisterScope temps(masm); |
| 186 | |
| 187 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 188 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 189 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 190 | int64_t reg_size = kXRegSizeInBytes; |
| 191 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 192 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 193 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 194 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 195 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 196 | // to compute the base address(float point registers spill base address). |
| 197 | Register new_base = temps.AcquireSameSizeAs(base); |
| 198 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 199 | base = new_base; |
| 200 | spill_offset = -core_spill_size; |
| 201 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 202 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 203 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 204 | } |
| 205 | |
| 206 | if (is_save) { |
| 207 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 208 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 209 | } else { |
| 210 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 211 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 216 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 217 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 218 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 219 | // If the register holds an object, update the stack mask. |
| 220 | if (locations->RegisterContainsObject(i)) { |
| 221 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 222 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 223 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 224 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 225 | saved_core_stack_offsets_[i] = stack_offset; |
| 226 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 227 | } |
| 228 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 229 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 230 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 231 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 232 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 233 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 234 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 235 | } |
| 236 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 237 | SaveRestoreLiveRegistersHelper(codegen, |
| 238 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 239 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 240 | } |
| 241 | |
| 242 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 243 | SaveRestoreLiveRegistersHelper(codegen, |
| 244 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 245 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 246 | } |
| 247 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 248 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 249 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 250 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 252 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 253 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 254 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 255 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 256 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 257 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 258 | // Live registers will be restored in the catch block if caught. |
| 259 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 260 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 261 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 262 | // move resolver. |
| 263 | InvokeRuntimeCallingConvention calling_convention; |
| 264 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 265 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 266 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 267 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 268 | ? kQuickThrowStringBounds |
| 269 | : kQuickThrowArrayBounds; |
| 270 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 271 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 272 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 275 | bool IsFatal() const OVERRIDE { return true; } |
| 276 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 277 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 278 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 279 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 280 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 281 | }; |
| 282 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 283 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 284 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 285 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 286 | |
| 287 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 288 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 289 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 290 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 291 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 294 | bool IsFatal() const OVERRIDE { return true; } |
| 295 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 296 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 297 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 298 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 300 | }; |
| 301 | |
| 302 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 303 | public: |
| 304 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 305 | HInstruction* at, |
| 306 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 307 | bool do_clinit, |
| 308 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 309 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 310 | : SlowPathCodeARM64(at), |
| 311 | cls_(cls), |
| 312 | dex_pc_(dex_pc), |
| 313 | do_clinit_(do_clinit), |
| 314 | bss_entry_temp_(bss_entry_temp), |
| 315 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 316 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 317 | } |
| 318 | |
| 319 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 320 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 321 | Location out = locations->Out(); |
| 322 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 323 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 324 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 325 | InvokeRuntimeCallingConvention calling_convention; |
| 326 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 327 | // 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] | 328 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 329 | bool is_load_class_bss_entry = |
| 330 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 331 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 332 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 333 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 334 | DCHECK( |
| 335 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 338 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 339 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 340 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 341 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 342 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 343 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 344 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 345 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 346 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 347 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 348 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 349 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 350 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 351 | |
| 352 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 353 | if (out.IsValid()) { |
| 354 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 355 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 356 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 357 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 358 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 359 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 360 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 361 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 362 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 363 | if (call_saves_everything_except_r0_ip0) { |
| 364 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 365 | } else { |
| 366 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 367 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 368 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 369 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 370 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 371 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 372 | { |
| 373 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 374 | __ Bind(strp_label); |
| 375 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 376 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 377 | } |
| 378 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 379 | __ B(GetExitLabel()); |
| 380 | } |
| 381 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 383 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 384 | private: |
| 385 | // The class this slow path will load. |
| 386 | HLoadClass* const cls_; |
| 387 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 388 | // The dex PC of `at_`. |
| 389 | const uint32_t dex_pc_; |
| 390 | |
| 391 | // Whether to initialize the class. |
| 392 | const bool do_clinit_; |
| 393 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 394 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 395 | vixl::aarch64::Register bss_entry_temp_; |
| 396 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 397 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 398 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 399 | }; |
| 400 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 401 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 402 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 403 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 404 | : SlowPathCodeARM64(instruction), |
| 405 | temp_(temp), |
| 406 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 407 | |
| 408 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 409 | LocationSummary* locations = instruction_->GetLocations(); |
| 410 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 411 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 412 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 413 | InvokeRuntimeCallingConvention calling_convention; |
| 414 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 415 | DCHECK(temp_.IsValid()); |
| 416 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 417 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 418 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 419 | __ Bind(GetEntryLabel()); |
| 420 | SaveLiveRegisters(codegen, locations); |
| 421 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 422 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 423 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 424 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 425 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 426 | Primitive::Type type = instruction_->GetType(); |
| 427 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 428 | |
| 429 | RestoreLiveRegisters(codegen, locations); |
| 430 | |
| 431 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 432 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 433 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 434 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 435 | } else { |
| 436 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 437 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 438 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 439 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 440 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 441 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 442 | { |
| 443 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 444 | __ Bind(strp_label); |
| 445 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 446 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | __ B(GetExitLabel()); |
| 450 | } |
| 451 | |
| 452 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 453 | |
| 454 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 455 | const Register temp_; |
| 456 | vixl::aarch64::Label* adrp_label_; |
| 457 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 458 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 459 | }; |
| 460 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 461 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 462 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 463 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 464 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 465 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 466 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 467 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 468 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 469 | // Live registers will be restored in the catch block if caught. |
| 470 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 471 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 472 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 473 | instruction_, |
| 474 | instruction_->GetDexPc(), |
| 475 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 476 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 479 | bool IsFatal() const OVERRIDE { return true; } |
| 480 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 481 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 482 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 483 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 484 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 485 | }; |
| 486 | |
| 487 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 488 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 489 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 490 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 491 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 492 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 493 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 494 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 495 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 496 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 497 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 498 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 499 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 500 | if (successor_ == nullptr) { |
| 501 | __ B(GetReturnLabel()); |
| 502 | } else { |
| 503 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 504 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 505 | } |
| 506 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 507 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 508 | DCHECK(successor_ == nullptr); |
| 509 | return &return_label_; |
| 510 | } |
| 511 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 512 | HBasicBlock* GetSuccessor() const { |
| 513 | return successor_; |
| 514 | } |
| 515 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 516 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 517 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 518 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 519 | // If not null, the block to branch to after the suspend check. |
| 520 | HBasicBlock* const successor_; |
| 521 | |
| 522 | // 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] | 523 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 524 | |
| 525 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 526 | }; |
| 527 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 528 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 529 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 530 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 531 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 532 | |
| 533 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 534 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 535 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 536 | DCHECK(instruction_->IsCheckCast() |
| 537 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 538 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 539 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 540 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 541 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 542 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 543 | if (!is_fatal_) { |
| 544 | SaveLiveRegisters(codegen, locations); |
| 545 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 546 | |
| 547 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 548 | // move resolver. |
| 549 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 550 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 551 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 552 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 553 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 554 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 555 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 556 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 557 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 558 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 559 | Primitive::Type ret_type = instruction_->GetType(); |
| 560 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 561 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 562 | } else { |
| 563 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 564 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 565 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 568 | if (!is_fatal_) { |
| 569 | RestoreLiveRegisters(codegen, locations); |
| 570 | __ B(GetExitLabel()); |
| 571 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 574 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 575 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 576 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 577 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 578 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 579 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 580 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 581 | }; |
| 582 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 583 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 584 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 585 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 586 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 587 | |
| 588 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 589 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 590 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 591 | LocationSummary* locations = instruction_->GetLocations(); |
| 592 | SaveLiveRegisters(codegen, locations); |
| 593 | InvokeRuntimeCallingConvention calling_convention; |
| 594 | __ Mov(calling_convention.GetRegisterAt(0), |
| 595 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 596 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 597 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 600 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 601 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 602 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 603 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 604 | }; |
| 605 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 606 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 607 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 608 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 609 | |
| 610 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 611 | LocationSummary* locations = instruction_->GetLocations(); |
| 612 | __ Bind(GetEntryLabel()); |
| 613 | SaveLiveRegisters(codegen, locations); |
| 614 | |
| 615 | InvokeRuntimeCallingConvention calling_convention; |
| 616 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 617 | parallel_move.AddMove( |
| 618 | locations->InAt(0), |
| 619 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 620 | Primitive::kPrimNot, |
| 621 | nullptr); |
| 622 | parallel_move.AddMove( |
| 623 | locations->InAt(1), |
| 624 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 625 | Primitive::kPrimInt, |
| 626 | nullptr); |
| 627 | parallel_move.AddMove( |
| 628 | locations->InAt(2), |
| 629 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 630 | Primitive::kPrimNot, |
| 631 | nullptr); |
| 632 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 633 | |
| 634 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 635 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 636 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 637 | RestoreLiveRegisters(codegen, locations); |
| 638 | __ B(GetExitLabel()); |
| 639 | } |
| 640 | |
| 641 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 642 | |
| 643 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 644 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 645 | }; |
| 646 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 647 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 648 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 649 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 650 | |
| 651 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 652 | // 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] | 653 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 654 | num_entries * sizeof(int32_t), |
| 655 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 656 | |
| 657 | __ Bind(&table_start_); |
| 658 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 659 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 660 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 661 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 662 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 663 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 664 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 665 | Literal<int32_t> literal(jump_offset); |
| 666 | __ place(&literal); |
| 667 | } |
| 668 | } |
| 669 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 670 | // Abstract base class for read barrier slow paths marking a reference |
| 671 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 672 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 673 | // Argument `entrypoint` must be a register location holding the read |
| 674 | // barrier marking runtime entry point to be invoked. |
| 675 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 676 | protected: |
| 677 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 678 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 679 | DCHECK(kEmitCompilerReadBarrier); |
| 680 | } |
| 681 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 682 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 683 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 684 | // Generate assembly code calling the read barrier marking runtime |
| 685 | // entry point (ReadBarrierMarkRegX). |
| 686 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 687 | // No need to save live registers; it's taken care of by the |
| 688 | // entrypoint. Also, there is no need to update the stack mask, |
| 689 | // as this runtime call will not trigger a garbage collection. |
| 690 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 691 | DCHECK_NE(ref_.reg(), LR); |
| 692 | DCHECK_NE(ref_.reg(), WSP); |
| 693 | DCHECK_NE(ref_.reg(), WZR); |
| 694 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 695 | // as a temporary, it cannot be the entry point's input/output. |
| 696 | DCHECK_NE(ref_.reg(), IP0); |
| 697 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 698 | // "Compact" slow path, saving two moves. |
| 699 | // |
| 700 | // Instead of using the standard runtime calling convention (input |
| 701 | // and output in W0): |
| 702 | // |
| 703 | // W0 <- ref |
| 704 | // W0 <- ReadBarrierMark(W0) |
| 705 | // ref <- W0 |
| 706 | // |
| 707 | // we just use rX (the register containing `ref`) as input and output |
| 708 | // of a dedicated entrypoint: |
| 709 | // |
| 710 | // rX <- ReadBarrierMarkRegX(rX) |
| 711 | // |
| 712 | if (entrypoint_.IsValid()) { |
| 713 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 714 | __ Blr(XRegisterFrom(entrypoint_)); |
| 715 | } else { |
| 716 | // Entrypoint is not already loaded, load from the thread. |
| 717 | int32_t entry_point_offset = |
| 718 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 719 | // This runtime call does not require a stack map. |
| 720 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // The location (register) of the marked object reference. |
| 725 | const Location ref_; |
| 726 | |
| 727 | // The location of the entrypoint if it is already loaded. |
| 728 | const Location entrypoint_; |
| 729 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 730 | private: |
| 731 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 732 | }; |
| 733 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 734 | // Slow path marking an object reference `ref` during a read |
| 735 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 736 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 737 | // |
| 738 | // This means that after the execution of this slow path, `ref` will |
| 739 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 740 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 741 | // probably still be a from-space reference (unless it gets updated by |
| 742 | // another thread, or if another thread installed another object |
| 743 | // reference (different from `ref`) in `obj.field`). |
| 744 | // |
| 745 | // If `entrypoint` is a valid location it is assumed to already be |
| 746 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 747 | // 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] | 748 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 749 | public: |
| 750 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 751 | Location ref, |
| 752 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 753 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 754 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 758 | |
| 759 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 760 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 761 | DCHECK(locations->CanCall()); |
| 762 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 763 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 764 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 765 | << "Unexpected instruction in read barrier marking slow path: " |
| 766 | << instruction_->DebugName(); |
| 767 | |
| 768 | __ Bind(GetEntryLabel()); |
| 769 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 770 | __ B(GetExitLabel()); |
| 771 | } |
| 772 | |
| 773 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 774 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 775 | }; |
| 776 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 777 | // Slow path loading `obj`'s lock word, loading a reference from |
| 778 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 779 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 780 | // read barrier). The field `obj.field` in the object `obj` holding |
| 781 | // this reference does not get updated by this slow path after marking |
| 782 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 783 | // below for that). |
| 784 | // |
| 785 | // This means that after the execution of this slow path, `ref` will |
| 786 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 787 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 788 | // probably still be a from-space reference (unless it gets updated by |
| 789 | // another thread, or if another thread installed another object |
| 790 | // reference (different from `ref`) in `obj.field`). |
| 791 | // |
| 792 | // Argument `entrypoint` must be a register location holding the read |
| 793 | // barrier marking runtime entry point to be invoked. |
| 794 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 795 | public: |
| 796 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 797 | Location ref, |
| 798 | Register obj, |
| 799 | uint32_t offset, |
| 800 | Location index, |
| 801 | size_t scale_factor, |
| 802 | bool needs_null_check, |
| 803 | bool use_load_acquire, |
| 804 | Register temp, |
| 805 | Location entrypoint) |
| 806 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 807 | obj_(obj), |
| 808 | offset_(offset), |
| 809 | index_(index), |
| 810 | scale_factor_(scale_factor), |
| 811 | needs_null_check_(needs_null_check), |
| 812 | use_load_acquire_(use_load_acquire), |
| 813 | temp_(temp) { |
| 814 | DCHECK(kEmitCompilerReadBarrier); |
| 815 | DCHECK(kUseBakerReadBarrier); |
| 816 | } |
| 817 | |
| 818 | const char* GetDescription() const OVERRIDE { |
| 819 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 820 | } |
| 821 | |
| 822 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 823 | LocationSummary* locations = instruction_->GetLocations(); |
| 824 | DCHECK(locations->CanCall()); |
| 825 | DCHECK(ref_.IsRegister()) << ref_; |
| 826 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 827 | DCHECK(obj_.IsW()); |
| 828 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 829 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 830 | instruction_->IsStaticFieldGet() || |
| 831 | instruction_->IsArrayGet() || |
| 832 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 833 | instruction_->IsInstanceOf() || |
| 834 | instruction_->IsCheckCast() || |
| 835 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 836 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 837 | << "Unexpected instruction in read barrier marking slow path: " |
| 838 | << instruction_->DebugName(); |
| 839 | // The read barrier instrumentation of object ArrayGet |
| 840 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 841 | // instruction. |
| 842 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 843 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 844 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 845 | // Temporary register `temp_`, used to store the lock word, must |
| 846 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 847 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 848 | // need the lock word to still be in `temp_` after the reference |
| 849 | // load. |
| 850 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 851 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 852 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 853 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 854 | |
| 855 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 856 | // inserted after the original load. However, in fast path based |
| 857 | // Baker's read barriers, we need to perform the load of |
| 858 | // mirror::Object::monitor_ *before* the original reference load. |
| 859 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 860 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 861 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 862 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 863 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 864 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 865 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 866 | // if (is_gray) { |
| 867 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 868 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 869 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 870 | // Note: the original implementation in ReadBarrier::Barrier is |
| 871 | // slightly more complex as it performs additional checks that we do |
| 872 | // not do here for performance reasons. |
| 873 | |
| 874 | // /* int32_t */ monitor = obj->monitor_ |
| 875 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 876 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 877 | if (needs_null_check_) { |
| 878 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 879 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 880 | // /* LockWord */ lock_word = LockWord(monitor) |
| 881 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 882 | "art::LockWord and int32_t have different sizes."); |
| 883 | |
| 884 | // Introduce a dependency on the lock_word including rb_state, |
| 885 | // to prevent load-load reordering, and without using |
| 886 | // a memory barrier (which would be more expensive). |
| 887 | // `obj` is unchanged by this operation, but its value now depends |
| 888 | // on `temp`. |
| 889 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 890 | |
| 891 | // The actual reference load. |
| 892 | // A possible implicit null check has already been handled above. |
| 893 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 894 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 895 | ref_, |
| 896 | obj_, |
| 897 | offset_, |
| 898 | index_, |
| 899 | scale_factor_, |
| 900 | /* needs_null_check */ false, |
| 901 | use_load_acquire_); |
| 902 | |
| 903 | // Mark the object `ref` when `obj` is gray. |
| 904 | // |
| 905 | // if (rb_state == ReadBarrier::GrayState()) |
| 906 | // ref = ReadBarrier::Mark(ref); |
| 907 | // |
| 908 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 909 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 910 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 911 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 912 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 913 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 914 | __ B(GetExitLabel()); |
| 915 | } |
| 916 | |
| 917 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | // The register containing the object holding the marked object reference field. |
| 919 | Register obj_; |
| 920 | // The offset, index and scale factor to access the reference in `obj_`. |
| 921 | uint32_t offset_; |
| 922 | Location index_; |
| 923 | size_t scale_factor_; |
| 924 | // Is a null check required? |
| 925 | bool needs_null_check_; |
| 926 | // Should this reference load use Load-Acquire semantics? |
| 927 | bool use_load_acquire_; |
| 928 | // A temporary register used to hold the lock word of `obj_`. |
| 929 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 930 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 931 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 932 | }; |
| 933 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 934 | // Slow path loading `obj`'s lock word, loading a reference from |
| 935 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 936 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 937 | // read barrier). If needed, this slow path also atomically updates |
| 938 | // the field `obj.field` in the object `obj` holding this reference |
| 939 | // after marking (contrary to |
| 940 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 941 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 942 | // |
| 943 | // This means that after the execution of this slow path, both `ref` |
| 944 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 945 | // hold the same to-space reference (unless another thread installed |
| 946 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 947 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 948 | // Argument `entrypoint` must be a register location holding the read |
| 949 | // barrier marking runtime entry point to be invoked. |
| 950 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 951 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 952 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 953 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 954 | Location ref, |
| 955 | Register obj, |
| 956 | uint32_t offset, |
| 957 | Location index, |
| 958 | size_t scale_factor, |
| 959 | bool needs_null_check, |
| 960 | bool use_load_acquire, |
| 961 | Register temp, |
| 962 | Location entrypoint) |
| 963 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 964 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 965 | offset_(offset), |
| 966 | index_(index), |
| 967 | scale_factor_(scale_factor), |
| 968 | needs_null_check_(needs_null_check), |
| 969 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 970 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 971 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 972 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 976 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 980 | LocationSummary* locations = instruction_->GetLocations(); |
| 981 | Register ref_reg = WRegisterFrom(ref_); |
| 982 | DCHECK(locations->CanCall()); |
| 983 | DCHECK(ref_.IsRegister()) << ref_; |
| 984 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 985 | DCHECK(obj_.IsW()); |
| 986 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 987 | |
| 988 | // 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] | 989 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 990 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 991 | << instruction_->DebugName(); |
| 992 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 993 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 994 | DCHECK_EQ(offset_, 0u); |
| 995 | DCHECK_EQ(scale_factor_, 0u); |
| 996 | DCHECK_EQ(use_load_acquire_, false); |
| 997 | // The location of the offset of the marked reference field within `obj_`. |
| 998 | Location field_offset = index_; |
| 999 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 1000 | |
| 1001 | // Temporary register `temp_`, used to store the lock word, must |
| 1002 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1003 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1004 | // need the lock word to still be in `temp_` after the reference |
| 1005 | // load. |
| 1006 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1007 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1008 | |
| 1009 | __ Bind(GetEntryLabel()); |
| 1010 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1011 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1012 | // |
| 1013 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1014 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1015 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1016 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1017 | // if (is_gray) { |
| 1018 | // old_ref = ref; |
| 1019 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1020 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1021 | // } |
| 1022 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1023 | // /* int32_t */ monitor = obj->monitor_ |
| 1024 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1025 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1026 | if (needs_null_check_) { |
| 1027 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1028 | } |
| 1029 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1030 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1031 | "art::LockWord and int32_t have different sizes."); |
| 1032 | |
| 1033 | // Introduce a dependency on the lock_word including rb_state, |
| 1034 | // to prevent load-load reordering, and without using |
| 1035 | // a memory barrier (which would be more expensive). |
| 1036 | // `obj` is unchanged by this operation, but its value now depends |
| 1037 | // on `temp`. |
| 1038 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1039 | |
| 1040 | // The actual reference load. |
| 1041 | // A possible implicit null check has already been handled above. |
| 1042 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1043 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1044 | ref_, |
| 1045 | obj_, |
| 1046 | offset_, |
| 1047 | index_, |
| 1048 | scale_factor_, |
| 1049 | /* needs_null_check */ false, |
| 1050 | use_load_acquire_); |
| 1051 | |
| 1052 | // Mark the object `ref` when `obj` is gray. |
| 1053 | // |
| 1054 | // if (rb_state == ReadBarrier::GrayState()) |
| 1055 | // ref = ReadBarrier::Mark(ref); |
| 1056 | // |
| 1057 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1058 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1059 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1060 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1061 | |
| 1062 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1063 | // Note that we cannot use IP to save the old reference, as IP is |
| 1064 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1065 | // need the old reference after the call to that entry point. |
| 1066 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1067 | __ Mov(temp_.W(), ref_reg); |
| 1068 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1069 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1070 | |
| 1071 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1072 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1073 | // |
| 1074 | // Note that this field could also hold a different object, if |
| 1075 | // another thread had concurrently changed it. In that case, the |
| 1076 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1077 | // (CAS) operation below would abort the CAS, leaving the field |
| 1078 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1079 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1080 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1081 | |
| 1082 | // Update the the holder's field atomically. This may fail if |
| 1083 | // mutator updates before us, but it's OK. This is achieved |
| 1084 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1085 | // memory synchronization ordering, where the expected value is |
| 1086 | // the old reference and the desired value is the new reference. |
| 1087 | |
| 1088 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1089 | UseScratchRegisterScope temps(masm); |
| 1090 | |
| 1091 | // Convenience aliases. |
| 1092 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1093 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1094 | Register expected = temp_.W(); |
| 1095 | Register value = ref_reg; |
| 1096 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1097 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1098 | |
| 1099 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1100 | |
| 1101 | if (kPoisonHeapReferences) { |
| 1102 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1103 | if (value.Is(expected)) { |
| 1104 | // Do not poison `value`, as it is the same register as |
| 1105 | // `expected`, which has just been poisoned. |
| 1106 | } else { |
| 1107 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | // do { |
| 1112 | // tmp_value = [tmp_ptr] - expected; |
| 1113 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1114 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1115 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1116 | __ Bind(&loop_head); |
| 1117 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1118 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1119 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1120 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1121 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1122 | __ B(&exit_loop); |
| 1123 | __ Bind(&comparison_failed); |
| 1124 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1125 | __ Bind(&exit_loop); |
| 1126 | |
| 1127 | if (kPoisonHeapReferences) { |
| 1128 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1129 | if (value.Is(expected)) { |
| 1130 | // Do not unpoison `value`, as it is the same register as |
| 1131 | // `expected`, which has just been unpoisoned. |
| 1132 | } else { |
| 1133 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1137 | __ B(GetExitLabel()); |
| 1138 | } |
| 1139 | |
| 1140 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1141 | // The register containing the object holding the marked object reference field. |
| 1142 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1143 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1144 | uint32_t offset_; |
| 1145 | Location index_; |
| 1146 | size_t scale_factor_; |
| 1147 | // Is a null check required? |
| 1148 | bool needs_null_check_; |
| 1149 | // Should this reference load use Load-Acquire semantics? |
| 1150 | bool use_load_acquire_; |
| 1151 | // A temporary register used to hold the lock word of `obj_`; and |
| 1152 | // also to hold the original reference value, when the reference is |
| 1153 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1154 | const Register temp_; |
| 1155 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1156 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1157 | }; |
| 1158 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1159 | // Slow path generating a read barrier for a heap reference. |
| 1160 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1161 | public: |
| 1162 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1163 | Location out, |
| 1164 | Location ref, |
| 1165 | Location obj, |
| 1166 | uint32_t offset, |
| 1167 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1168 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1169 | out_(out), |
| 1170 | ref_(ref), |
| 1171 | obj_(obj), |
| 1172 | offset_(offset), |
| 1173 | index_(index) { |
| 1174 | DCHECK(kEmitCompilerReadBarrier); |
| 1175 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1176 | // has been overwritten by (or after) the heap object reference load |
| 1177 | // to be instrumented, e.g.: |
| 1178 | // |
| 1179 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1180 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1181 | // |
| 1182 | // In that case, we have lost the information about the original |
| 1183 | // object, and the emitted read barrier cannot work properly. |
| 1184 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1185 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1186 | } |
| 1187 | |
| 1188 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1189 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1190 | LocationSummary* locations = instruction_->GetLocations(); |
| 1191 | Primitive::Type type = Primitive::kPrimNot; |
| 1192 | DCHECK(locations->CanCall()); |
| 1193 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1194 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1195 | instruction_->IsStaticFieldGet() || |
| 1196 | instruction_->IsArrayGet() || |
| 1197 | instruction_->IsInstanceOf() || |
| 1198 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1199 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1200 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1201 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1202 | // The read barrier instrumentation of object ArrayGet |
| 1203 | // instructions does not support the HIntermediateAddress |
| 1204 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1205 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1206 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1207 | |
| 1208 | __ Bind(GetEntryLabel()); |
| 1209 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1210 | SaveLiveRegisters(codegen, locations); |
| 1211 | |
| 1212 | // We may have to change the index's value, but as `index_` is a |
| 1213 | // constant member (like other "inputs" of this slow path), |
| 1214 | // introduce a copy of it, `index`. |
| 1215 | Location index = index_; |
| 1216 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1217 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1218 | if (instruction_->IsArrayGet()) { |
| 1219 | // Compute the actual memory offset and store it in `index`. |
| 1220 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1221 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1222 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1223 | // We are about to change the value of `index_reg` (see the |
| 1224 | // calls to vixl::MacroAssembler::Lsl and |
| 1225 | // vixl::MacroAssembler::Mov below), but it has |
| 1226 | // not been saved by the previous call to |
| 1227 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1228 | // callee-save register -- |
| 1229 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1230 | // callee-save registers, as it has been designed with the |
| 1231 | // assumption that callee-save registers are supposed to be |
| 1232 | // handled by the called function. So, as a callee-save |
| 1233 | // register, `index_reg` _would_ eventually be saved onto |
| 1234 | // the stack, but it would be too late: we would have |
| 1235 | // changed its value earlier. Therefore, we manually save |
| 1236 | // it here into another freely available register, |
| 1237 | // `free_reg`, chosen of course among the caller-save |
| 1238 | // registers (as a callee-save `free_reg` register would |
| 1239 | // exhibit the same problem). |
| 1240 | // |
| 1241 | // Note we could have requested a temporary register from |
| 1242 | // the register allocator instead; but we prefer not to, as |
| 1243 | // this is a slow path, and we know we can find a |
| 1244 | // caller-save register that is available. |
| 1245 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1246 | __ Mov(free_reg.W(), index_reg); |
| 1247 | index_reg = free_reg; |
| 1248 | index = LocationFrom(index_reg); |
| 1249 | } else { |
| 1250 | // The initial register stored in `index_` has already been |
| 1251 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1252 | // (as it is not a callee-save register), so we can freely |
| 1253 | // use it. |
| 1254 | } |
| 1255 | // Shifting the index value contained in `index_reg` by the scale |
| 1256 | // factor (2) cannot overflow in practice, as the runtime is |
| 1257 | // unable to allocate object arrays with a size larger than |
| 1258 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1259 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1260 | static_assert( |
| 1261 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1262 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1263 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1264 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1265 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1266 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1267 | // (as in the case of ArrayGet), as it is actually an offset |
| 1268 | // to an object field within an object. |
| 1269 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1270 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1271 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1272 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1273 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1274 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1275 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | // We're moving two or three locations to locations that could |
| 1280 | // overlap, so we need a parallel move resolver. |
| 1281 | InvokeRuntimeCallingConvention calling_convention; |
| 1282 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1283 | parallel_move.AddMove(ref_, |
| 1284 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1285 | type, |
| 1286 | nullptr); |
| 1287 | parallel_move.AddMove(obj_, |
| 1288 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1289 | type, |
| 1290 | nullptr); |
| 1291 | if (index.IsValid()) { |
| 1292 | parallel_move.AddMove(index, |
| 1293 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1294 | Primitive::kPrimInt, |
| 1295 | nullptr); |
| 1296 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1297 | } else { |
| 1298 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1299 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1300 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1301 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1302 | instruction_, |
| 1303 | instruction_->GetDexPc(), |
| 1304 | this); |
| 1305 | CheckEntrypointTypes< |
| 1306 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1307 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1308 | |
| 1309 | RestoreLiveRegisters(codegen, locations); |
| 1310 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1311 | __ B(GetExitLabel()); |
| 1312 | } |
| 1313 | |
| 1314 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1315 | |
| 1316 | private: |
| 1317 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1318 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1319 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1320 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1321 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1322 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1323 | } |
| 1324 | } |
| 1325 | // We shall never fail to find a free caller-save register, as |
| 1326 | // there are more than two core caller-save registers on ARM64 |
| 1327 | // (meaning it is possible to find one which is different from |
| 1328 | // `ref` and `obj`). |
| 1329 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1330 | LOG(FATAL) << "Could not find a free register"; |
| 1331 | UNREACHABLE(); |
| 1332 | } |
| 1333 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1334 | const Location out_; |
| 1335 | const Location ref_; |
| 1336 | const Location obj_; |
| 1337 | const uint32_t offset_; |
| 1338 | // An additional location containing an index to an array. |
| 1339 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1340 | // UnsafeGetObjectVolatile intrinsics. |
| 1341 | const Location index_; |
| 1342 | |
| 1343 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1344 | }; |
| 1345 | |
| 1346 | // Slow path generating a read barrier for a GC root. |
| 1347 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1348 | public: |
| 1349 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1350 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1351 | DCHECK(kEmitCompilerReadBarrier); |
| 1352 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1353 | |
| 1354 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1355 | LocationSummary* locations = instruction_->GetLocations(); |
| 1356 | Primitive::Type type = Primitive::kPrimNot; |
| 1357 | DCHECK(locations->CanCall()); |
| 1358 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1359 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1360 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1361 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1362 | |
| 1363 | __ Bind(GetEntryLabel()); |
| 1364 | SaveLiveRegisters(codegen, locations); |
| 1365 | |
| 1366 | InvokeRuntimeCallingConvention calling_convention; |
| 1367 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1368 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1369 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1370 | // thus we need a 64-bit move here, and we cannot use |
| 1371 | // |
| 1372 | // arm64_codegen->MoveLocation( |
| 1373 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1374 | // root_, |
| 1375 | // type); |
| 1376 | // |
| 1377 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1378 | // reference type (`Primitive::kPrimNot`). |
| 1379 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1380 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1381 | instruction_, |
| 1382 | instruction_->GetDexPc(), |
| 1383 | this); |
| 1384 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1385 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1386 | |
| 1387 | RestoreLiveRegisters(codegen, locations); |
| 1388 | __ B(GetExitLabel()); |
| 1389 | } |
| 1390 | |
| 1391 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1392 | |
| 1393 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1394 | const Location out_; |
| 1395 | const Location root_; |
| 1396 | |
| 1397 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1398 | }; |
| 1399 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1400 | #undef __ |
| 1401 | |
| 1402 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1403 | Location next_location; |
| 1404 | if (type == Primitive::kPrimVoid) { |
| 1405 | LOG(FATAL) << "Unreachable type " << type; |
| 1406 | } |
| 1407 | |
| 1408 | if (Primitive::IsFloatingPointType(type) && |
| 1409 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1410 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1411 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1412 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1413 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1414 | } else { |
| 1415 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1416 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1417 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1418 | } |
| 1419 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1420 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1421 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1422 | return next_location; |
| 1423 | } |
| 1424 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1425 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1426 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1429 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1430 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1431 | const CompilerOptions& compiler_options, |
| 1432 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1433 | : CodeGenerator(graph, |
| 1434 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1435 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1436 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1437 | callee_saved_core_registers.GetList(), |
| 1438 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1439 | compiler_options, |
| 1440 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1441 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1442 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1443 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1444 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1445 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1446 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1447 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1448 | uint32_literals_(std::less<uint32_t>(), |
| 1449 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1450 | uint64_literals_(std::less<uint64_t>(), |
| 1451 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1452 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1453 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1454 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1455 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1456 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1457 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1458 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1459 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1460 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1461 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1462 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1463 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1464 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1465 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1466 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1467 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1468 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1469 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1470 | jump_table->EmitTable(this); |
| 1471 | } |
| 1472 | } |
| 1473 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1474 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1475 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1476 | // Ensure we emit the literal pool. |
| 1477 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1478 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1479 | CodeGenerator::Finalize(allocator); |
| 1480 | } |
| 1481 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1482 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1483 | // Note: There are 6 kinds of moves: |
| 1484 | // 1. constant -> GPR/FPR (non-cycle) |
| 1485 | // 2. constant -> stack (non-cycle) |
| 1486 | // 3. GPR/FPR -> GPR/FPR |
| 1487 | // 4. GPR/FPR -> stack |
| 1488 | // 5. stack -> GPR/FPR |
| 1489 | // 6. stack -> stack (non-cycle) |
| 1490 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1491 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1492 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1493 | // dependency. |
| 1494 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1495 | } |
| 1496 | |
| 1497 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1498 | vixl_temps_.Close(); |
| 1499 | } |
| 1500 | |
| 1501 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1502 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1503 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1504 | || kind == Location::kSIMDStackSlot); |
| 1505 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1506 | ? Location::kFpuRegister |
| 1507 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1508 | Location scratch = GetScratchLocation(kind); |
| 1509 | if (!scratch.Equals(Location::NoLocation())) { |
| 1510 | return scratch; |
| 1511 | } |
| 1512 | // Allocate from VIXL temp registers. |
| 1513 | if (kind == Location::kRegister) { |
| 1514 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1515 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1516 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1517 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1518 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1519 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1520 | } |
| 1521 | AddScratchLocation(scratch); |
| 1522 | return scratch; |
| 1523 | } |
| 1524 | |
| 1525 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1526 | if (loc.IsRegister()) { |
| 1527 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1528 | } else { |
| 1529 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1530 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1531 | } |
| 1532 | RemoveScratchLocation(loc); |
| 1533 | } |
| 1534 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1535 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1536 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1537 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1540 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1541 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1542 | __ Bind(&frame_entry_label_); |
| 1543 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1544 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1545 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1546 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1547 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1548 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1549 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1550 | { |
| 1551 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1552 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1553 | kInstructionSize, |
| 1554 | CodeBufferCheckScope::kExactSize); |
| 1555 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1556 | RecordPcInfo(nullptr, 0); |
| 1557 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1558 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1559 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1560 | if (!HasEmptyFrame()) { |
| 1561 | int frame_size = GetFrameSize(); |
| 1562 | // Stack layout: |
| 1563 | // sp[frame_size - 8] : lr. |
| 1564 | // ... : other preserved core registers. |
| 1565 | // ... : other preserved fp registers. |
| 1566 | // ... : reserved frame space. |
| 1567 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1568 | |
| 1569 | // Save the current method if we need it. Note that we do not |
| 1570 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1571 | // in the SSA graph. |
| 1572 | if (RequiresCurrentMethod()) { |
| 1573 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1574 | } else { |
| 1575 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1576 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1577 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1578 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1579 | frame_size - GetCoreSpillSize()); |
| 1580 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1581 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1582 | |
| 1583 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1584 | // Initialize should_deoptimize flag to 0. |
| 1585 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1586 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1587 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1588 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1592 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1593 | if (!HasEmptyFrame()) { |
| 1594 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1595 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1596 | frame_size - FrameEntrySpillSize()); |
| 1597 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1598 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1599 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1600 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1601 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1602 | __ Ret(); |
| 1603 | GetAssembler()->cfi().RestoreState(); |
| 1604 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1605 | } |
| 1606 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1607 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1608 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1609 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1610 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1611 | } |
| 1612 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1613 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1614 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1615 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1616 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1617 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1618 | } |
| 1619 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1620 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1621 | __ Bind(GetLabelOf(block)); |
| 1622 | } |
| 1623 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1624 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1625 | DCHECK(location.IsRegister()); |
| 1626 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1627 | } |
| 1628 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1629 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1630 | if (location.IsRegister()) { |
| 1631 | locations->AddTemp(location); |
| 1632 | } else { |
| 1633 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1634 | } |
| 1635 | } |
| 1636 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1637 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1638 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1639 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1640 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1641 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1642 | if (value_can_be_null) { |
| 1643 | __ Cbz(value, &done); |
| 1644 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1645 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1646 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1647 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1648 | if (value_can_be_null) { |
| 1649 | __ Bind(&done); |
| 1650 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1651 | } |
| 1652 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1653 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1654 | // Blocked core registers: |
| 1655 | // lr : Runtime reserved. |
| 1656 | // tr : Runtime reserved. |
| 1657 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1658 | // ip1 : VIXL core temp. |
| 1659 | // ip0 : VIXL core temp. |
| 1660 | // |
| 1661 | // Blocked fp registers: |
| 1662 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1663 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1664 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1665 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1666 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1667 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1668 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1669 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1670 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1671 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1672 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1673 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1674 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1675 | // Stubs do not save callee-save floating point registers. If the graph |
| 1676 | // is debuggable, we need to deal with these registers differently. For |
| 1677 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1678 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1679 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1680 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1681 | } |
| 1682 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1683 | } |
| 1684 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1685 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1686 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1687 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1688 | return kArm64WordSize; |
| 1689 | } |
| 1690 | |
| 1691 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1692 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1693 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1694 | return kArm64WordSize; |
| 1695 | } |
| 1696 | |
| 1697 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1698 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1699 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1700 | return kArm64WordSize; |
| 1701 | } |
| 1702 | |
| 1703 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1704 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1705 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1706 | return kArm64WordSize; |
| 1707 | } |
| 1708 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1709 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1710 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1714 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1717 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1718 | if (constant->IsIntConstant()) { |
| 1719 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1720 | } else if (constant->IsLongConstant()) { |
| 1721 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1722 | } else if (constant->IsNullConstant()) { |
| 1723 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1724 | } else if (constant->IsFloatConstant()) { |
| 1725 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1726 | } else { |
| 1727 | DCHECK(constant->IsDoubleConstant()); |
| 1728 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1729 | } |
| 1730 | } |
| 1731 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1732 | |
| 1733 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1734 | DCHECK(constant.IsConstant()); |
| 1735 | HConstant* cst = constant.GetConstant(); |
| 1736 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1737 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1738 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1739 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1740 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1741 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1742 | } |
| 1743 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1744 | // Allocate a scratch register from the VIXL pool, querying first |
| 1745 | // the floating-point register pool, and then the core register |
| 1746 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1747 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1748 | // using a different allocation strategy. |
| 1749 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1750 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1751 | int size_in_bits) { |
| 1752 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1753 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1754 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1755 | } |
| 1756 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1757 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1758 | Location source, |
| 1759 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1760 | if (source.Equals(destination)) { |
| 1761 | return; |
| 1762 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1763 | |
| 1764 | // A valid move can always be inferred from the destination and source |
| 1765 | // locations. When moving from and to a register, the argument type can be |
| 1766 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1767 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1768 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1769 | |
| 1770 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1771 | if (unspecified_type) { |
| 1772 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1773 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1774 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1775 | || src_cst->IsFloatConstant() |
| 1776 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1777 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1778 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1779 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1780 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1781 | // type is appropriate. Else the source is a register, and since the |
| 1782 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1783 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1784 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1785 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1786 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1787 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1788 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1789 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1790 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1791 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1792 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1793 | } else if (source.IsSIMDStackSlot()) { |
| 1794 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1795 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1796 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1797 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1798 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1799 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1800 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1801 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1802 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1803 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1804 | ? Primitive::kPrimLong |
| 1805 | : Primitive::kPrimInt; |
| 1806 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1807 | } |
| 1808 | } else { |
| 1809 | DCHECK(source.IsFpuRegister()); |
| 1810 | if (destination.IsRegister()) { |
| 1811 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1812 | ? Primitive::kPrimDouble |
| 1813 | : Primitive::kPrimFloat; |
| 1814 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1815 | } else { |
| 1816 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1817 | if (GetGraph()->HasSIMD()) { |
| 1818 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1819 | } else { |
| 1820 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | } else if (destination.IsSIMDStackSlot()) { |
| 1825 | if (source.IsFpuRegister()) { |
| 1826 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1827 | } else { |
| 1828 | DCHECK(source.IsSIMDStackSlot()); |
| 1829 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1830 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1831 | Register temp = temps.AcquireX(); |
| 1832 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1833 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1834 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1835 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1836 | } else { |
| 1837 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1838 | __ Ldr(temp, StackOperandFrom(source)); |
| 1839 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1840 | } |
| 1841 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1842 | } else { // The destination is not a register. It must be a stack slot. |
| 1843 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1844 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1845 | if (unspecified_type) { |
| 1846 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1847 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1848 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1849 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1850 | } |
| 1851 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1852 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1853 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1854 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1855 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1856 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1857 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1858 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1859 | HConstant* src_cst = source.GetConstant(); |
| 1860 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1861 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1862 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1863 | ? Register(xzr) |
| 1864 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1865 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1866 | if (src_cst->IsIntConstant()) { |
| 1867 | temp = temps.AcquireW(); |
| 1868 | } else if (src_cst->IsLongConstant()) { |
| 1869 | temp = temps.AcquireX(); |
| 1870 | } else if (src_cst->IsFloatConstant()) { |
| 1871 | temp = temps.AcquireS(); |
| 1872 | } else { |
| 1873 | DCHECK(src_cst->IsDoubleConstant()); |
| 1874 | temp = temps.AcquireD(); |
| 1875 | } |
| 1876 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1877 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1878 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1879 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1880 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1881 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1882 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1883 | // Use any scratch register (a core or a floating-point one) |
| 1884 | // from VIXL scratch register pools as a temporary. |
| 1885 | // |
| 1886 | // We used to only use the FP scratch register pool, but in some |
| 1887 | // rare cases the only register from this pool (D31) would |
| 1888 | // already be used (e.g. within a ParallelMove instruction, when |
| 1889 | // a move is blocked by a another move requiring a scratch FP |
| 1890 | // register, which would reserve D31). To prevent this issue, we |
| 1891 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1892 | // |
| 1893 | // Also, we start by asking for a FP scratch register first, as the |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1894 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1895 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1896 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1897 | // allocates core scratch registers first. |
| 1898 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1899 | GetVIXLAssembler(), |
| 1900 | &temps, |
| 1901 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1902 | __ Ldr(temp, StackOperandFrom(source)); |
| 1903 | __ Str(temp, StackOperandFrom(destination)); |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1909 | CPURegister dst, |
| 1910 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1911 | switch (type) { |
| 1912 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1913 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1914 | break; |
| 1915 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1916 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1917 | break; |
| 1918 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1919 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1920 | break; |
| 1921 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1922 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | case Primitive::kPrimInt: |
| 1925 | case Primitive::kPrimNot: |
| 1926 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1927 | case Primitive::kPrimFloat: |
| 1928 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1929 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1930 | __ Ldr(dst, src); |
| 1931 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1932 | case Primitive::kPrimVoid: |
| 1933 | LOG(FATAL) << "Unreachable type " << type; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1937 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1938 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1939 | const MemOperand& src, |
| 1940 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1941 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1942 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1943 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1944 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1945 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1946 | DCHECK(!src.IsPreIndex()); |
| 1947 | DCHECK(!src.IsPostIndex()); |
| 1948 | |
| 1949 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1950 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1951 | { |
| 1952 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1953 | MemOperand base = MemOperand(temp_base); |
| 1954 | switch (type) { |
| 1955 | case Primitive::kPrimBoolean: |
| 1956 | { |
| 1957 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1958 | __ ldarb(Register(dst), base); |
| 1959 | if (needs_null_check) { |
| 1960 | MaybeRecordImplicitNullCheck(instruction); |
| 1961 | } |
| 1962 | } |
| 1963 | break; |
| 1964 | case Primitive::kPrimByte: |
| 1965 | { |
| 1966 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1967 | __ ldarb(Register(dst), base); |
| 1968 | if (needs_null_check) { |
| 1969 | MaybeRecordImplicitNullCheck(instruction); |
| 1970 | } |
| 1971 | } |
| 1972 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1973 | break; |
| 1974 | case Primitive::kPrimChar: |
| 1975 | { |
| 1976 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1977 | __ ldarh(Register(dst), base); |
| 1978 | if (needs_null_check) { |
| 1979 | MaybeRecordImplicitNullCheck(instruction); |
| 1980 | } |
| 1981 | } |
| 1982 | break; |
| 1983 | case Primitive::kPrimShort: |
| 1984 | { |
| 1985 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1986 | __ ldarh(Register(dst), base); |
| 1987 | if (needs_null_check) { |
| 1988 | MaybeRecordImplicitNullCheck(instruction); |
| 1989 | } |
| 1990 | } |
| 1991 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1992 | break; |
| 1993 | case Primitive::kPrimInt: |
| 1994 | case Primitive::kPrimNot: |
| 1995 | case Primitive::kPrimLong: |
| 1996 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 1997 | { |
| 1998 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1999 | __ ldar(Register(dst), base); |
| 2000 | if (needs_null_check) { |
| 2001 | MaybeRecordImplicitNullCheck(instruction); |
| 2002 | } |
| 2003 | } |
| 2004 | break; |
| 2005 | case Primitive::kPrimFloat: |
| 2006 | case Primitive::kPrimDouble: { |
| 2007 | DCHECK(dst.IsFPRegister()); |
| 2008 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2009 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2010 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2011 | { |
| 2012 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2013 | __ ldar(temp, base); |
| 2014 | if (needs_null_check) { |
| 2015 | MaybeRecordImplicitNullCheck(instruction); |
| 2016 | } |
| 2017 | } |
| 2018 | __ Fmov(FPRegister(dst), temp); |
| 2019 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2020 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2021 | case Primitive::kPrimVoid: |
| 2022 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2023 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2024 | } |
| 2025 | } |
| 2026 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2027 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2028 | CPURegister src, |
| 2029 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2030 | switch (type) { |
| 2031 | case Primitive::kPrimBoolean: |
| 2032 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2033 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2034 | break; |
| 2035 | case Primitive::kPrimChar: |
| 2036 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2037 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2038 | break; |
| 2039 | case Primitive::kPrimInt: |
| 2040 | case Primitive::kPrimNot: |
| 2041 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2042 | case Primitive::kPrimFloat: |
| 2043 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2044 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2045 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2046 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2047 | case Primitive::kPrimVoid: |
| 2048 | LOG(FATAL) << "Unreachable type " << type; |
| 2049 | } |
| 2050 | } |
| 2051 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2052 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2053 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2054 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2055 | const MemOperand& dst, |
| 2056 | bool needs_null_check) { |
| 2057 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2058 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2059 | Register temp_base = temps.AcquireX(); |
| 2060 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2061 | DCHECK(!dst.IsPreIndex()); |
| 2062 | DCHECK(!dst.IsPostIndex()); |
| 2063 | |
| 2064 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2065 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2066 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2067 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2068 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2069 | switch (type) { |
| 2070 | case Primitive::kPrimBoolean: |
| 2071 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2072 | { |
| 2073 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2074 | __ stlrb(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::kPrimChar: |
| 2081 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2082 | { |
| 2083 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2084 | __ stlrh(Register(src), base); |
| 2085 | if (needs_null_check) { |
| 2086 | MaybeRecordImplicitNullCheck(instruction); |
| 2087 | } |
| 2088 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | case Primitive::kPrimInt: |
| 2091 | case Primitive::kPrimNot: |
| 2092 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2093 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2094 | { |
| 2095 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2096 | __ stlr(Register(src), base); |
| 2097 | if (needs_null_check) { |
| 2098 | MaybeRecordImplicitNullCheck(instruction); |
| 2099 | } |
| 2100 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | case Primitive::kPrimFloat: |
| 2103 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2104 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2105 | Register temp_src; |
| 2106 | if (src.IsZero()) { |
| 2107 | // The zero register is used to avoid synthesizing zero constants. |
| 2108 | temp_src = Register(src); |
| 2109 | } else { |
| 2110 | DCHECK(src.IsFPRegister()); |
| 2111 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2112 | __ Fmov(temp_src, FPRegister(src)); |
| 2113 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2114 | { |
| 2115 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2116 | __ stlr(temp_src, base); |
| 2117 | if (needs_null_check) { |
| 2118 | MaybeRecordImplicitNullCheck(instruction); |
| 2119 | } |
| 2120 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2121 | break; |
| 2122 | } |
| 2123 | case Primitive::kPrimVoid: |
| 2124 | LOG(FATAL) << "Unreachable type " << type; |
| 2125 | } |
| 2126 | } |
| 2127 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2128 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2129 | HInstruction* instruction, |
| 2130 | uint32_t dex_pc, |
| 2131 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2132 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2133 | |
| 2134 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2135 | { |
| 2136 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2137 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2138 | __ blr(lr); |
| 2139 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2140 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2141 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2142 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2145 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2146 | HInstruction* instruction, |
| 2147 | SlowPathCode* slow_path) { |
| 2148 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2149 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2150 | __ Blr(lr); |
| 2151 | } |
| 2152 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2153 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2154 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2155 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2156 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2157 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2158 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2159 | // 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] | 2160 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2161 | __ Add(temp, class_reg, status_offset); |
| 2162 | __ Ldar(temp, HeapOperand(temp)); |
| 2163 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2164 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2165 | __ Bind(slow_path->GetExitLabel()); |
| 2166 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2167 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2168 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2169 | BarrierType type = BarrierAll; |
| 2170 | |
| 2171 | switch (kind) { |
| 2172 | case MemBarrierKind::kAnyAny: |
| 2173 | case MemBarrierKind::kAnyStore: { |
| 2174 | type = BarrierAll; |
| 2175 | break; |
| 2176 | } |
| 2177 | case MemBarrierKind::kLoadAny: { |
| 2178 | type = BarrierReads; |
| 2179 | break; |
| 2180 | } |
| 2181 | case MemBarrierKind::kStoreStore: { |
| 2182 | type = BarrierWrites; |
| 2183 | break; |
| 2184 | } |
| 2185 | default: |
| 2186 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2187 | } |
| 2188 | __ Dmb(InnerShareable, type); |
| 2189 | } |
| 2190 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2191 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2192 | HBasicBlock* successor) { |
| 2193 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2194 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2195 | if (slow_path == nullptr) { |
| 2196 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2197 | instruction->SetSlowPath(slow_path); |
| 2198 | codegen_->AddSlowPath(slow_path); |
| 2199 | if (successor != nullptr) { |
| 2200 | DCHECK(successor->IsLoopHeader()); |
| 2201 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2202 | } |
| 2203 | } else { |
| 2204 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2205 | } |
| 2206 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2207 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2208 | Register temp = temps.AcquireW(); |
| 2209 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2210 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2211 | if (successor == nullptr) { |
| 2212 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2213 | __ Bind(slow_path->GetReturnLabel()); |
| 2214 | } else { |
| 2215 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2216 | __ B(slow_path->GetEntryLabel()); |
| 2217 | // slow_path will return to GetLabelOf(successor). |
| 2218 | } |
| 2219 | } |
| 2220 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2221 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2222 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2223 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2224 | assembler_(codegen->GetAssembler()), |
| 2225 | codegen_(codegen) {} |
| 2226 | |
| 2227 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2228 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2229 | |
| 2230 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2231 | |
| 2232 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2233 | // Using a base helps identify when we hit such breakpoints. |
| 2234 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2235 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2236 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2237 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2238 | }; |
| 2239 | |
| 2240 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2241 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2242 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2243 | } \ |
| 2244 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2245 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2246 | locations->SetOut(Location::Any()); \ |
| 2247 | } |
| 2248 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2249 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2250 | |
| 2251 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2252 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2253 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2254 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2255 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2256 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2257 | Primitive::Type type = instr->GetResultType(); |
| 2258 | switch (type) { |
| 2259 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2260 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2261 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2262 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2264 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2265 | |
| 2266 | case Primitive::kPrimFloat: |
| 2267 | case Primitive::kPrimDouble: |
| 2268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2269 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2270 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2271 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2272 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2273 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2274 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2278 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2279 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2280 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2281 | |
| 2282 | bool object_field_get_with_read_barrier = |
| 2283 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2284 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2285 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2286 | object_field_get_with_read_barrier ? |
| 2287 | LocationSummary::kCallOnSlowPath : |
| 2288 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2289 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2290 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2291 | // We need a temporary register for the read barrier marking slow |
| 2292 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2293 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2294 | !Runtime::Current()->UseJitCompilation() && |
| 2295 | !field_info.IsVolatile()) { |
| 2296 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2297 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2298 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2299 | locations->AddTemp(FixedTempLocation()); |
| 2300 | } |
| 2301 | } else { |
| 2302 | locations->AddTemp(Location::RequiresRegister()); |
| 2303 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2304 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2306 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2307 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2308 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2309 | // The output overlaps for an object field get when read barriers |
| 2310 | // are enabled: we do not want the load to overwrite the object's |
| 2311 | // location, as we need it to emit the read barrier. |
| 2312 | locations->SetOut( |
| 2313 | Location::RequiresRegister(), |
| 2314 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2319 | const FieldInfo& field_info) { |
| 2320 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2321 | LocationSummary* locations = instruction->GetLocations(); |
| 2322 | Location base_loc = locations->InAt(0); |
| 2323 | Location out = locations->Out(); |
| 2324 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2325 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2326 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2327 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2328 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2329 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2330 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2331 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2332 | Location maybe_temp = |
| 2333 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2334 | // Note that potential implicit null checks are handled in this |
| 2335 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2336 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2337 | instruction, |
| 2338 | out, |
| 2339 | base, |
| 2340 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2341 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2342 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2343 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2344 | } else { |
| 2345 | // General case. |
| 2346 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2347 | // Note that a potential implicit null check is handled in this |
| 2348 | // CodeGeneratorARM64::LoadAcquire call. |
| 2349 | // NB: LoadAcquire will record the pc info if needed. |
| 2350 | codegen_->LoadAcquire( |
| 2351 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2352 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2353 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2354 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2355 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2356 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2357 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2358 | if (field_type == Primitive::kPrimNot) { |
| 2359 | // If read barriers are enabled, emit read barriers other than |
| 2360 | // Baker's using a slow path (and also unpoison the loaded |
| 2361 | // reference, if heap poisoning is enabled). |
| 2362 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2363 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2364 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2368 | LocationSummary* locations = |
| 2369 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2370 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2371 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2372 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2373 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2374 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2375 | } else { |
| 2376 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2381 | const FieldInfo& field_info, |
| 2382 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2383 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2384 | |
| 2385 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2386 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2387 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2388 | Offset offset = field_info.GetFieldOffset(); |
| 2389 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2390 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2391 | { |
| 2392 | // We use a block to end the scratch scope before the write barrier, thus |
| 2393 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2394 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2395 | |
| 2396 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2397 | DCHECK(value.IsW()); |
| 2398 | Register temp = temps.AcquireW(); |
| 2399 | __ Mov(temp, value.W()); |
| 2400 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2401 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2402 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2403 | |
| 2404 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2405 | codegen_->StoreRelease( |
| 2406 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2407 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2408 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2409 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2410 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2411 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2412 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2416 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2420 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2421 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2422 | |
| 2423 | switch (type) { |
| 2424 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2425 | case Primitive::kPrimLong: { |
| 2426 | Register dst = OutputRegister(instr); |
| 2427 | Register lhs = InputRegisterAt(instr, 0); |
| 2428 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2429 | if (instr->IsAdd()) { |
| 2430 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2431 | } else if (instr->IsAnd()) { |
| 2432 | __ And(dst, lhs, rhs); |
| 2433 | } else if (instr->IsOr()) { |
| 2434 | __ Orr(dst, lhs, rhs); |
| 2435 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2436 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2437 | } else if (instr->IsRor()) { |
| 2438 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2439 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2440 | __ Ror(dst, lhs, shift); |
| 2441 | } else { |
| 2442 | // Ensure shift distance is in the same size register as the result. If |
| 2443 | // we are rotating a long and the shift comes in a w register originally, |
| 2444 | // we don't need to sxtw for use as an x since the shift distances are |
| 2445 | // all & reg_bits - 1. |
| 2446 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2447 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2448 | } else { |
| 2449 | DCHECK(instr->IsXor()); |
| 2450 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2451 | } |
| 2452 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2453 | } |
| 2454 | case Primitive::kPrimFloat: |
| 2455 | case Primitive::kPrimDouble: { |
| 2456 | FPRegister dst = OutputFPRegister(instr); |
| 2457 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2458 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2459 | if (instr->IsAdd()) { |
| 2460 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2461 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2462 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2463 | } else { |
| 2464 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2465 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2466 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2467 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2468 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2469 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2473 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2474 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2475 | |
| 2476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2477 | Primitive::Type type = instr->GetResultType(); |
| 2478 | switch (type) { |
| 2479 | case Primitive::kPrimInt: |
| 2480 | case Primitive::kPrimLong: { |
| 2481 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2482 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2483 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | } |
| 2486 | default: |
| 2487 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2492 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2493 | |
| 2494 | Primitive::Type type = instr->GetType(); |
| 2495 | switch (type) { |
| 2496 | case Primitive::kPrimInt: |
| 2497 | case Primitive::kPrimLong: { |
| 2498 | Register dst = OutputRegister(instr); |
| 2499 | Register lhs = InputRegisterAt(instr, 0); |
| 2500 | Operand rhs = InputOperandAt(instr, 1); |
| 2501 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2502 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2503 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2504 | if (instr->IsShl()) { |
| 2505 | __ Lsl(dst, lhs, shift_value); |
| 2506 | } else if (instr->IsShr()) { |
| 2507 | __ Asr(dst, lhs, shift_value); |
| 2508 | } else { |
| 2509 | __ Lsr(dst, lhs, shift_value); |
| 2510 | } |
| 2511 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2512 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2513 | |
| 2514 | if (instr->IsShl()) { |
| 2515 | __ Lsl(dst, lhs, rhs_reg); |
| 2516 | } else if (instr->IsShr()) { |
| 2517 | __ Asr(dst, lhs, rhs_reg); |
| 2518 | } else { |
| 2519 | __ Lsr(dst, lhs, rhs_reg); |
| 2520 | } |
| 2521 | } |
| 2522 | break; |
| 2523 | } |
| 2524 | default: |
| 2525 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2526 | } |
| 2527 | } |
| 2528 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2529 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2530 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2534 | HandleBinaryOp(instruction); |
| 2535 | } |
| 2536 | |
| 2537 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2538 | HandleBinaryOp(instruction); |
| 2539 | } |
| 2540 | |
| 2541 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2542 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2545 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2546 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2547 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2548 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2549 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2550 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2551 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2552 | } |
| 2553 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2554 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2555 | Register dst = OutputRegister(instr); |
| 2556 | Register lhs = InputRegisterAt(instr, 0); |
| 2557 | Register rhs = InputRegisterAt(instr, 1); |
| 2558 | |
| 2559 | switch (instr->GetOpKind()) { |
| 2560 | case HInstruction::kAnd: |
| 2561 | __ Bic(dst, lhs, rhs); |
| 2562 | break; |
| 2563 | case HInstruction::kOr: |
| 2564 | __ Orn(dst, lhs, rhs); |
| 2565 | break; |
| 2566 | case HInstruction::kXor: |
| 2567 | __ Eon(dst, lhs, rhs); |
| 2568 | break; |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unreachable"; |
| 2571 | } |
| 2572 | } |
| 2573 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2574 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2575 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2576 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2577 | instruction->GetType() == Primitive::kPrimLong); |
| 2578 | LocationSummary* locations = |
| 2579 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2580 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2581 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2582 | } else { |
| 2583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2584 | } |
| 2585 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2586 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2587 | } |
| 2588 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2589 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2590 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2591 | Primitive::Type type = instruction->GetType(); |
| 2592 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2593 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2594 | Register out = OutputRegister(instruction); |
| 2595 | Register left; |
| 2596 | if (kind != HInstruction::kNeg) { |
| 2597 | left = InputRegisterAt(instruction, 0); |
| 2598 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2599 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2600 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2601 | // conversion) can have a different type from the current instruction's type, |
| 2602 | // so we manually indicate the type. |
| 2603 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2604 | Operand right_operand(0); |
| 2605 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2606 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2607 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2608 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2609 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2610 | right_operand = Operand(right_reg, |
| 2611 | helpers::ShiftFromOpKind(op_kind), |
| 2612 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | // Logical binary operations do not support extension operations in the |
| 2616 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2617 | // the extension as a separate instruction. |
| 2618 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2619 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2620 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2621 | kind != HInstruction::kNeg)); |
| 2622 | switch (kind) { |
| 2623 | case HInstruction::kAdd: |
| 2624 | __ Add(out, left, right_operand); |
| 2625 | break; |
| 2626 | case HInstruction::kAnd: |
| 2627 | __ And(out, left, right_operand); |
| 2628 | break; |
| 2629 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2630 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2631 | __ Neg(out, right_operand); |
| 2632 | break; |
| 2633 | case HInstruction::kOr: |
| 2634 | __ Orr(out, left, right_operand); |
| 2635 | break; |
| 2636 | case HInstruction::kSub: |
| 2637 | __ Sub(out, left, right_operand); |
| 2638 | break; |
| 2639 | case HInstruction::kXor: |
| 2640 | __ Eor(out, left, right_operand); |
| 2641 | break; |
| 2642 | default: |
| 2643 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2644 | UNREACHABLE(); |
| 2645 | } |
| 2646 | } |
| 2647 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2648 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2649 | LocationSummary* locations = |
| 2650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2652 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2656 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2657 | __ Add(OutputRegister(instruction), |
| 2658 | InputRegisterAt(instruction, 0), |
| 2659 | Operand(InputOperandAt(instruction, 1))); |
| 2660 | } |
| 2661 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2662 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2663 | LocationSummary* locations = |
| 2664 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2665 | |
| 2666 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2667 | |
| 2668 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2669 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2670 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2671 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2672 | // loop. |
| 2673 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2674 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2675 | : Location::RequiresRegister()); |
| 2676 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2677 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2678 | } |
| 2679 | |
| 2680 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2681 | HIntermediateAddressIndex* instruction) { |
| 2682 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2683 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2684 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2685 | |
| 2686 | if (shift == 0) { |
| 2687 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2688 | } else { |
| 2689 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2690 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2691 | } |
| 2692 | } |
| 2693 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2694 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2695 | LocationSummary* locations = |
| 2696 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2697 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2698 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2699 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2700 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2701 | // Don't allocate register for Mneg instruction. |
| 2702 | } else { |
| 2703 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2704 | Location::RequiresRegister()); |
| 2705 | } |
| 2706 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2707 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2708 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2709 | } |
| 2710 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2711 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2712 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2713 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2714 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2715 | |
| 2716 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2717 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2718 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2719 | if (instr->GetType() == Primitive::kPrimLong && |
| 2720 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2721 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2722 | vixl::aarch64::Instruction* prev = |
| 2723 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2724 | if (prev->IsLoadOrStore()) { |
| 2725 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2726 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2727 | __ nop(); |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2732 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2733 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2734 | } else { |
| 2735 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2736 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2737 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2738 | __ Mneg(res, mul_left, mul_right); |
| 2739 | } else { |
| 2740 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2741 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2742 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2743 | } |
| 2744 | } |
| 2745 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2746 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2747 | bool object_array_get_with_read_barrier = |
| 2748 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2749 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2750 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2751 | object_array_get_with_read_barrier ? |
| 2752 | LocationSummary::kCallOnSlowPath : |
| 2753 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2754 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2755 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2756 | // We need a temporary register for the read barrier marking slow |
| 2757 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2758 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2759 | !Runtime::Current()->UseJitCompilation() && |
| 2760 | instruction->GetIndex()->IsConstant()) { |
| 2761 | // Array loads with constant index are treated as field loads. |
| 2762 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2763 | // constant index loads we need a temporary only if the offset is too big. |
| 2764 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2765 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2766 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2767 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2768 | locations->AddTemp(FixedTempLocation()); |
| 2769 | } |
| 2770 | } else { |
| 2771 | locations->AddTemp(Location::RequiresRegister()); |
| 2772 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2773 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2774 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2775 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2776 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2777 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2778 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2779 | // The output overlaps in the case of an object array get with |
| 2780 | // read barriers enabled: we do not want the move to overwrite the |
| 2781 | // array's location, as we need it to emit the read barrier. |
| 2782 | locations->SetOut( |
| 2783 | Location::RequiresRegister(), |
| 2784 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2785 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2789 | Primitive::Type type = instruction->GetType(); |
| 2790 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2791 | LocationSummary* locations = instruction->GetLocations(); |
| 2792 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2793 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2794 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2795 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2796 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2797 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2798 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2799 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2800 | // The read barrier instrumentation of object ArrayGet instructions |
| 2801 | // does not support the HIntermediateAddress instruction. |
| 2802 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2803 | instruction->GetArray()->IsIntermediateAddress() && |
| 2804 | kEmitCompilerReadBarrier)); |
| 2805 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2806 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2807 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2808 | // Note that a potential implicit null check is handled in the |
| 2809 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2810 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2811 | if (index.IsConstant()) { |
| 2812 | // Array load with a constant index can be treated as a field load. |
| 2813 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2814 | Location maybe_temp = |
| 2815 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2816 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2817 | out, |
| 2818 | obj.W(), |
| 2819 | offset, |
| 2820 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2821 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2822 | /* use_load_acquire */ false); |
| 2823 | } else { |
| 2824 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2825 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2826 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2827 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2828 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2829 | // General case. |
| 2830 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2831 | Register length; |
| 2832 | if (maybe_compressed_char_at) { |
| 2833 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2834 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2835 | { |
| 2836 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2837 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2838 | |
| 2839 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2840 | DCHECK_LT(count_offset, offset); |
| 2841 | int64_t adjusted_offset = |
| 2842 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2843 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2844 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2845 | } else { |
| 2846 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2847 | } |
| 2848 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2849 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2850 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2851 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2852 | if (maybe_compressed_char_at) { |
| 2853 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2854 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2855 | "Expecting 0=compressed, 1=uncompressed"); |
| 2856 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2857 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2858 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2859 | __ B(&done); |
| 2860 | __ Bind(&uncompressed_load); |
| 2861 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2862 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2863 | __ Bind(&done); |
| 2864 | } else { |
| 2865 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2866 | source = HeapOperand(obj, offset); |
| 2867 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2868 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2869 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2870 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2871 | // We do not need to compute the intermediate address from the array: the |
| 2872 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2873 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2874 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2875 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2876 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2877 | } |
| 2878 | temp = obj; |
| 2879 | } else { |
| 2880 | __ Add(temp, obj, offset); |
| 2881 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2882 | if (maybe_compressed_char_at) { |
| 2883 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2884 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2885 | "Expecting 0=compressed, 1=uncompressed"); |
| 2886 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2887 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2888 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2889 | __ B(&done); |
| 2890 | __ Bind(&uncompressed_load); |
| 2891 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2892 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2893 | __ Bind(&done); |
| 2894 | } else { |
| 2895 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2896 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2897 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2898 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2899 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2900 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2901 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2902 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2903 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2904 | |
| 2905 | if (type == Primitive::kPrimNot) { |
| 2906 | static_assert( |
| 2907 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2908 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2909 | Location obj_loc = locations->InAt(0); |
| 2910 | if (index.IsConstant()) { |
| 2911 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2912 | } else { |
| 2913 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2914 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2915 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2916 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2919 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2920 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2921 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2922 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2926 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2927 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2928 | { |
| 2929 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2930 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2931 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2932 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2933 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2934 | // Mask out compression flag from String's array length. |
| 2935 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2936 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2937 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2938 | } |
| 2939 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2940 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2941 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2942 | |
| 2943 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2944 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2945 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2946 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2947 | LocationSummary::kCallOnSlowPath : |
| 2948 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2949 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2950 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2951 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2952 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2953 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2954 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2955 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2956 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2961 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2962 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2963 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2964 | bool needs_write_barrier = |
| 2965 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2966 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2967 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2968 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2969 | CPURegister source = value; |
| 2970 | Location index = locations->InAt(1); |
| 2971 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2972 | MemOperand destination = HeapOperand(array); |
| 2973 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2974 | |
| 2975 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2976 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2977 | if (index.IsConstant()) { |
| 2978 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2979 | destination = HeapOperand(array, offset); |
| 2980 | } else { |
| 2981 | UseScratchRegisterScope temps(masm); |
| 2982 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2983 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2984 | // We do not need to compute the intermediate address from the array: the |
| 2985 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2986 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2987 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2988 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2989 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2990 | } |
| 2991 | temp = array; |
| 2992 | } else { |
| 2993 | __ Add(temp, array, offset); |
| 2994 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2995 | destination = HeapOperand(temp, |
| 2996 | XRegisterFrom(index), |
| 2997 | LSL, |
| 2998 | Primitive::ComponentSizeShift(value_type)); |
| 2999 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3000 | { |
| 3001 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3002 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3003 | codegen_->Store(value_type, value, destination); |
| 3004 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3005 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3006 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3007 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3008 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3009 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3010 | { |
| 3011 | // We use a block to end the scratch scope before the write barrier, thus |
| 3012 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3013 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3014 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3015 | if (index.IsConstant()) { |
| 3016 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3017 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3018 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3019 | destination = HeapOperand(temp, |
| 3020 | XRegisterFrom(index), |
| 3021 | LSL, |
| 3022 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3023 | } |
| 3024 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3025 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3026 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3027 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3028 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3029 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3030 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 3031 | codegen_->AddSlowPath(slow_path); |
| 3032 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3033 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3034 | __ Cbnz(Register(value), &non_zero); |
| 3035 | if (!index.IsConstant()) { |
| 3036 | __ Add(temp, array, offset); |
| 3037 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3038 | { |
| 3039 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3040 | // emitted. |
| 3041 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3042 | __ Str(wzr, destination); |
| 3043 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3044 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3045 | __ B(&done); |
| 3046 | __ Bind(&non_zero); |
| 3047 | } |
| 3048 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3049 | // Note that when Baker read barriers are enabled, the type |
| 3050 | // checks are performed without read barriers. This is fine, |
| 3051 | // even in the case where a class object is in the from-space |
| 3052 | // after the flip, as a comparison involving such a type would |
| 3053 | // not produce a false positive; it may of course produce a |
| 3054 | // false negative, in which case we would take the ArraySet |
| 3055 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3056 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3057 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3058 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3059 | { |
| 3060 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3061 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3062 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3063 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3064 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3065 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3066 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3067 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3068 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3069 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3070 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3071 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3072 | // nor `temp2`, as we are comparing two poisoned references. |
| 3073 | __ Cmp(temp, temp2); |
| 3074 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3075 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3076 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3077 | vixl::aarch64::Label do_put; |
| 3078 | __ B(eq, &do_put); |
| 3079 | // If heap poisoning is enabled, the `temp` reference has |
| 3080 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3081 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3082 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3083 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3084 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3085 | // If heap poisoning is enabled, no need to unpoison |
| 3086 | // `temp`, as we are comparing against null below. |
| 3087 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3088 | __ Bind(&do_put); |
| 3089 | } else { |
| 3090 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3095 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3096 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3097 | __ Mov(temp2, value.W()); |
| 3098 | GetAssembler()->PoisonHeapReference(temp2); |
| 3099 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | if (!index.IsConstant()) { |
| 3103 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3104 | } else { |
| 3105 | // We no longer need the `temp` here so release it as the store below may |
| 3106 | // need a scratch register (if the constant index makes the offset too large) |
| 3107 | // and the poisoned `source` could be using the other scratch register. |
| 3108 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3109 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3110 | { |
| 3111 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3112 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3113 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3114 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3115 | if (!may_need_runtime_call_for_type_check) { |
| 3116 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3117 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3118 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3119 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3120 | |
| 3121 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3122 | |
| 3123 | if (done.IsLinked()) { |
| 3124 | __ Bind(&done); |
| 3125 | } |
| 3126 | |
| 3127 | if (slow_path != nullptr) { |
| 3128 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3129 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3133 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3134 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3135 | InvokeRuntimeCallingConvention calling_convention; |
| 3136 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3137 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3138 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3139 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3140 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3144 | BoundsCheckSlowPathARM64* slow_path = |
| 3145 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3146 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3147 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3148 | __ B(slow_path->GetEntryLabel(), hs); |
| 3149 | } |
| 3150 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3151 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3152 | LocationSummary* locations = |
| 3153 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3154 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3155 | if (check->HasUses()) { |
| 3156 | locations->SetOut(Location::SameAsFirstInput()); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3161 | // We assume the class is not null. |
| 3162 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3163 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3164 | codegen_->AddSlowPath(slow_path); |
| 3165 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3166 | } |
| 3167 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3168 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3169 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3170 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3171 | } |
| 3172 | |
| 3173 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3174 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3175 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3176 | if (rhs_loc.IsConstant()) { |
| 3177 | // 0.0 is the only immediate that can be encoded directly in |
| 3178 | // an FCMP instruction. |
| 3179 | // |
| 3180 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3181 | // specify that in a floating-point comparison, positive zero |
| 3182 | // and negative zero are considered equal, so we can use the |
| 3183 | // literal 0.0 for both cases here. |
| 3184 | // |
| 3185 | // Note however that some methods (Float.equal, Float.compare, |
| 3186 | // Float.compareTo, Double.equal, Double.compare, |
| 3187 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3188 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3189 | // -0.0. So if we ever translate calls to these methods into a |
| 3190 | // HCompare instruction, we must handle the -0.0 case with |
| 3191 | // care here. |
| 3192 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3193 | __ Fcmp(lhs_reg, 0.0); |
| 3194 | } else { |
| 3195 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3196 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3199 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3200 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3201 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3202 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3203 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3204 | case Primitive::kPrimBoolean: |
| 3205 | case Primitive::kPrimByte: |
| 3206 | case Primitive::kPrimShort: |
| 3207 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3208 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3209 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3210 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3211 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3212 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3213 | break; |
| 3214 | } |
| 3215 | case Primitive::kPrimFloat: |
| 3216 | case Primitive::kPrimDouble: { |
| 3217 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3218 | locations->SetInAt(1, |
| 3219 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3220 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3221 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3222 | locations->SetOut(Location::RequiresRegister()); |
| 3223 | break; |
| 3224 | } |
| 3225 | default: |
| 3226 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3231 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3232 | |
| 3233 | // 0 if: left == right |
| 3234 | // 1 if: left > right |
| 3235 | // -1 if: left < right |
| 3236 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3237 | case Primitive::kPrimBoolean: |
| 3238 | case Primitive::kPrimByte: |
| 3239 | case Primitive::kPrimShort: |
| 3240 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3241 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3242 | case Primitive::kPrimLong: { |
| 3243 | Register result = OutputRegister(compare); |
| 3244 | Register left = InputRegisterAt(compare, 0); |
| 3245 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3246 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3247 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3248 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | } |
| 3251 | case Primitive::kPrimFloat: |
| 3252 | case Primitive::kPrimDouble: { |
| 3253 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3254 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3255 | __ Cset(result, ne); |
| 3256 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3257 | break; |
| 3258 | } |
| 3259 | default: |
| 3260 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3261 | } |
| 3262 | } |
| 3263 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3264 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3265 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3266 | |
| 3267 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3269 | locations->SetInAt(1, |
| 3270 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3271 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3272 | : Location::RequiresFpuRegister()); |
| 3273 | } else { |
| 3274 | // Integer cases. |
| 3275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3276 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3277 | } |
| 3278 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3279 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3280 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3281 | } |
| 3282 | } |
| 3283 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3284 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3285 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3286 | return; |
| 3287 | } |
| 3288 | |
| 3289 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3290 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3291 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3292 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3293 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3294 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3295 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3296 | } else { |
| 3297 | // Integer cases. |
| 3298 | Register lhs = InputRegisterAt(instruction, 0); |
| 3299 | Operand rhs = InputOperandAt(instruction, 1); |
| 3300 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3301 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3302 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3306 | M(Equal) \ |
| 3307 | M(NotEqual) \ |
| 3308 | M(LessThan) \ |
| 3309 | M(LessThanOrEqual) \ |
| 3310 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3311 | M(GreaterThanOrEqual) \ |
| 3312 | M(Below) \ |
| 3313 | M(BelowOrEqual) \ |
| 3314 | M(Above) \ |
| 3315 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3316 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3317 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3318 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3319 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3320 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3321 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3322 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3323 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3324 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3325 | |
| 3326 | LocationSummary* locations = instruction->GetLocations(); |
| 3327 | Location second = locations->InAt(1); |
| 3328 | DCHECK(second.IsConstant()); |
| 3329 | |
| 3330 | Register out = OutputRegister(instruction); |
| 3331 | Register dividend = InputRegisterAt(instruction, 0); |
| 3332 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3333 | DCHECK(imm == 1 || imm == -1); |
| 3334 | |
| 3335 | if (instruction->IsRem()) { |
| 3336 | __ Mov(out, 0); |
| 3337 | } else { |
| 3338 | if (imm == 1) { |
| 3339 | __ Mov(out, dividend); |
| 3340 | } else { |
| 3341 | __ Neg(out, dividend); |
| 3342 | } |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3347 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3348 | |
| 3349 | LocationSummary* locations = instruction->GetLocations(); |
| 3350 | Location second = locations->InAt(1); |
| 3351 | DCHECK(second.IsConstant()); |
| 3352 | |
| 3353 | Register out = OutputRegister(instruction); |
| 3354 | Register dividend = InputRegisterAt(instruction, 0); |
| 3355 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3356 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3357 | int ctz_imm = CTZ(abs_imm); |
| 3358 | |
| 3359 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3360 | Register temp = temps.AcquireSameSizeAs(out); |
| 3361 | |
| 3362 | if (instruction->IsDiv()) { |
| 3363 | __ Add(temp, dividend, abs_imm - 1); |
| 3364 | __ Cmp(dividend, 0); |
| 3365 | __ Csel(out, temp, dividend, lt); |
| 3366 | if (imm > 0) { |
| 3367 | __ Asr(out, out, ctz_imm); |
| 3368 | } else { |
| 3369 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3370 | } |
| 3371 | } else { |
| 3372 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3373 | __ Asr(temp, dividend, bits - 1); |
| 3374 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3375 | __ Add(out, dividend, temp); |
| 3376 | __ And(out, out, abs_imm - 1); |
| 3377 | __ Sub(out, out, temp); |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3382 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3383 | |
| 3384 | LocationSummary* locations = instruction->GetLocations(); |
| 3385 | Location second = locations->InAt(1); |
| 3386 | DCHECK(second.IsConstant()); |
| 3387 | |
| 3388 | Register out = OutputRegister(instruction); |
| 3389 | Register dividend = InputRegisterAt(instruction, 0); |
| 3390 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3391 | |
| 3392 | Primitive::Type type = instruction->GetResultType(); |
| 3393 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3394 | |
| 3395 | int64_t magic; |
| 3396 | int shift; |
| 3397 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3398 | |
| 3399 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3400 | Register temp = temps.AcquireSameSizeAs(out); |
| 3401 | |
| 3402 | // temp = get_high(dividend * magic) |
| 3403 | __ Mov(temp, magic); |
| 3404 | if (type == Primitive::kPrimLong) { |
| 3405 | __ Smulh(temp, dividend, temp); |
| 3406 | } else { |
| 3407 | __ Smull(temp.X(), dividend, temp); |
| 3408 | __ Lsr(temp.X(), temp.X(), 32); |
| 3409 | } |
| 3410 | |
| 3411 | if (imm > 0 && magic < 0) { |
| 3412 | __ Add(temp, temp, dividend); |
| 3413 | } else if (imm < 0 && magic > 0) { |
| 3414 | __ Sub(temp, temp, dividend); |
| 3415 | } |
| 3416 | |
| 3417 | if (shift != 0) { |
| 3418 | __ Asr(temp, temp, shift); |
| 3419 | } |
| 3420 | |
| 3421 | if (instruction->IsDiv()) { |
| 3422 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3423 | } else { |
| 3424 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3425 | // TODO: Strength reduction for msub. |
| 3426 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3427 | __ Mov(temp_imm, imm); |
| 3428 | __ Msub(out, temp, temp_imm, dividend); |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3433 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3434 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3435 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3436 | |
| 3437 | LocationSummary* locations = instruction->GetLocations(); |
| 3438 | Register out = OutputRegister(instruction); |
| 3439 | Location second = locations->InAt(1); |
| 3440 | |
| 3441 | if (second.IsConstant()) { |
| 3442 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3443 | |
| 3444 | if (imm == 0) { |
| 3445 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3446 | } else if (imm == 1 || imm == -1) { |
| 3447 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3448 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3449 | DivRemByPowerOfTwo(instruction); |
| 3450 | } else { |
| 3451 | DCHECK(imm <= -2 || imm >= 2); |
| 3452 | GenerateDivRemWithAnyConstant(instruction); |
| 3453 | } |
| 3454 | } else { |
| 3455 | Register dividend = InputRegisterAt(instruction, 0); |
| 3456 | Register divisor = InputRegisterAt(instruction, 1); |
| 3457 | if (instruction->IsDiv()) { |
| 3458 | __ Sdiv(out, dividend, divisor); |
| 3459 | } else { |
| 3460 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3461 | Register temp = temps.AcquireSameSizeAs(out); |
| 3462 | __ Sdiv(temp, dividend, divisor); |
| 3463 | __ Msub(out, temp, divisor, dividend); |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3468 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3469 | LocationSummary* locations = |
| 3470 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3471 | switch (div->GetResultType()) { |
| 3472 | case Primitive::kPrimInt: |
| 3473 | case Primitive::kPrimLong: |
| 3474 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3475 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3476 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3477 | break; |
| 3478 | |
| 3479 | case Primitive::kPrimFloat: |
| 3480 | case Primitive::kPrimDouble: |
| 3481 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3482 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3483 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3484 | break; |
| 3485 | |
| 3486 | default: |
| 3487 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3492 | Primitive::Type type = div->GetResultType(); |
| 3493 | switch (type) { |
| 3494 | case Primitive::kPrimInt: |
| 3495 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3496 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3497 | break; |
| 3498 | |
| 3499 | case Primitive::kPrimFloat: |
| 3500 | case Primitive::kPrimDouble: |
| 3501 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3502 | break; |
| 3503 | |
| 3504 | default: |
| 3505 | LOG(FATAL) << "Unexpected div type " << type; |
| 3506 | } |
| 3507 | } |
| 3508 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3509 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3510 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3511 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3515 | SlowPathCodeARM64* slow_path = |
| 3516 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3517 | codegen_->AddSlowPath(slow_path); |
| 3518 | Location value = instruction->GetLocations()->InAt(0); |
| 3519 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3520 | Primitive::Type type = instruction->GetType(); |
| 3521 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3522 | if (!Primitive::IsIntegralType(type)) { |
| 3523 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3524 | return; |
| 3525 | } |
| 3526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3527 | if (value.IsConstant()) { |
| 3528 | int64_t divisor = Int64ConstantFrom(value); |
| 3529 | if (divisor == 0) { |
| 3530 | __ B(slow_path->GetEntryLabel()); |
| 3531 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3532 | // A division by a non-null constant is valid. We don't need to perform |
| 3533 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3534 | } |
| 3535 | } else { |
| 3536 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3537 | } |
| 3538 | } |
| 3539 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3540 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3541 | LocationSummary* locations = |
| 3542 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3543 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3544 | } |
| 3545 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3546 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3547 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3548 | // Will be generated at use site. |
| 3549 | } |
| 3550 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3551 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3552 | exit->SetLocations(nullptr); |
| 3553 | } |
| 3554 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3555 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3556 | } |
| 3557 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3558 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3559 | LocationSummary* locations = |
| 3560 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3561 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3562 | } |
| 3563 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3564 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3565 | // Will be generated at use site. |
| 3566 | } |
| 3567 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3568 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3569 | DCHECK(!successor->IsExitBlock()); |
| 3570 | HBasicBlock* block = got->GetBlock(); |
| 3571 | HInstruction* previous = got->GetPrevious(); |
| 3572 | HLoopInformation* info = block->GetLoopInformation(); |
| 3573 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3574 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3575 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3576 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3577 | return; |
| 3578 | } |
| 3579 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3580 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3581 | } |
| 3582 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3583 | __ B(codegen_->GetLabelOf(successor)); |
| 3584 | } |
| 3585 | } |
| 3586 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3587 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3588 | got->SetLocations(nullptr); |
| 3589 | } |
| 3590 | |
| 3591 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3592 | HandleGoto(got, got->GetSuccessor()); |
| 3593 | } |
| 3594 | |
| 3595 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3596 | try_boundary->SetLocations(nullptr); |
| 3597 | } |
| 3598 | |
| 3599 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3600 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3601 | if (!successor->IsExitBlock()) { |
| 3602 | HandleGoto(try_boundary, successor); |
| 3603 | } |
| 3604 | } |
| 3605 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3606 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3607 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3608 | vixl::aarch64::Label* true_target, |
| 3609 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3610 | // FP branching requires both targets to be explicit. If either of the targets |
| 3611 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3612 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3613 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3614 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3615 | if (true_target == nullptr && false_target == nullptr) { |
| 3616 | // Nothing to do. The code always falls through. |
| 3617 | return; |
| 3618 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3619 | // Constant condition, statically compared against "true" (integer value 1). |
| 3620 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3621 | if (true_target != nullptr) { |
| 3622 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3623 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3624 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3625 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3626 | if (false_target != nullptr) { |
| 3627 | __ B(false_target); |
| 3628 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3629 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3630 | return; |
| 3631 | } |
| 3632 | |
| 3633 | // The following code generates these patterns: |
| 3634 | // (1) true_target == nullptr && false_target != nullptr |
| 3635 | // - opposite condition true => branch to false_target |
| 3636 | // (2) true_target != nullptr && false_target == nullptr |
| 3637 | // - condition true => branch to true_target |
| 3638 | // (3) true_target != nullptr && false_target != nullptr |
| 3639 | // - condition true => branch to true_target |
| 3640 | // - branch to false_target |
| 3641 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3642 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3643 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3644 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3645 | if (true_target == nullptr) { |
| 3646 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3647 | } else { |
| 3648 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3649 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3650 | } else { |
| 3651 | // The condition instruction has not been materialized, use its inputs as |
| 3652 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3653 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3654 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3655 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3656 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3657 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3658 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3659 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3660 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3661 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3662 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3663 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3664 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3665 | // Integer cases. |
| 3666 | Register lhs = InputRegisterAt(condition, 0); |
| 3667 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3668 | |
| 3669 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3670 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3671 | if (true_target == nullptr) { |
| 3672 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3673 | non_fallthrough_target = false_target; |
| 3674 | } else { |
| 3675 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3676 | non_fallthrough_target = true_target; |
| 3677 | } |
| 3678 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3679 | 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] | 3680 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3681 | switch (arm64_cond) { |
| 3682 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3683 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3684 | break; |
| 3685 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3686 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3687 | break; |
| 3688 | case lt: |
| 3689 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3690 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3691 | break; |
| 3692 | case ge: |
| 3693 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3694 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3695 | break; |
| 3696 | default: |
| 3697 | // Without the `static_cast` the compiler throws an error for |
| 3698 | // `-Werror=sign-promo`. |
| 3699 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3700 | } |
| 3701 | } else { |
| 3702 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3703 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3704 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3705 | } |
| 3706 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3707 | |
| 3708 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3709 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3710 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3711 | __ B(false_target); |
| 3712 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3713 | |
| 3714 | if (fallthrough_target.IsLinked()) { |
| 3715 | __ Bind(&fallthrough_target); |
| 3716 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3717 | } |
| 3718 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3719 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3720 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3721 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3722 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3727 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3728 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3729 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3730 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3731 | true_target = nullptr; |
| 3732 | } |
| 3733 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3734 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3735 | false_target = nullptr; |
| 3736 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3737 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3741 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3742 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3743 | InvokeRuntimeCallingConvention calling_convention; |
| 3744 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3745 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3746 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3747 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3748 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3753 | SlowPathCodeARM64* slow_path = |
| 3754 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3755 | GenerateTestAndBranch(deoptimize, |
| 3756 | /* condition_input_index */ 0, |
| 3757 | slow_path->GetEntryLabel(), |
| 3758 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3759 | } |
| 3760 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3761 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3762 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3763 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3764 | locations->SetOut(Location::RequiresRegister()); |
| 3765 | } |
| 3766 | |
| 3767 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3768 | __ Ldr(OutputRegister(flag), |
| 3769 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3770 | } |
| 3771 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3772 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3773 | return condition->IsCondition() && |
| 3774 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3775 | } |
| 3776 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3777 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3778 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3779 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3780 | : ARM64Condition(cond); |
| 3781 | } |
| 3782 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3783 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3784 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3785 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3786 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3787 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3788 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3789 | } else { |
| 3790 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3791 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3792 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3793 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3794 | // Ask VIXL whether we should synthesize constants in registers. |
| 3795 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3796 | Operand true_op = is_true_value_constant ? |
| 3797 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3798 | Operand false_op = is_false_value_constant ? |
| 3799 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3800 | bool true_value_in_register = false; |
| 3801 | bool false_value_in_register = false; |
| 3802 | MacroAssembler::GetCselSynthesisInformation( |
| 3803 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3804 | true_value_in_register |= !is_true_value_constant; |
| 3805 | false_value_in_register |= !is_false_value_constant; |
| 3806 | |
| 3807 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3808 | : Location::ConstantLocation(cst_true_value)); |
| 3809 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3810 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3811 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3812 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3813 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3814 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3815 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3816 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3820 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3821 | Condition csel_cond; |
| 3822 | |
| 3823 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3824 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3825 | // Use the condition flags set by the previous instruction. |
| 3826 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3827 | } else { |
| 3828 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3829 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3830 | } |
| 3831 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3832 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3833 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3834 | } else { |
| 3835 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3836 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3839 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3840 | __ Fcsel(OutputFPRegister(select), |
| 3841 | InputFPRegisterAt(select, 1), |
| 3842 | InputFPRegisterAt(select, 0), |
| 3843 | csel_cond); |
| 3844 | } else { |
| 3845 | __ Csel(OutputRegister(select), |
| 3846 | InputOperandAt(select, 1), |
| 3847 | InputOperandAt(select, 0), |
| 3848 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3849 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3852 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3853 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3854 | } |
| 3855 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3856 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3857 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | void CodeGeneratorARM64::GenerateNop() { |
| 3861 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3864 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3865 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3869 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3873 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3877 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3878 | } |
| 3879 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3880 | // Temp is used for read barrier. |
| 3881 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3882 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3883 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3884 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3885 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3886 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3887 | return 1; |
| 3888 | } |
| 3889 | return 0; |
| 3890 | } |
| 3891 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3892 | // 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] | 3893 | // interface pointer, one for loading the current interface. |
| 3894 | // The other checks have one temp for loading the object's class. |
| 3895 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3896 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3897 | return 3; |
| 3898 | } |
| 3899 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3902 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3903 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3904 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3905 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3906 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3907 | case TypeCheckKind::kExactCheck: |
| 3908 | case TypeCheckKind::kAbstractClassCheck: |
| 3909 | case TypeCheckKind::kClassHierarchyCheck: |
| 3910 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3911 | call_kind = |
| 3912 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3913 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3914 | break; |
| 3915 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3916 | case TypeCheckKind::kUnresolvedCheck: |
| 3917 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3918 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3919 | break; |
| 3920 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3921 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3922 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3923 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3924 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3925 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3926 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3927 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3928 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3929 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3930 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3931 | // Add temps if necessary for read barriers. |
| 3932 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3936 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3937 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3938 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3939 | Register obj = InputRegisterAt(instruction, 0); |
| 3940 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3941 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3942 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3943 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3944 | DCHECK_LE(num_temps, 1u); |
| 3945 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3947 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3948 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3949 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3950 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3951 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3952 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3953 | |
| 3954 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3955 | // Avoid null check if we know `obj` is not null. |
| 3956 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3957 | __ Cbz(obj, &zero); |
| 3958 | } |
| 3959 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3960 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3961 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3962 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3963 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3964 | out_loc, |
| 3965 | obj_loc, |
| 3966 | class_offset, |
| 3967 | maybe_temp_loc, |
| 3968 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3969 | __ Cmp(out, cls); |
| 3970 | __ Cset(out, eq); |
| 3971 | if (zero.IsLinked()) { |
| 3972 | __ B(&done); |
| 3973 | } |
| 3974 | break; |
| 3975 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3976 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3977 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3978 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3979 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3980 | out_loc, |
| 3981 | obj_loc, |
| 3982 | class_offset, |
| 3983 | maybe_temp_loc, |
| 3984 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3985 | // If the class is abstract, we eagerly fetch the super class of the |
| 3986 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3987 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3988 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3989 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3990 | GenerateReferenceLoadOneRegister(instruction, |
| 3991 | out_loc, |
| 3992 | super_offset, |
| 3993 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3994 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3995 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3996 | __ Cbz(out, &done); |
| 3997 | __ Cmp(out, cls); |
| 3998 | __ B(ne, &loop); |
| 3999 | __ Mov(out, 1); |
| 4000 | if (zero.IsLinked()) { |
| 4001 | __ B(&done); |
| 4002 | } |
| 4003 | break; |
| 4004 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4005 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4006 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4007 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4008 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4009 | out_loc, |
| 4010 | obj_loc, |
| 4011 | class_offset, |
| 4012 | maybe_temp_loc, |
| 4013 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4014 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4015 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4016 | __ Bind(&loop); |
| 4017 | __ Cmp(out, cls); |
| 4018 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4019 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4020 | GenerateReferenceLoadOneRegister(instruction, |
| 4021 | out_loc, |
| 4022 | super_offset, |
| 4023 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4024 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4025 | __ Cbnz(out, &loop); |
| 4026 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4027 | __ B(&done); |
| 4028 | __ Bind(&success); |
| 4029 | __ Mov(out, 1); |
| 4030 | if (zero.IsLinked()) { |
| 4031 | __ B(&done); |
| 4032 | } |
| 4033 | break; |
| 4034 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4035 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4036 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4037 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4038 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4039 | out_loc, |
| 4040 | obj_loc, |
| 4041 | class_offset, |
| 4042 | maybe_temp_loc, |
| 4043 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4044 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4045 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4046 | __ Cmp(out, cls); |
| 4047 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4048 | // 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] | 4049 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4050 | GenerateReferenceLoadOneRegister(instruction, |
| 4051 | out_loc, |
| 4052 | component_offset, |
| 4053 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4054 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4055 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4056 | __ Cbz(out, &done); |
| 4057 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4058 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4059 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4060 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4061 | __ Mov(out, 1); |
| 4062 | __ B(&done); |
| 4063 | break; |
| 4064 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4065 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4066 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4067 | // No read barrier since the slow path will retry upon failure. |
| 4068 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4069 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4070 | out_loc, |
| 4071 | obj_loc, |
| 4072 | class_offset, |
| 4073 | maybe_temp_loc, |
| 4074 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4075 | __ Cmp(out, cls); |
| 4076 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4077 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4078 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4079 | codegen_->AddSlowPath(slow_path); |
| 4080 | __ B(ne, slow_path->GetEntryLabel()); |
| 4081 | __ Mov(out, 1); |
| 4082 | if (zero.IsLinked()) { |
| 4083 | __ B(&done); |
| 4084 | } |
| 4085 | break; |
| 4086 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4087 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4088 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4089 | case TypeCheckKind::kInterfaceCheck: { |
| 4090 | // Note that we indeed only call on slow path, but we always go |
| 4091 | // into the slow path for the unresolved and interface check |
| 4092 | // cases. |
| 4093 | // |
| 4094 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4095 | // entry point without resorting to a type checking slow path |
| 4096 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4097 | // require to assign fixed registers for the inputs of this |
| 4098 | // HInstanceOf instruction (following the runtime calling |
| 4099 | // convention), which might be cluttered by the potential first |
| 4100 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4101 | // |
| 4102 | // TODO: Introduce a new runtime entry point taking the object |
| 4103 | // to test (instead of its class) as argument, and let it deal |
| 4104 | // with the read barrier issues. This will let us refactor this |
| 4105 | // case of the `switch` code as it was previously (with a direct |
| 4106 | // call to the runtime not using a type checking slow path). |
| 4107 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4108 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4109 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4110 | /* is_fatal */ false); |
| 4111 | codegen_->AddSlowPath(slow_path); |
| 4112 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4113 | if (zero.IsLinked()) { |
| 4114 | __ B(&done); |
| 4115 | } |
| 4116 | break; |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | if (zero.IsLinked()) { |
| 4121 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4122 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | if (done.IsLinked()) { |
| 4126 | __ Bind(&done); |
| 4127 | } |
| 4128 | |
| 4129 | if (slow_path != nullptr) { |
| 4130 | __ Bind(slow_path->GetExitLabel()); |
| 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4135 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4136 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4137 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4138 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4139 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4140 | case TypeCheckKind::kExactCheck: |
| 4141 | case TypeCheckKind::kAbstractClassCheck: |
| 4142 | case TypeCheckKind::kClassHierarchyCheck: |
| 4143 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4144 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4145 | LocationSummary::kCallOnSlowPath : |
| 4146 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4147 | break; |
| 4148 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4149 | case TypeCheckKind::kUnresolvedCheck: |
| 4150 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4151 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4152 | break; |
| 4153 | } |
| 4154 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4155 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4156 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4157 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4158 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4159 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4163 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4164 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4165 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4166 | Register obj = InputRegisterAt(instruction, 0); |
| 4167 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4168 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4169 | DCHECK_GE(num_temps, 1u); |
| 4170 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4171 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4172 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4173 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4174 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4175 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4176 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4177 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4178 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4179 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4180 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4181 | const uint32_t object_array_data_offset = |
| 4182 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4183 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4184 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4185 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4186 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4187 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4188 | if (!kEmitCompilerReadBarrier) { |
| 4189 | is_type_check_slow_path_fatal = |
| 4190 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4191 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4192 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4193 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4194 | !instruction->CanThrowIntoCatchBlock(); |
| 4195 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4196 | SlowPathCodeARM64* type_check_slow_path = |
| 4197 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4198 | is_type_check_slow_path_fatal); |
| 4199 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4200 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4201 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4202 | // Avoid null check if we know obj is not null. |
| 4203 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4204 | __ Cbz(obj, &done); |
| 4205 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4206 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4207 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4208 | case TypeCheckKind::kExactCheck: |
| 4209 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4210 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4211 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4212 | temp_loc, |
| 4213 | obj_loc, |
| 4214 | class_offset, |
| 4215 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4216 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4217 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4218 | __ Cmp(temp, cls); |
| 4219 | // Jump to slow path for throwing the exception or doing a |
| 4220 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4221 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4222 | break; |
| 4223 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4224 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4225 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4226 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4227 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4228 | temp_loc, |
| 4229 | obj_loc, |
| 4230 | class_offset, |
| 4231 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4232 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4233 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4234 | // If the class is abstract, we eagerly fetch the super class of the |
| 4235 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4236 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4237 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4238 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4239 | GenerateReferenceLoadOneRegister(instruction, |
| 4240 | temp_loc, |
| 4241 | super_offset, |
| 4242 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4243 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4244 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4245 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4246 | // exception. |
| 4247 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4248 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4249 | __ Cmp(temp, cls); |
| 4250 | __ B(ne, &loop); |
| 4251 | break; |
| 4252 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4253 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4254 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4255 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4256 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4257 | temp_loc, |
| 4258 | obj_loc, |
| 4259 | class_offset, |
| 4260 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4261 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4262 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4263 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4264 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4265 | __ Bind(&loop); |
| 4266 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4267 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4268 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4269 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4270 | GenerateReferenceLoadOneRegister(instruction, |
| 4271 | temp_loc, |
| 4272 | super_offset, |
| 4273 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4274 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4275 | |
| 4276 | // If the class reference currently in `temp` is not null, jump |
| 4277 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4278 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4279 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4280 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4281 | break; |
| 4282 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4283 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4284 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4285 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4286 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4287 | temp_loc, |
| 4288 | obj_loc, |
| 4289 | class_offset, |
| 4290 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4291 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4292 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4293 | // Do an exact check. |
| 4294 | __ Cmp(temp, cls); |
| 4295 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4296 | |
| 4297 | // 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] | 4298 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4299 | GenerateReferenceLoadOneRegister(instruction, |
| 4300 | temp_loc, |
| 4301 | component_offset, |
| 4302 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4303 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4304 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4305 | // If the component type is null, jump to the slow path to throw the exception. |
| 4306 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4307 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4308 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4309 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4310 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4311 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4312 | break; |
| 4313 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4314 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4315 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4316 | // 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] | 4317 | // |
| 4318 | // We cannot directly call the CheckCast runtime entry point |
| 4319 | // without resorting to a type checking slow path here (i.e. by |
| 4320 | // calling InvokeRuntime directly), as it would require to |
| 4321 | // assign fixed registers for the inputs of this HInstanceOf |
| 4322 | // instruction (following the runtime calling convention), which |
| 4323 | // might be cluttered by the potential first read barrier |
| 4324 | // emission at the beginning of this method. |
| 4325 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4326 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4327 | case TypeCheckKind::kInterfaceCheck: { |
| 4328 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4329 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4330 | temp_loc, |
| 4331 | obj_loc, |
| 4332 | class_offset, |
| 4333 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4334 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4335 | |
| 4336 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4337 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4338 | temp_loc, |
| 4339 | temp_loc, |
| 4340 | iftable_offset, |
| 4341 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4342 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4343 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4344 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4345 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4346 | vixl::aarch64::Label start_loop; |
| 4347 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4348 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4349 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4350 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4351 | // Go to next interface. |
| 4352 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4353 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4354 | // Compare the classes and continue the loop if they do not match. |
| 4355 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4356 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4357 | break; |
| 4358 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4359 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4360 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4361 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4362 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4363 | } |
| 4364 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4365 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4366 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4367 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4368 | } |
| 4369 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4370 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4371 | // Will be generated at use site. |
| 4372 | } |
| 4373 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4374 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4375 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4376 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4377 | } |
| 4378 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4379 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4380 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4383 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4384 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4385 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4386 | // the method_idx. |
| 4387 | HandleInvoke(invoke); |
| 4388 | } |
| 4389 | |
| 4390 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4391 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4392 | } |
| 4393 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4394 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4395 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4396 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4397 | } |
| 4398 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4399 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4400 | HandleInvoke(invoke); |
| 4401 | } |
| 4402 | |
| 4403 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4404 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4405 | LocationSummary* locations = invoke->GetLocations(); |
| 4406 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4407 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4408 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4409 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4410 | |
| 4411 | // The register ip1 is required to be used for the hidden argument in |
| 4412 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4413 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4414 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4415 | scratch_scope.Exclude(ip1); |
| 4416 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4417 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4418 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4419 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4420 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4421 | { |
| 4422 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4423 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4424 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4425 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4426 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4427 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4428 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4429 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4430 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4431 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4432 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4433 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4434 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4435 | // emit a read barrier for the previous class reference load. |
| 4436 | // However this is not required in practice, as this is an |
| 4437 | // intermediate/temporary reference and because the current |
| 4438 | // concurrent copying collector keeps the from-space memory |
| 4439 | // intact/accessible until the end of the marking phase (the |
| 4440 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4441 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4442 | __ Ldr(temp, |
| 4443 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4444 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4445 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4446 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4447 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4448 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4449 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4450 | |
| 4451 | { |
| 4452 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4453 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4454 | |
| 4455 | // lr(); |
| 4456 | __ blr(lr); |
| 4457 | DCHECK(!codegen_->IsLeafMethod()); |
| 4458 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4459 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4463 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4464 | if (intrinsic.TryDispatch(invoke)) { |
| 4465 | return; |
| 4466 | } |
| 4467 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4468 | HandleInvoke(invoke); |
| 4469 | } |
| 4470 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4471 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4472 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4473 | // art::PrepareForRegisterAllocation. |
| 4474 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4475 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4476 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4477 | if (intrinsic.TryDispatch(invoke)) { |
| 4478 | return; |
| 4479 | } |
| 4480 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4481 | HandleInvoke(invoke); |
| 4482 | } |
| 4483 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4484 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4485 | if (invoke->GetLocations()->Intrinsified()) { |
| 4486 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4487 | intrinsic.Dispatch(invoke); |
| 4488 | return true; |
| 4489 | } |
| 4490 | return false; |
| 4491 | } |
| 4492 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4493 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4494 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4495 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4496 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4497 | return desired_dispatch_info; |
| 4498 | } |
| 4499 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 4500 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4501 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4502 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4503 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4504 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4505 | uint32_t offset = |
| 4506 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4507 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4508 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4509 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4510 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4512 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4514 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4515 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4516 | // Add ADRP with its PC-relative method patch. |
| 4517 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4518 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4519 | // Add ADD with its PC-relative method patch. |
| 4520 | vixl::aarch64::Label* add_label = |
| 4521 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4522 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4523 | break; |
| 4524 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4525 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4526 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4527 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4528 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4529 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4530 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4531 | const DexFile& dex_file = invoke->GetDexFileForPcRelativeDexCache(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4532 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4533 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4534 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4535 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4536 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4537 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4538 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4540 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4542 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4543 | Register reg = XRegisterFrom(temp); |
| 4544 | Register method_reg; |
| 4545 | if (current_method.IsRegister()) { |
| 4546 | method_reg = XRegisterFrom(current_method); |
| 4547 | } else { |
| 4548 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4549 | DCHECK(!current_method.IsValid()); |
| 4550 | method_reg = reg; |
| 4551 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 4552 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 4553 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4554 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4555 | __ Ldr(reg.X(), |
| 4556 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4557 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4558 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4559 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4560 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4561 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 4562 | break; |
| 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | switch (invoke->GetCodePtrLocation()) { |
| 4567 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4568 | __ Bl(&frame_entry_label_); |
| 4569 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4570 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4571 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4572 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4573 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4574 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4575 | { |
| 4576 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4577 | // BLR must be the last instruction emitted in this function. |
| 4578 | // Recording the pc will occur right after returning from this function. |
| 4579 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4580 | kInstructionSize, |
| 4581 | CodeBufferCheckScope::kExactSize); |
| 4582 | // lr() |
| 4583 | __ blr(lr); |
| 4584 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4585 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4586 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4587 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4588 | DCHECK(!IsLeafMethod()); |
| 4589 | } |
| 4590 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4591 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4592 | // Use the calling convention instead of the location of the receiver, as |
| 4593 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4594 | // slow path, the arguments have been moved to the right place, so here we are |
| 4595 | // guaranteed that the receiver is the first register of the calling convention. |
| 4596 | InvokeDexCallingConvention calling_convention; |
| 4597 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4598 | Register temp = XRegisterFrom(temp_in); |
| 4599 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4600 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4601 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4602 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4603 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4604 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4605 | |
| 4606 | { |
| 4607 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4608 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4609 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4610 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4611 | MaybeRecordImplicitNullCheck(invoke); |
| 4612 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4613 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4614 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4615 | // intermediate/temporary reference and because the current |
| 4616 | // concurrent copying collector keeps the from-space memory |
| 4617 | // intact/accessible until the end of the marking phase (the |
| 4618 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4619 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4620 | // temp = temp->GetMethodAt(method_offset); |
| 4621 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4622 | // lr = temp->GetEntryPoint(); |
| 4623 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4624 | { |
| 4625 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4626 | // BLR should be the last instruction emitted in this function. |
| 4627 | // Recording the pc will occur right after returning from this function. |
| 4628 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4629 | // lr(); |
| 4630 | __ blr(lr); |
| 4631 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4632 | } |
| 4633 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4634 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4635 | HandleInvoke(invoke); |
| 4636 | } |
| 4637 | |
| 4638 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4639 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4640 | } |
| 4641 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4642 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4643 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4644 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4645 | return NewPcRelativePatch(*target_method.dex_file, |
| 4646 | target_method.dex_method_index, |
| 4647 | adrp_label, |
| 4648 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4651 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4652 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4653 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4654 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4655 | 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] | 4656 | } |
| 4657 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4658 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4659 | const DexFile& dex_file, |
| 4660 | dex::TypeIndex type_index, |
| 4661 | vixl::aarch64::Label* adrp_label) { |
| 4662 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4663 | } |
| 4664 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4665 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4666 | const DexFile& dex_file, |
| 4667 | dex::StringIndex string_index, |
| 4668 | vixl::aarch64::Label* adrp_label) { |
| 4669 | return |
| 4670 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4671 | } |
| 4672 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4673 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4674 | const DexFile& dex_file, |
| 4675 | uint32_t element_offset, |
| 4676 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4677 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4678 | } |
| 4679 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4680 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4681 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4682 | return &baker_read_barrier_patches_.back().label; |
| 4683 | } |
| 4684 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4685 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4686 | const DexFile& dex_file, |
| 4687 | uint32_t offset_or_index, |
| 4688 | vixl::aarch64::Label* adrp_label, |
| 4689 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4690 | // Add a patch entry and return the label. |
| 4691 | patches->emplace_back(dex_file, offset_or_index); |
| 4692 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4693 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4694 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4695 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4696 | return label; |
| 4697 | } |
| 4698 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4699 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4700 | uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 4701 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4702 | } |
| 4703 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4704 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4705 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4706 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4707 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4708 | return jit_string_patches_.GetOrCreate( |
| 4709 | StringReference(&dex_file, string_index), |
| 4710 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4711 | } |
| 4712 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4713 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4714 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4715 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4716 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4717 | return jit_class_patches_.GetOrCreate( |
| 4718 | TypeReference(&dex_file, type_index), |
| 4719 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4720 | } |
| 4721 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4722 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4723 | vixl::aarch64::Register reg) { |
| 4724 | DCHECK(reg.IsX()); |
| 4725 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4726 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4727 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4731 | vixl::aarch64::Register out, |
| 4732 | vixl::aarch64::Register base) { |
| 4733 | DCHECK(out.IsX()); |
| 4734 | DCHECK(base.IsX()); |
| 4735 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4736 | __ Bind(fixup_label); |
| 4737 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4738 | } |
| 4739 | |
| 4740 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4741 | vixl::aarch64::Register out, |
| 4742 | vixl::aarch64::Register base) { |
| 4743 | DCHECK(base.IsX()); |
| 4744 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4745 | __ Bind(fixup_label); |
| 4746 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4747 | } |
| 4748 | |
| 4749 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4750 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4751 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4752 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4753 | for (const PcRelativePatchInfo& info : infos) { |
| 4754 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4755 | &info.target_dex_file, |
| 4756 | info.pc_insn_label->GetLocation(), |
| 4757 | info.offset_or_index)); |
| 4758 | } |
| 4759 | } |
| 4760 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4761 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4762 | DCHECK(linker_patches->empty()); |
| 4763 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4764 | pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4765 | pc_relative_method_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4766 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4767 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4768 | pc_relative_string_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4769 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4770 | linker_patches->reserve(size); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4771 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4772 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4773 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4774 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4775 | info.offset_or_index)); |
| 4776 | } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4777 | if (GetCompilerOptions().IsBootImage()) { |
| 4778 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4779 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4780 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4781 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4782 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4783 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4784 | } else { |
| 4785 | DCHECK(pc_relative_method_patches_.empty()); |
| 4786 | DCHECK(pc_relative_type_patches_.empty()); |
| 4787 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4788 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4789 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4790 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4791 | linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4792 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 4793 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 4794 | info.custom_data)); |
| 4795 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4796 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4799 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4800 | Uint32ToLiteralMap* map) { |
| 4801 | return map->GetOrCreate( |
| 4802 | value, |
| 4803 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4804 | } |
| 4805 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4806 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4807 | return uint64_literals_.GetOrCreate( |
| 4808 | value, |
| 4809 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4812 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4813 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4814 | // art::PrepareForRegisterAllocation. |
| 4815 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4816 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4817 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4818 | return; |
| 4819 | } |
| 4820 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4821 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4822 | // are no pools emitted. |
| 4823 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4824 | LocationSummary* locations = invoke->GetLocations(); |
| 4825 | codegen_->GenerateStaticOrDirectCall( |
| 4826 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4827 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4831 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4832 | return; |
| 4833 | } |
| 4834 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4835 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4836 | // are no pools emitted. |
| 4837 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4838 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4839 | DCHECK(!codegen_->IsLeafMethod()); |
| 4840 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4841 | } |
| 4842 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4843 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4844 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4845 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4846 | case HLoadClass::LoadKind::kInvalid: |
| 4847 | LOG(FATAL) << "UNREACHABLE"; |
| 4848 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4849 | case HLoadClass::LoadKind::kReferrersClass: |
| 4850 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4851 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4852 | case HLoadClass::LoadKind::kBssEntry: |
| 4853 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4854 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4855 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4856 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4857 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4858 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4859 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4860 | break; |
| 4861 | } |
| 4862 | return desired_class_load_kind; |
| 4863 | } |
| 4864 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4865 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4866 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4867 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4868 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4869 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4870 | cls, |
| 4871 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4872 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4873 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4874 | return; |
| 4875 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4876 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4877 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4878 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4879 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4880 | ? LocationSummary::kCallOnSlowPath |
| 4881 | : LocationSummary::kNoCall; |
| 4882 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4883 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4884 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4885 | } |
| 4886 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4887 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4888 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4889 | } |
| 4890 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4891 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4892 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4893 | // 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] | 4894 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4895 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4896 | InvokeRuntimeCallingConvention calling_convention; |
| 4897 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4898 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4899 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4900 | Primitive::kPrimNot).GetCode()); |
| 4901 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4902 | } else { |
| 4903 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4904 | } |
| 4905 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4906 | } |
| 4907 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4908 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4909 | // move. |
| 4910 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4911 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4912 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4913 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4914 | return; |
| 4915 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4916 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4917 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4918 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4919 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4920 | Register bss_entry_temp; |
| 4921 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4922 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4923 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4924 | ? kWithoutReadBarrier |
| 4925 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4926 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4927 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4928 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4929 | DCHECK(!cls->CanCallRuntime()); |
| 4930 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4931 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4932 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4933 | GenerateGcRootFieldLoad(cls, |
| 4934 | out_loc, |
| 4935 | current_method, |
| 4936 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4937 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4938 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4939 | break; |
| 4940 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4941 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4942 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4943 | // Add ADRP with its PC-relative type patch. |
| 4944 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4945 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4946 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4947 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4948 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4949 | vixl::aarch64::Label* add_label = |
| 4950 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4951 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4952 | break; |
| 4953 | } |
| 4954 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4955 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4956 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4957 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4958 | DCHECK_NE(address, 0u); |
| 4959 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4960 | break; |
| 4961 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4962 | case HLoadClass::LoadKind::kBssEntry: { |
| 4963 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4964 | const DexFile& dex_file = cls->GetDexFile(); |
| 4965 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4966 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4967 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4968 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4969 | // Add LDR with its PC-relative Class patch. |
| 4970 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4971 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4972 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4973 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4974 | out_loc, |
| 4975 | bss_entry_temp, |
| 4976 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4977 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4978 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4979 | generate_null_check = true; |
| 4980 | break; |
| 4981 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4982 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4983 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4984 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4985 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4986 | GenerateGcRootFieldLoad(cls, |
| 4987 | out_loc, |
| 4988 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4989 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4990 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4991 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4992 | break; |
| 4993 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4994 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4995 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4996 | LOG(FATAL) << "UNREACHABLE"; |
| 4997 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5000 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5001 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5002 | DCHECK(cls->CanCallRuntime()); |
| 5003 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5004 | 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] | 5005 | codegen_->AddSlowPath(slow_path); |
| 5006 | if (generate_null_check) { |
| 5007 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5008 | } |
| 5009 | if (cls->MustGenerateClinitCheck()) { |
| 5010 | GenerateClassInitializationCheck(slow_path, out); |
| 5011 | } else { |
| 5012 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | } |
| 5016 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5017 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5018 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5019 | } |
| 5020 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5021 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5022 | LocationSummary* locations = |
| 5023 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5024 | locations->SetOut(Location::RequiresRegister()); |
| 5025 | } |
| 5026 | |
| 5027 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5028 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5029 | } |
| 5030 | |
| 5031 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5032 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5033 | } |
| 5034 | |
| 5035 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5036 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5039 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5040 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5041 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5042 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5043 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5044 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5045 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5046 | case HLoadString::LoadKind::kJitTableAddress: |
| 5047 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5048 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5049 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5050 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5051 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5052 | } |
| 5053 | return desired_string_load_kind; |
| 5054 | } |
| 5055 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5056 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5057 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5058 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5059 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5060 | InvokeRuntimeCallingConvention calling_convention; |
| 5061 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5062 | } else { |
| 5063 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5064 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5065 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5066 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5067 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5068 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5069 | InvokeRuntimeCallingConvention calling_convention; |
| 5070 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5071 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5072 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5073 | Primitive::kPrimNot).GetCode()); |
| 5074 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5075 | } else { |
| 5076 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5077 | } |
| 5078 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5079 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5082 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5083 | // move. |
| 5084 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5085 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5086 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5087 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5088 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 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 | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6093 | // HeapReference<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. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6188 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 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 | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6250 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6251 | DCHECK(kEmitCompilerReadBarrier); |
| 6252 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6253 | // If we are emitting an array load, we should not be using a |
| 6254 | // Load Acquire instruction. In other words: |
| 6255 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6256 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6257 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6258 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6259 | // whether we need to enter the slow path to mark the reference. |
| 6260 | // Then, in the slow path, check the gray bit in the lock word of |
| 6261 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 6262 | // not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6263 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6264 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6265 | // instead, we load into `temp2` the read barrier mark entry point |
| 6266 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6267 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6268 | // |
| 6269 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6270 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6271 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6272 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6273 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6274 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6275 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6276 | // if (is_gray) { |
| 6277 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6278 | // } |
| 6279 | // } else { |
| 6280 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6281 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6282 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6283 | // Slow path marking the object `ref` when the GC is marking. The |
| 6284 | // entrypoint will already be loaded in `temp2`. |
| 6285 | Register temp2 = lr; |
| 6286 | Location temp2_loc = LocationFrom(temp2); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6287 | SlowPathCodeARM64* slow_path = |
| 6288 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6289 | instruction, |
| 6290 | ref, |
| 6291 | obj, |
| 6292 | offset, |
| 6293 | index, |
| 6294 | scale_factor, |
| 6295 | needs_null_check, |
| 6296 | use_load_acquire, |
| 6297 | temp, |
| 6298 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6299 | AddSlowPath(slow_path); |
| 6300 | |
| 6301 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6302 | const int32_t entry_point_offset = |
| 6303 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6304 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6305 | // threads are suspended or running a checkpoint. |
| 6306 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6307 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6308 | // checking GetIsGcMarking. |
| 6309 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6310 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6311 | GenerateRawReferenceLoad( |
| 6312 | 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] | 6313 | __ Bind(slow_path->GetExitLabel()); |
| 6314 | } |
| 6315 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6316 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6317 | Location ref, |
| 6318 | Register obj, |
| 6319 | Location field_offset, |
| 6320 | Register temp, |
| 6321 | bool needs_null_check, |
| 6322 | bool use_load_acquire) { |
| 6323 | DCHECK(kEmitCompilerReadBarrier); |
| 6324 | DCHECK(kUseBakerReadBarrier); |
| 6325 | // If we are emitting an array load, we should not be using a |
| 6326 | // Load Acquire instruction. In other words: |
| 6327 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6328 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6329 | |
| 6330 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6331 | // whether we need to enter the slow path to update the reference |
| 6332 | // field within `obj`. Then, in the slow path, check the gray bit |
| 6333 | // in the lock word of the reference's holder (`obj`) to decide |
| 6334 | // whether to mark `ref` and update the field or not. |
| 6335 | // |
| 6336 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6337 | // instead, we load into `temp2` the read barrier mark entry point |
| 6338 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6339 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6340 | // |
| 6341 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6342 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6343 | // // Slow path. |
| 6344 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6345 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6346 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6347 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6348 | // if (is_gray) { |
| 6349 | // old_ref = ref; |
| 6350 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6351 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6352 | // } |
| 6353 | // } |
| 6354 | |
| 6355 | // Slow path updating the object reference at address `obj + field_offset` |
| 6356 | // when the GC is marking. The entrypoint will already be loaded in `temp2`. |
| 6357 | Register temp2 = lr; |
| 6358 | Location temp2_loc = LocationFrom(temp2); |
| 6359 | SlowPathCodeARM64* slow_path = |
| 6360 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6361 | instruction, |
| 6362 | ref, |
| 6363 | obj, |
| 6364 | /* offset */ 0u, |
| 6365 | /* index */ field_offset, |
| 6366 | /* scale_factor */ 0u /* "times 1" */, |
| 6367 | needs_null_check, |
| 6368 | use_load_acquire, |
| 6369 | temp, |
| 6370 | /* entrypoint */ temp2_loc); |
| 6371 | AddSlowPath(slow_path); |
| 6372 | |
| 6373 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6374 | const int32_t entry_point_offset = |
| 6375 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6376 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6377 | // threads are suspended or running a checkpoint. |
| 6378 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
| 6379 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6380 | // checking GetIsGcMarking. |
| 6381 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
| 6382 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6383 | // up-to-date, and we don't need to load the reference). |
| 6384 | __ Bind(slow_path->GetExitLabel()); |
| 6385 | } |
| 6386 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6387 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6388 | Location ref, |
| 6389 | Register obj, |
| 6390 | uint32_t offset, |
| 6391 | Location index, |
| 6392 | size_t scale_factor, |
| 6393 | bool needs_null_check, |
| 6394 | bool use_load_acquire) { |
| 6395 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6396 | Primitive::Type type = Primitive::kPrimNot; |
| 6397 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6398 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6399 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6400 | // that no pools are emitted between the load (macro) instruction |
| 6401 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6402 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6403 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6404 | // Load types involving an "index": ArrayGet, |
| 6405 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6406 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6407 | if (use_load_acquire) { |
| 6408 | // UnsafeGetObjectVolatile intrinsic case. |
| 6409 | // Register `index` is not an index in an object array, but an |
| 6410 | // offset to an object reference field within object `obj`. |
| 6411 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6412 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6413 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6414 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6415 | DCHECK_EQ(offset, 0u); |
| 6416 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6417 | DCHECK_EQ(needs_null_check, false); |
| 6418 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6419 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6420 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6421 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6422 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6423 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6424 | if (index.IsConstant()) { |
| 6425 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6426 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6427 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6428 | if (needs_null_check) { |
| 6429 | MaybeRecordImplicitNullCheck(instruction); |
| 6430 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6431 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6432 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6433 | Register temp = temps.AcquireW(); |
| 6434 | __ Add(temp, obj, offset); |
| 6435 | { |
| 6436 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6437 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6438 | if (needs_null_check) { |
| 6439 | MaybeRecordImplicitNullCheck(instruction); |
| 6440 | } |
| 6441 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6442 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6443 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6444 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6445 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6446 | MemOperand field = HeapOperand(obj, offset); |
| 6447 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6448 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6449 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6450 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6451 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6452 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6453 | if (needs_null_check) { |
| 6454 | MaybeRecordImplicitNullCheck(instruction); |
| 6455 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6456 | } |
| 6457 | } |
| 6458 | |
| 6459 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6460 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6461 | } |
| 6462 | |
| 6463 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6464 | Location out, |
| 6465 | Location ref, |
| 6466 | Location obj, |
| 6467 | uint32_t offset, |
| 6468 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6469 | DCHECK(kEmitCompilerReadBarrier); |
| 6470 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6471 | // Insert a slow path based read barrier *after* the reference load. |
| 6472 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6473 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6474 | // reference will be carried out by the runtime within the slow |
| 6475 | // path. |
| 6476 | // |
| 6477 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6478 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6479 | // not used by the artReadBarrierSlow entry point. |
| 6480 | // |
| 6481 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6482 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6483 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6484 | AddSlowPath(slow_path); |
| 6485 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6486 | __ B(slow_path->GetEntryLabel()); |
| 6487 | __ Bind(slow_path->GetExitLabel()); |
| 6488 | } |
| 6489 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6490 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6491 | Location out, |
| 6492 | Location ref, |
| 6493 | Location obj, |
| 6494 | uint32_t offset, |
| 6495 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6496 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6497 | // Baker's read barriers shall be handled by the fast path |
| 6498 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6499 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6500 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6501 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6502 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6503 | } else if (kPoisonHeapReferences) { |
| 6504 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6505 | } |
| 6506 | } |
| 6507 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6508 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6509 | Location out, |
| 6510 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6511 | DCHECK(kEmitCompilerReadBarrier); |
| 6512 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6513 | // Insert a slow path based read barrier *after* the GC root load. |
| 6514 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6515 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6516 | // not need to do anything special for this here. |
| 6517 | SlowPathCodeARM64* slow_path = |
| 6518 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6519 | AddSlowPath(slow_path); |
| 6520 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6521 | __ B(slow_path->GetEntryLabel()); |
| 6522 | __ Bind(slow_path->GetExitLabel()); |
| 6523 | } |
| 6524 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6525 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6526 | LocationSummary* locations = |
| 6527 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6529 | locations->SetOut(Location::RequiresRegister()); |
| 6530 | } |
| 6531 | |
| 6532 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6533 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6534 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6535 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6536 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6537 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6538 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6539 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6540 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6541 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6542 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6543 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6544 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6545 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6546 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6547 | } |
| 6548 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6549 | static void PatchJitRootUse(uint8_t* code, |
| 6550 | const uint8_t* roots_data, |
| 6551 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6552 | uint64_t index_in_table) { |
| 6553 | uint32_t literal_offset = literal->GetOffset(); |
| 6554 | uintptr_t address = |
| 6555 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6556 | uint8_t* data = code + literal_offset; |
| 6557 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6558 | } |
| 6559 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6560 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6561 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6562 | const StringReference& string_reference = entry.first; |
| 6563 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6564 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6565 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6566 | uint64_t index_in_table = it->second; |
| 6567 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6568 | } |
| 6569 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6570 | const TypeReference& type_reference = entry.first; |
| 6571 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6572 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6573 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6574 | uint64_t index_in_table = it->second; |
| 6575 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6576 | } |
| 6577 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6578 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6579 | #undef __ |
| 6580 | #undef QUICK_ENTRY_POINT |
| 6581 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6582 | } // namespace arm64 |
| 6583 | } // namespace art |