Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame^] | 24 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 26 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 29 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 30 | #include "intrinsics.h" |
| 31 | #include "intrinsics_arm64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 32 | #include "linker/arm64/relative_patcher_arm64.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 33 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 35 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 36 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 37 | #include "thread.h" |
| 38 | #include "utils/arm64/assembler_arm64.h" |
| 39 | #include "utils/assembler.h" |
| 40 | #include "utils/stack_checks.h" |
| 41 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 42 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 43 | using vixl::ExactAssemblyScope; |
| 44 | using vixl::CodeBufferCheckScope; |
| 45 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 46 | |
| 47 | #ifdef __ |
| 48 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 49 | #endif |
| 50 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 51 | namespace art { |
| 52 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 53 | template<class MirrorType> |
| 54 | class GcRoot; |
| 55 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 56 | namespace arm64 { |
| 57 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 58 | using helpers::ARM64EncodableConstantOrRegister; |
| 59 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 60 | using helpers::CPURegisterFrom; |
| 61 | using helpers::DRegisterFrom; |
| 62 | using helpers::FPRegisterFrom; |
| 63 | using helpers::HeapOperand; |
| 64 | using helpers::HeapOperandFrom; |
| 65 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 66 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 67 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 69 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 71 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | using helpers::LocationFrom; |
| 73 | using helpers::OperandFromMemOperand; |
| 74 | using helpers::OutputCPURegister; |
| 75 | using helpers::OutputFPRegister; |
| 76 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 77 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 78 | using helpers::RegisterFrom; |
| 79 | using helpers::StackOperandFrom; |
| 80 | using helpers::VIXLRegCodeFromART; |
| 81 | using helpers::WRegisterFrom; |
| 82 | using helpers::XRegisterFrom; |
| 83 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 84 | // 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] | 85 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 86 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 87 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 88 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 89 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 90 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 91 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 92 | // the offset explicitly. |
| 93 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 94 | |
| 95 | // 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] | 96 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 97 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 98 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 99 | |
| 100 | // Some instructions have special requirements for a temporary, for example |
| 101 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 102 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 103 | // loads with large offsets need a fixed register to limit the number of link-time |
| 104 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 105 | // register that's neither callee-save nor an argument register. We choose x15. |
| 106 | inline Location FixedTempLocation() { |
| 107 | return Location::RegisterLocation(x15.GetCode()); |
| 108 | } |
| 109 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 110 | inline Condition ARM64Condition(IfCondition cond) { |
| 111 | switch (cond) { |
| 112 | case kCondEQ: return eq; |
| 113 | case kCondNE: return ne; |
| 114 | case kCondLT: return lt; |
| 115 | case kCondLE: return le; |
| 116 | case kCondGT: return gt; |
| 117 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 118 | case kCondB: return lo; |
| 119 | case kCondBE: return ls; |
| 120 | case kCondA: return hi; |
| 121 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 122 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 123 | LOG(FATAL) << "Unreachable"; |
| 124 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 127 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 128 | // The ARM64 condition codes can express all the necessary branches, see the |
| 129 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 130 | // There is no dex instruction or HIR that would need the missing conditions |
| 131 | // "equal or unordered" or "not equal". |
| 132 | switch (cond) { |
| 133 | case kCondEQ: return eq; |
| 134 | case kCondNE: return ne /* unordered */; |
| 135 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 136 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 137 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 138 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 139 | default: |
| 140 | LOG(FATAL) << "UNREACHABLE"; |
| 141 | UNREACHABLE(); |
| 142 | } |
| 143 | } |
| 144 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 145 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 146 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 147 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 148 | // but we use the exact registers for clarity. |
| 149 | if (return_type == Primitive::kPrimFloat) { |
| 150 | return LocationFrom(s0); |
| 151 | } else if (return_type == Primitive::kPrimDouble) { |
| 152 | return LocationFrom(d0); |
| 153 | } else if (return_type == Primitive::kPrimLong) { |
| 154 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 155 | } else if (return_type == Primitive::kPrimVoid) { |
| 156 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 157 | } else { |
| 158 | return LocationFrom(w0); |
| 159 | } |
| 160 | } |
| 161 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 162 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 163 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 166 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 167 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 168 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 169 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 170 | // Calculate memory accessing operand for save/restore live registers. |
| 171 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 172 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 173 | int64_t spill_offset, |
| 174 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 175 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 176 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 177 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 178 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 179 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 180 | codegen->GetNumberOfFloatingPointRegisters())); |
| 181 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 182 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 183 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 184 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 185 | |
| 186 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 187 | UseScratchRegisterScope temps(masm); |
| 188 | |
| 189 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 190 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 191 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 192 | int64_t reg_size = kXRegSizeInBytes; |
| 193 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 194 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 195 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 196 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 197 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 198 | // to compute the base address(float point registers spill base address). |
| 199 | Register new_base = temps.AcquireSameSizeAs(base); |
| 200 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 201 | base = new_base; |
| 202 | spill_offset = -core_spill_size; |
| 203 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 204 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 205 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 206 | } |
| 207 | |
| 208 | if (is_save) { |
| 209 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 210 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 211 | } else { |
| 212 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 213 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 218 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 219 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 220 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 221 | // If the register holds an object, update the stack mask. |
| 222 | if (locations->RegisterContainsObject(i)) { |
| 223 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 224 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 225 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 226 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 227 | saved_core_stack_offsets_[i] = stack_offset; |
| 228 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 229 | } |
| 230 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 231 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 232 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 233 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 234 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 235 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 236 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 237 | } |
| 238 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 239 | SaveRestoreLiveRegistersHelper(codegen, |
| 240 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 241 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 242 | } |
| 243 | |
| 244 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 245 | SaveRestoreLiveRegistersHelper(codegen, |
| 246 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 247 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 248 | } |
| 249 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 251 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 252 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 253 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 254 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 255 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 256 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 257 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 258 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 259 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 260 | // Live registers will be restored in the catch block if caught. |
| 261 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 262 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 263 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 264 | // move resolver. |
| 265 | InvokeRuntimeCallingConvention calling_convention; |
| 266 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 267 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 268 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 269 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 270 | ? kQuickThrowStringBounds |
| 271 | : kQuickThrowArrayBounds; |
| 272 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 273 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 274 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 277 | bool IsFatal() const OVERRIDE { return true; } |
| 278 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 279 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 280 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 282 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 283 | }; |
| 284 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 285 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 286 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 287 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 288 | |
| 289 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 290 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 291 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 292 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 293 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 296 | bool IsFatal() const OVERRIDE { return true; } |
| 297 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 298 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 299 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 301 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 302 | }; |
| 303 | |
| 304 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 305 | public: |
| 306 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 307 | HInstruction* at, |
| 308 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 309 | bool do_clinit, |
| 310 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 311 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 312 | : SlowPathCodeARM64(at), |
| 313 | cls_(cls), |
| 314 | dex_pc_(dex_pc), |
| 315 | do_clinit_(do_clinit), |
| 316 | bss_entry_temp_(bss_entry_temp), |
| 317 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 318 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 319 | } |
| 320 | |
| 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 322 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 323 | Location out = locations->Out(); |
| 324 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 325 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 326 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 327 | InvokeRuntimeCallingConvention calling_convention; |
| 328 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 329 | // 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] | 330 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 331 | bool is_load_class_bss_entry = |
| 332 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 333 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 334 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 335 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 336 | DCHECK( |
| 337 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 340 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 341 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 342 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 343 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 344 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 345 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 346 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 347 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 348 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 349 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 350 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 351 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 352 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 353 | |
| 354 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | if (out.IsValid()) { |
| 356 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 357 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 358 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 359 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 360 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 361 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 362 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 363 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 364 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 365 | if (call_saves_everything_except_r0_ip0) { |
| 366 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 367 | } else { |
| 368 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 369 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 370 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 371 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 372 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 373 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 374 | { |
| 375 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 376 | __ Bind(strp_label); |
| 377 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 378 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 379 | } |
| 380 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 381 | __ B(GetExitLabel()); |
| 382 | } |
| 383 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 384 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 385 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 386 | private: |
| 387 | // The class this slow path will load. |
| 388 | HLoadClass* const cls_; |
| 389 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 390 | // The dex PC of `at_`. |
| 391 | const uint32_t dex_pc_; |
| 392 | |
| 393 | // Whether to initialize the class. |
| 394 | const bool do_clinit_; |
| 395 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 396 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 397 | vixl::aarch64::Register bss_entry_temp_; |
| 398 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 399 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 400 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 401 | }; |
| 402 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 403 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 404 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 405 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 406 | : SlowPathCodeARM64(instruction), |
| 407 | temp_(temp), |
| 408 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 409 | |
| 410 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 411 | LocationSummary* locations = instruction_->GetLocations(); |
| 412 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 413 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 414 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 415 | InvokeRuntimeCallingConvention calling_convention; |
| 416 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 417 | DCHECK(temp_.IsValid()); |
| 418 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 419 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 420 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 421 | __ Bind(GetEntryLabel()); |
| 422 | SaveLiveRegisters(codegen, locations); |
| 423 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 424 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 425 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 426 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 427 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 428 | Primitive::Type type = instruction_->GetType(); |
| 429 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 430 | |
| 431 | RestoreLiveRegisters(codegen, locations); |
| 432 | |
| 433 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 434 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 435 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 436 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 437 | } else { |
| 438 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 439 | adrp_label_ = arm64_codegen->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 440 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 441 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 442 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 443 | arm64_codegen->NewStringBssEntryPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 444 | { |
| 445 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 446 | __ Bind(strp_label); |
| 447 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 448 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | __ B(GetExitLabel()); |
| 452 | } |
| 453 | |
| 454 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 455 | |
| 456 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 457 | const Register temp_; |
| 458 | vixl::aarch64::Label* adrp_label_; |
| 459 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 460 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 461 | }; |
| 462 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 463 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 464 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 465 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 466 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 467 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 468 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 469 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 470 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 471 | // Live registers will be restored in the catch block if caught. |
| 472 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 473 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 474 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 475 | instruction_, |
| 476 | instruction_->GetDexPc(), |
| 477 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 478 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 481 | bool IsFatal() const OVERRIDE { return true; } |
| 482 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 483 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 484 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 485 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 486 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 487 | }; |
| 488 | |
| 489 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 490 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 491 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 492 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 493 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 494 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 495 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 496 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 497 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 498 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 499 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 500 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 501 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 502 | if (successor_ == nullptr) { |
| 503 | __ B(GetReturnLabel()); |
| 504 | } else { |
| 505 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 506 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 509 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 510 | DCHECK(successor_ == nullptr); |
| 511 | return &return_label_; |
| 512 | } |
| 513 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 514 | HBasicBlock* GetSuccessor() const { |
| 515 | return successor_; |
| 516 | } |
| 517 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 518 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 519 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 520 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 521 | // If not null, the block to branch to after the suspend check. |
| 522 | HBasicBlock* const successor_; |
| 523 | |
| 524 | // 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] | 525 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 526 | |
| 527 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 528 | }; |
| 529 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 530 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 531 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 532 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 533 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 534 | |
| 535 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 536 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 537 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 538 | DCHECK(instruction_->IsCheckCast() |
| 539 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 540 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 541 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 542 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 543 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 544 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 545 | if (!is_fatal_) { |
| 546 | SaveLiveRegisters(codegen, locations); |
| 547 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 548 | |
| 549 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 550 | // move resolver. |
| 551 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 552 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 553 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 554 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 555 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 556 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 557 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 558 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 559 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 560 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 561 | Primitive::Type ret_type = instruction_->GetType(); |
| 562 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 563 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 564 | } else { |
| 565 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 566 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 567 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 570 | if (!is_fatal_) { |
| 571 | RestoreLiveRegisters(codegen, locations); |
| 572 | __ B(GetExitLabel()); |
| 573 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 576 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 577 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 578 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 579 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 580 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 581 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 582 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 583 | }; |
| 584 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 585 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 586 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 587 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 588 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 589 | |
| 590 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 591 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 592 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 593 | LocationSummary* locations = instruction_->GetLocations(); |
| 594 | SaveLiveRegisters(codegen, locations); |
| 595 | InvokeRuntimeCallingConvention calling_convention; |
| 596 | __ Mov(calling_convention.GetRegisterAt(0), |
| 597 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 598 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 599 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 602 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 603 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 604 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 605 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 606 | }; |
| 607 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 608 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 609 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 610 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 611 | |
| 612 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 613 | LocationSummary* locations = instruction_->GetLocations(); |
| 614 | __ Bind(GetEntryLabel()); |
| 615 | SaveLiveRegisters(codegen, locations); |
| 616 | |
| 617 | InvokeRuntimeCallingConvention calling_convention; |
| 618 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 619 | parallel_move.AddMove( |
| 620 | locations->InAt(0), |
| 621 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 622 | Primitive::kPrimNot, |
| 623 | nullptr); |
| 624 | parallel_move.AddMove( |
| 625 | locations->InAt(1), |
| 626 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 627 | Primitive::kPrimInt, |
| 628 | nullptr); |
| 629 | parallel_move.AddMove( |
| 630 | locations->InAt(2), |
| 631 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 632 | Primitive::kPrimNot, |
| 633 | nullptr); |
| 634 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 635 | |
| 636 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 637 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 638 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 639 | RestoreLiveRegisters(codegen, locations); |
| 640 | __ B(GetExitLabel()); |
| 641 | } |
| 642 | |
| 643 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 644 | |
| 645 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 646 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 647 | }; |
| 648 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 649 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 650 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 651 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 652 | |
| 653 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 654 | // 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] | 655 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 656 | num_entries * sizeof(int32_t), |
| 657 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 658 | |
| 659 | __ Bind(&table_start_); |
| 660 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 661 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 662 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 663 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 664 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 665 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 666 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 667 | Literal<int32_t> literal(jump_offset); |
| 668 | __ place(&literal); |
| 669 | } |
| 670 | } |
| 671 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 672 | // Abstract base class for read barrier slow paths marking a reference |
| 673 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 674 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 675 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 676 | // barrier marking runtime entry point to be invoked or an empty |
| 677 | // location; in the latter case, the read barrier marking runtime |
| 678 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 679 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 680 | protected: |
| 681 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 682 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 683 | DCHECK(kEmitCompilerReadBarrier); |
| 684 | } |
| 685 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 686 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 687 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 688 | // Generate assembly code calling the read barrier marking runtime |
| 689 | // entry point (ReadBarrierMarkRegX). |
| 690 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 691 | // No need to save live registers; it's taken care of by the |
| 692 | // entrypoint. Also, there is no need to update the stack mask, |
| 693 | // as this runtime call will not trigger a garbage collection. |
| 694 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 695 | DCHECK_NE(ref_.reg(), LR); |
| 696 | DCHECK_NE(ref_.reg(), WSP); |
| 697 | DCHECK_NE(ref_.reg(), WZR); |
| 698 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 699 | // as a temporary, it cannot be the entry point's input/output. |
| 700 | DCHECK_NE(ref_.reg(), IP0); |
| 701 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 702 | // "Compact" slow path, saving two moves. |
| 703 | // |
| 704 | // Instead of using the standard runtime calling convention (input |
| 705 | // and output in W0): |
| 706 | // |
| 707 | // W0 <- ref |
| 708 | // W0 <- ReadBarrierMark(W0) |
| 709 | // ref <- W0 |
| 710 | // |
| 711 | // we just use rX (the register containing `ref`) as input and output |
| 712 | // of a dedicated entrypoint: |
| 713 | // |
| 714 | // rX <- ReadBarrierMarkRegX(rX) |
| 715 | // |
| 716 | if (entrypoint_.IsValid()) { |
| 717 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 718 | __ Blr(XRegisterFrom(entrypoint_)); |
| 719 | } else { |
| 720 | // Entrypoint is not already loaded, load from the thread. |
| 721 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 722 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 723 | // This runtime call does not require a stack map. |
| 724 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | // The location (register) of the marked object reference. |
| 729 | const Location ref_; |
| 730 | |
| 731 | // The location of the entrypoint if it is already loaded. |
| 732 | const Location entrypoint_; |
| 733 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 734 | private: |
| 735 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 736 | }; |
| 737 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 738 | // Slow path marking an object reference `ref` during a read |
| 739 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 740 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 741 | // |
| 742 | // This means that after the execution of this slow path, `ref` will |
| 743 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 744 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 745 | // probably still be a from-space reference (unless it gets updated by |
| 746 | // another thread, or if another thread installed another object |
| 747 | // reference (different from `ref`) in `obj.field`). |
| 748 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 749 | // Argument `entrypoint` must be a register location holding the read |
| 750 | // barrier marking runtime entry point to be invoked or an empty |
| 751 | // location; in the latter case, the read barrier marking runtime |
| 752 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 753 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 754 | public: |
| 755 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 756 | Location ref, |
| 757 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 758 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 759 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 763 | |
| 764 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 765 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 766 | DCHECK(locations->CanCall()); |
| 767 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 768 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 769 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 770 | << "Unexpected instruction in read barrier marking slow path: " |
| 771 | << instruction_->DebugName(); |
| 772 | |
| 773 | __ Bind(GetEntryLabel()); |
| 774 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 775 | __ B(GetExitLabel()); |
| 776 | } |
| 777 | |
| 778 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 779 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 780 | }; |
| 781 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 782 | // Slow path loading `obj`'s lock word, loading a reference from |
| 783 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 784 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 785 | // read barrier). The field `obj.field` in the object `obj` holding |
| 786 | // this reference does not get updated by this slow path after marking |
| 787 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 788 | // below for that). |
| 789 | // |
| 790 | // This means that after the execution of this slow path, `ref` will |
| 791 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 792 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 793 | // probably still be a from-space reference (unless it gets updated by |
| 794 | // another thread, or if another thread installed another object |
| 795 | // reference (different from `ref`) in `obj.field`). |
| 796 | // |
| 797 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 798 | // barrier marking runtime entry point to be invoked or an empty |
| 799 | // location; in the latter case, the read barrier marking runtime |
| 800 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 801 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 802 | public: |
| 803 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 804 | Location ref, |
| 805 | Register obj, |
| 806 | uint32_t offset, |
| 807 | Location index, |
| 808 | size_t scale_factor, |
| 809 | bool needs_null_check, |
| 810 | bool use_load_acquire, |
| 811 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 812 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 813 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 814 | obj_(obj), |
| 815 | offset_(offset), |
| 816 | index_(index), |
| 817 | scale_factor_(scale_factor), |
| 818 | needs_null_check_(needs_null_check), |
| 819 | use_load_acquire_(use_load_acquire), |
| 820 | temp_(temp) { |
| 821 | DCHECK(kEmitCompilerReadBarrier); |
| 822 | DCHECK(kUseBakerReadBarrier); |
| 823 | } |
| 824 | |
| 825 | const char* GetDescription() const OVERRIDE { |
| 826 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 827 | } |
| 828 | |
| 829 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 830 | LocationSummary* locations = instruction_->GetLocations(); |
| 831 | DCHECK(locations->CanCall()); |
| 832 | DCHECK(ref_.IsRegister()) << ref_; |
| 833 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 834 | DCHECK(obj_.IsW()); |
| 835 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 836 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 837 | instruction_->IsStaticFieldGet() || |
| 838 | instruction_->IsArrayGet() || |
| 839 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 840 | instruction_->IsInstanceOf() || |
| 841 | instruction_->IsCheckCast() || |
| 842 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 843 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 844 | << "Unexpected instruction in read barrier marking slow path: " |
| 845 | << instruction_->DebugName(); |
| 846 | // The read barrier instrumentation of object ArrayGet |
| 847 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 848 | // instruction. |
| 849 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 850 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 851 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 852 | // Temporary register `temp_`, used to store the lock word, must |
| 853 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 854 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 855 | // need the lock word to still be in `temp_` after the reference |
| 856 | // load. |
| 857 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 858 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 859 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 860 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 861 | |
| 862 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 863 | // inserted after the original load. However, in fast path based |
| 864 | // Baker's read barriers, we need to perform the load of |
| 865 | // mirror::Object::monitor_ *before* the original reference load. |
| 866 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 867 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 868 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 869 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 870 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 871 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 872 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 873 | // if (is_gray) { |
| 874 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 875 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 876 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 877 | // Note: the original implementation in ReadBarrier::Barrier is |
| 878 | // slightly more complex as it performs additional checks that we do |
| 879 | // not do here for performance reasons. |
| 880 | |
| 881 | // /* int32_t */ monitor = obj->monitor_ |
| 882 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 883 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 884 | if (needs_null_check_) { |
| 885 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 886 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 887 | // /* LockWord */ lock_word = LockWord(monitor) |
| 888 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 889 | "art::LockWord and int32_t have different sizes."); |
| 890 | |
| 891 | // Introduce a dependency on the lock_word including rb_state, |
| 892 | // to prevent load-load reordering, and without using |
| 893 | // a memory barrier (which would be more expensive). |
| 894 | // `obj` is unchanged by this operation, but its value now depends |
| 895 | // on `temp`. |
| 896 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 897 | |
| 898 | // The actual reference load. |
| 899 | // A possible implicit null check has already been handled above. |
| 900 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 901 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 902 | ref_, |
| 903 | obj_, |
| 904 | offset_, |
| 905 | index_, |
| 906 | scale_factor_, |
| 907 | /* needs_null_check */ false, |
| 908 | use_load_acquire_); |
| 909 | |
| 910 | // Mark the object `ref` when `obj` is gray. |
| 911 | // |
| 912 | // if (rb_state == ReadBarrier::GrayState()) |
| 913 | // ref = ReadBarrier::Mark(ref); |
| 914 | // |
| 915 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 916 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 917 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 918 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 919 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 920 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 921 | __ B(GetExitLabel()); |
| 922 | } |
| 923 | |
| 924 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 925 | // The register containing the object holding the marked object reference field. |
| 926 | Register obj_; |
| 927 | // The offset, index and scale factor to access the reference in `obj_`. |
| 928 | uint32_t offset_; |
| 929 | Location index_; |
| 930 | size_t scale_factor_; |
| 931 | // Is a null check required? |
| 932 | bool needs_null_check_; |
| 933 | // Should this reference load use Load-Acquire semantics? |
| 934 | bool use_load_acquire_; |
| 935 | // A temporary register used to hold the lock word of `obj_`. |
| 936 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 937 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 938 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 939 | }; |
| 940 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 941 | // Slow path loading `obj`'s lock word, loading a reference from |
| 942 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 943 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 944 | // read barrier). If needed, this slow path also atomically updates |
| 945 | // the field `obj.field` in the object `obj` holding this reference |
| 946 | // after marking (contrary to |
| 947 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 948 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 949 | // |
| 950 | // This means that after the execution of this slow path, both `ref` |
| 951 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 952 | // hold the same to-space reference (unless another thread installed |
| 953 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 954 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 955 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 956 | // barrier marking runtime entry point to be invoked or an empty |
| 957 | // location; in the latter case, the read barrier marking runtime |
| 958 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 959 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 960 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 961 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 962 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 963 | HInstruction* instruction, |
| 964 | Location ref, |
| 965 | Register obj, |
| 966 | uint32_t offset, |
| 967 | Location index, |
| 968 | size_t scale_factor, |
| 969 | bool needs_null_check, |
| 970 | bool use_load_acquire, |
| 971 | Register temp, |
| 972 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 973 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 974 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 975 | offset_(offset), |
| 976 | index_(index), |
| 977 | scale_factor_(scale_factor), |
| 978 | needs_null_check_(needs_null_check), |
| 979 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 980 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 981 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 982 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 986 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 990 | LocationSummary* locations = instruction_->GetLocations(); |
| 991 | Register ref_reg = WRegisterFrom(ref_); |
| 992 | DCHECK(locations->CanCall()); |
| 993 | DCHECK(ref_.IsRegister()) << ref_; |
| 994 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 995 | DCHECK(obj_.IsW()); |
| 996 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 997 | |
| 998 | // 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] | 999 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1000 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1001 | << instruction_->DebugName(); |
| 1002 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1003 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1004 | DCHECK_EQ(offset_, 0u); |
| 1005 | DCHECK_EQ(scale_factor_, 0u); |
| 1006 | DCHECK_EQ(use_load_acquire_, false); |
| 1007 | // The location of the offset of the marked reference field within `obj_`. |
| 1008 | Location field_offset = index_; |
| 1009 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 1010 | |
| 1011 | // Temporary register `temp_`, used to store the lock word, must |
| 1012 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1013 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1014 | // need the lock word to still be in `temp_` after the reference |
| 1015 | // load. |
| 1016 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1017 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1018 | |
| 1019 | __ Bind(GetEntryLabel()); |
| 1020 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1021 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1022 | // |
| 1023 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1024 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1025 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1026 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1027 | // if (is_gray) { |
| 1028 | // old_ref = ref; |
| 1029 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1030 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1031 | // } |
| 1032 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1033 | // /* int32_t */ monitor = obj->monitor_ |
| 1034 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1035 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1036 | if (needs_null_check_) { |
| 1037 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1038 | } |
| 1039 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1040 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1041 | "art::LockWord and int32_t have different sizes."); |
| 1042 | |
| 1043 | // Introduce a dependency on the lock_word including rb_state, |
| 1044 | // to prevent load-load reordering, and without using |
| 1045 | // a memory barrier (which would be more expensive). |
| 1046 | // `obj` is unchanged by this operation, but its value now depends |
| 1047 | // on `temp`. |
| 1048 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1049 | |
| 1050 | // The actual reference load. |
| 1051 | // A possible implicit null check has already been handled above. |
| 1052 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1053 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1054 | ref_, |
| 1055 | obj_, |
| 1056 | offset_, |
| 1057 | index_, |
| 1058 | scale_factor_, |
| 1059 | /* needs_null_check */ false, |
| 1060 | use_load_acquire_); |
| 1061 | |
| 1062 | // Mark the object `ref` when `obj` is gray. |
| 1063 | // |
| 1064 | // if (rb_state == ReadBarrier::GrayState()) |
| 1065 | // ref = ReadBarrier::Mark(ref); |
| 1066 | // |
| 1067 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1068 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1069 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1070 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1071 | |
| 1072 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1073 | // Note that we cannot use IP to save the old reference, as IP is |
| 1074 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1075 | // need the old reference after the call to that entry point. |
| 1076 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1077 | __ Mov(temp_.W(), ref_reg); |
| 1078 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1079 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1080 | |
| 1081 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1082 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1083 | // |
| 1084 | // Note that this field could also hold a different object, if |
| 1085 | // another thread had concurrently changed it. In that case, the |
| 1086 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1087 | // (CAS) operation below would abort the CAS, leaving the field |
| 1088 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1089 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1090 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1091 | |
| 1092 | // Update the the holder's field atomically. This may fail if |
| 1093 | // mutator updates before us, but it's OK. This is achieved |
| 1094 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1095 | // memory synchronization ordering, where the expected value is |
| 1096 | // the old reference and the desired value is the new reference. |
| 1097 | |
| 1098 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1099 | UseScratchRegisterScope temps(masm); |
| 1100 | |
| 1101 | // Convenience aliases. |
| 1102 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1103 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1104 | Register expected = temp_.W(); |
| 1105 | Register value = ref_reg; |
| 1106 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1107 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1108 | |
| 1109 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1110 | |
| 1111 | if (kPoisonHeapReferences) { |
| 1112 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1113 | if (value.Is(expected)) { |
| 1114 | // Do not poison `value`, as it is the same register as |
| 1115 | // `expected`, which has just been poisoned. |
| 1116 | } else { |
| 1117 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | // do { |
| 1122 | // tmp_value = [tmp_ptr] - expected; |
| 1123 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1124 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1125 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1126 | __ Bind(&loop_head); |
| 1127 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1128 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1129 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1130 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1131 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1132 | __ B(&exit_loop); |
| 1133 | __ Bind(&comparison_failed); |
| 1134 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1135 | __ Bind(&exit_loop); |
| 1136 | |
| 1137 | if (kPoisonHeapReferences) { |
| 1138 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1139 | if (value.Is(expected)) { |
| 1140 | // Do not unpoison `value`, as it is the same register as |
| 1141 | // `expected`, which has just been unpoisoned. |
| 1142 | } else { |
| 1143 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1144 | } |
| 1145 | } |
| 1146 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1147 | __ B(GetExitLabel()); |
| 1148 | } |
| 1149 | |
| 1150 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1151 | // The register containing the object holding the marked object reference field. |
| 1152 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1153 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1154 | uint32_t offset_; |
| 1155 | Location index_; |
| 1156 | size_t scale_factor_; |
| 1157 | // Is a null check required? |
| 1158 | bool needs_null_check_; |
| 1159 | // Should this reference load use Load-Acquire semantics? |
| 1160 | bool use_load_acquire_; |
| 1161 | // A temporary register used to hold the lock word of `obj_`; and |
| 1162 | // also to hold the original reference value, when the reference is |
| 1163 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1164 | const Register temp_; |
| 1165 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1166 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1167 | }; |
| 1168 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1169 | // Slow path generating a read barrier for a heap reference. |
| 1170 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1171 | public: |
| 1172 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1173 | Location out, |
| 1174 | Location ref, |
| 1175 | Location obj, |
| 1176 | uint32_t offset, |
| 1177 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1178 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1179 | out_(out), |
| 1180 | ref_(ref), |
| 1181 | obj_(obj), |
| 1182 | offset_(offset), |
| 1183 | index_(index) { |
| 1184 | DCHECK(kEmitCompilerReadBarrier); |
| 1185 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1186 | // has been overwritten by (or after) the heap object reference load |
| 1187 | // to be instrumented, e.g.: |
| 1188 | // |
| 1189 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1190 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1191 | // |
| 1192 | // In that case, we have lost the information about the original |
| 1193 | // object, and the emitted read barrier cannot work properly. |
| 1194 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1195 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1196 | } |
| 1197 | |
| 1198 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1199 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1200 | LocationSummary* locations = instruction_->GetLocations(); |
| 1201 | Primitive::Type type = Primitive::kPrimNot; |
| 1202 | DCHECK(locations->CanCall()); |
| 1203 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1204 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1205 | instruction_->IsStaticFieldGet() || |
| 1206 | instruction_->IsArrayGet() || |
| 1207 | instruction_->IsInstanceOf() || |
| 1208 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1209 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1210 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1211 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1212 | // The read barrier instrumentation of object ArrayGet |
| 1213 | // instructions does not support the HIntermediateAddress |
| 1214 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1215 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1216 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1217 | |
| 1218 | __ Bind(GetEntryLabel()); |
| 1219 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1220 | SaveLiveRegisters(codegen, locations); |
| 1221 | |
| 1222 | // We may have to change the index's value, but as `index_` is a |
| 1223 | // constant member (like other "inputs" of this slow path), |
| 1224 | // introduce a copy of it, `index`. |
| 1225 | Location index = index_; |
| 1226 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1227 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1228 | if (instruction_->IsArrayGet()) { |
| 1229 | // Compute the actual memory offset and store it in `index`. |
| 1230 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1231 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1232 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1233 | // We are about to change the value of `index_reg` (see the |
| 1234 | // calls to vixl::MacroAssembler::Lsl and |
| 1235 | // vixl::MacroAssembler::Mov below), but it has |
| 1236 | // not been saved by the previous call to |
| 1237 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1238 | // callee-save register -- |
| 1239 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1240 | // callee-save registers, as it has been designed with the |
| 1241 | // assumption that callee-save registers are supposed to be |
| 1242 | // handled by the called function. So, as a callee-save |
| 1243 | // register, `index_reg` _would_ eventually be saved onto |
| 1244 | // the stack, but it would be too late: we would have |
| 1245 | // changed its value earlier. Therefore, we manually save |
| 1246 | // it here into another freely available register, |
| 1247 | // `free_reg`, chosen of course among the caller-save |
| 1248 | // registers (as a callee-save `free_reg` register would |
| 1249 | // exhibit the same problem). |
| 1250 | // |
| 1251 | // Note we could have requested a temporary register from |
| 1252 | // the register allocator instead; but we prefer not to, as |
| 1253 | // this is a slow path, and we know we can find a |
| 1254 | // caller-save register that is available. |
| 1255 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1256 | __ Mov(free_reg.W(), index_reg); |
| 1257 | index_reg = free_reg; |
| 1258 | index = LocationFrom(index_reg); |
| 1259 | } else { |
| 1260 | // The initial register stored in `index_` has already been |
| 1261 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1262 | // (as it is not a callee-save register), so we can freely |
| 1263 | // use it. |
| 1264 | } |
| 1265 | // Shifting the index value contained in `index_reg` by the scale |
| 1266 | // factor (2) cannot overflow in practice, as the runtime is |
| 1267 | // unable to allocate object arrays with a size larger than |
| 1268 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1269 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1270 | static_assert( |
| 1271 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1272 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1273 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1274 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1275 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1276 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1277 | // (as in the case of ArrayGet), as it is actually an offset |
| 1278 | // to an object field within an object. |
| 1279 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1280 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1281 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1282 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1283 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1284 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1285 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | // We're moving two or three locations to locations that could |
| 1290 | // overlap, so we need a parallel move resolver. |
| 1291 | InvokeRuntimeCallingConvention calling_convention; |
| 1292 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1293 | parallel_move.AddMove(ref_, |
| 1294 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1295 | type, |
| 1296 | nullptr); |
| 1297 | parallel_move.AddMove(obj_, |
| 1298 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1299 | type, |
| 1300 | nullptr); |
| 1301 | if (index.IsValid()) { |
| 1302 | parallel_move.AddMove(index, |
| 1303 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1304 | Primitive::kPrimInt, |
| 1305 | nullptr); |
| 1306 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1307 | } else { |
| 1308 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1309 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1310 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1311 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1312 | instruction_, |
| 1313 | instruction_->GetDexPc(), |
| 1314 | this); |
| 1315 | CheckEntrypointTypes< |
| 1316 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1317 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1318 | |
| 1319 | RestoreLiveRegisters(codegen, locations); |
| 1320 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1321 | __ B(GetExitLabel()); |
| 1322 | } |
| 1323 | |
| 1324 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1325 | |
| 1326 | private: |
| 1327 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1328 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1329 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1330 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1331 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1332 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1333 | } |
| 1334 | } |
| 1335 | // We shall never fail to find a free caller-save register, as |
| 1336 | // there are more than two core caller-save registers on ARM64 |
| 1337 | // (meaning it is possible to find one which is different from |
| 1338 | // `ref` and `obj`). |
| 1339 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1340 | LOG(FATAL) << "Could not find a free register"; |
| 1341 | UNREACHABLE(); |
| 1342 | } |
| 1343 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1344 | const Location out_; |
| 1345 | const Location ref_; |
| 1346 | const Location obj_; |
| 1347 | const uint32_t offset_; |
| 1348 | // An additional location containing an index to an array. |
| 1349 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1350 | // UnsafeGetObjectVolatile intrinsics. |
| 1351 | const Location index_; |
| 1352 | |
| 1353 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1354 | }; |
| 1355 | |
| 1356 | // Slow path generating a read barrier for a GC root. |
| 1357 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1358 | public: |
| 1359 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1360 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1361 | DCHECK(kEmitCompilerReadBarrier); |
| 1362 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1363 | |
| 1364 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1365 | LocationSummary* locations = instruction_->GetLocations(); |
| 1366 | Primitive::Type type = Primitive::kPrimNot; |
| 1367 | DCHECK(locations->CanCall()); |
| 1368 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1369 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1370 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1371 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1372 | |
| 1373 | __ Bind(GetEntryLabel()); |
| 1374 | SaveLiveRegisters(codegen, locations); |
| 1375 | |
| 1376 | InvokeRuntimeCallingConvention calling_convention; |
| 1377 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1378 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1379 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1380 | // thus we need a 64-bit move here, and we cannot use |
| 1381 | // |
| 1382 | // arm64_codegen->MoveLocation( |
| 1383 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1384 | // root_, |
| 1385 | // type); |
| 1386 | // |
| 1387 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1388 | // reference type (`Primitive::kPrimNot`). |
| 1389 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1390 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1391 | instruction_, |
| 1392 | instruction_->GetDexPc(), |
| 1393 | this); |
| 1394 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1395 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1396 | |
| 1397 | RestoreLiveRegisters(codegen, locations); |
| 1398 | __ B(GetExitLabel()); |
| 1399 | } |
| 1400 | |
| 1401 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1402 | |
| 1403 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1404 | const Location out_; |
| 1405 | const Location root_; |
| 1406 | |
| 1407 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1408 | }; |
| 1409 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1410 | #undef __ |
| 1411 | |
| 1412 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1413 | Location next_location; |
| 1414 | if (type == Primitive::kPrimVoid) { |
| 1415 | LOG(FATAL) << "Unreachable type " << type; |
| 1416 | } |
| 1417 | |
| 1418 | if (Primitive::IsFloatingPointType(type) && |
| 1419 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1420 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1421 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1422 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1423 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1424 | } else { |
| 1425 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1426 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1427 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1428 | } |
| 1429 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1430 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1431 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1432 | return next_location; |
| 1433 | } |
| 1434 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1435 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1436 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1437 | } |
| 1438 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1439 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1440 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1441 | const CompilerOptions& compiler_options, |
| 1442 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1443 | : CodeGenerator(graph, |
| 1444 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1445 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1446 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1447 | callee_saved_core_registers.GetList(), |
| 1448 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1449 | compiler_options, |
| 1450 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1451 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1452 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1453 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1454 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1455 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1456 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1457 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1458 | uint32_literals_(std::less<uint32_t>(), |
| 1459 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1460 | uint64_literals_(std::less<uint64_t>(), |
| 1461 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1462 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1463 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1464 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1465 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1466 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1467 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1468 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1469 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1470 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1471 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1472 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1473 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1474 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1475 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1476 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1477 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1478 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1479 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1480 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1481 | jump_table->EmitTable(this); |
| 1482 | } |
| 1483 | } |
| 1484 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1485 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1486 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1487 | // Ensure we emit the literal pool. |
| 1488 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1489 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1490 | CodeGenerator::Finalize(allocator); |
| 1491 | } |
| 1492 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1493 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1494 | // Note: There are 6 kinds of moves: |
| 1495 | // 1. constant -> GPR/FPR (non-cycle) |
| 1496 | // 2. constant -> stack (non-cycle) |
| 1497 | // 3. GPR/FPR -> GPR/FPR |
| 1498 | // 4. GPR/FPR -> stack |
| 1499 | // 5. stack -> GPR/FPR |
| 1500 | // 6. stack -> stack (non-cycle) |
| 1501 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1502 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1503 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1504 | // dependency. |
| 1505 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1506 | } |
| 1507 | |
| 1508 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1509 | vixl_temps_.Close(); |
| 1510 | } |
| 1511 | |
| 1512 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1513 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1514 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1515 | || kind == Location::kSIMDStackSlot); |
| 1516 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1517 | ? Location::kFpuRegister |
| 1518 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1519 | Location scratch = GetScratchLocation(kind); |
| 1520 | if (!scratch.Equals(Location::NoLocation())) { |
| 1521 | return scratch; |
| 1522 | } |
| 1523 | // Allocate from VIXL temp registers. |
| 1524 | if (kind == Location::kRegister) { |
| 1525 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1526 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1527 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1528 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1529 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1530 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1531 | } |
| 1532 | AddScratchLocation(scratch); |
| 1533 | return scratch; |
| 1534 | } |
| 1535 | |
| 1536 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1537 | if (loc.IsRegister()) { |
| 1538 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1539 | } else { |
| 1540 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1541 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1542 | } |
| 1543 | RemoveScratchLocation(loc); |
| 1544 | } |
| 1545 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1546 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1547 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1548 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1551 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1552 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1553 | __ Bind(&frame_entry_label_); |
| 1554 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1555 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1556 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1557 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1558 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1559 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1560 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1561 | { |
| 1562 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1563 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1564 | kInstructionSize, |
| 1565 | CodeBufferCheckScope::kExactSize); |
| 1566 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1567 | RecordPcInfo(nullptr, 0); |
| 1568 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1569 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1570 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1571 | if (!HasEmptyFrame()) { |
| 1572 | int frame_size = GetFrameSize(); |
| 1573 | // Stack layout: |
| 1574 | // sp[frame_size - 8] : lr. |
| 1575 | // ... : other preserved core registers. |
| 1576 | // ... : other preserved fp registers. |
| 1577 | // ... : reserved frame space. |
| 1578 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1579 | |
| 1580 | // Save the current method if we need it. Note that we do not |
| 1581 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1582 | // in the SSA graph. |
| 1583 | if (RequiresCurrentMethod()) { |
| 1584 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1585 | } else { |
| 1586 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1587 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1588 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1589 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1590 | frame_size - GetCoreSpillSize()); |
| 1591 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1592 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1593 | |
| 1594 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1595 | // Initialize should_deoptimize flag to 0. |
| 1596 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1597 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1598 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1599 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1600 | |
| 1601 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1605 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1606 | if (!HasEmptyFrame()) { |
| 1607 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1608 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1609 | frame_size - FrameEntrySpillSize()); |
| 1610 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1611 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1612 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1613 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1614 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1615 | __ Ret(); |
| 1616 | GetAssembler()->cfi().RestoreState(); |
| 1617 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1620 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1621 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1622 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1623 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1624 | } |
| 1625 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1626 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1627 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1628 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1629 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1630 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1631 | } |
| 1632 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1633 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1634 | __ Bind(GetLabelOf(block)); |
| 1635 | } |
| 1636 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1637 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1638 | DCHECK(location.IsRegister()); |
| 1639 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1640 | } |
| 1641 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1642 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1643 | if (location.IsRegister()) { |
| 1644 | locations->AddTemp(location); |
| 1645 | } else { |
| 1646 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1647 | } |
| 1648 | } |
| 1649 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1650 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1651 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1652 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1653 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1654 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1655 | if (value_can_be_null) { |
| 1656 | __ Cbz(value, &done); |
| 1657 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1658 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1659 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1660 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1661 | if (value_can_be_null) { |
| 1662 | __ Bind(&done); |
| 1663 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1664 | } |
| 1665 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1666 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1667 | // Blocked core registers: |
| 1668 | // lr : Runtime reserved. |
| 1669 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1670 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1671 | // ip1 : VIXL core temp. |
| 1672 | // ip0 : VIXL core temp. |
| 1673 | // |
| 1674 | // Blocked fp registers: |
| 1675 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1676 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1677 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1678 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1679 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1680 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1681 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1682 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1683 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1684 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1685 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1686 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1687 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1688 | // Stubs do not save callee-save floating point registers. If the graph |
| 1689 | // is debuggable, we need to deal with these registers differently. For |
| 1690 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1691 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1692 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1693 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1694 | } |
| 1695 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1696 | } |
| 1697 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1698 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1699 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1700 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1701 | return kArm64WordSize; |
| 1702 | } |
| 1703 | |
| 1704 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1705 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1706 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1707 | return kArm64WordSize; |
| 1708 | } |
| 1709 | |
| 1710 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1711 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1712 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1713 | return kArm64WordSize; |
| 1714 | } |
| 1715 | |
| 1716 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1717 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1718 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1719 | return kArm64WordSize; |
| 1720 | } |
| 1721 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1722 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1723 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1727 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1730 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1731 | if (constant->IsIntConstant()) { |
| 1732 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1733 | } else if (constant->IsLongConstant()) { |
| 1734 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1735 | } else if (constant->IsNullConstant()) { |
| 1736 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1737 | } else if (constant->IsFloatConstant()) { |
| 1738 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1739 | } else { |
| 1740 | DCHECK(constant->IsDoubleConstant()); |
| 1741 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1742 | } |
| 1743 | } |
| 1744 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1745 | |
| 1746 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1747 | DCHECK(constant.IsConstant()); |
| 1748 | HConstant* cst = constant.GetConstant(); |
| 1749 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1750 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1751 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1752 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1753 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1754 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1755 | } |
| 1756 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1757 | // Allocate a scratch register from the VIXL pool, querying first |
| 1758 | // the floating-point register pool, and then the core register |
| 1759 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1760 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1761 | // using a different allocation strategy. |
| 1762 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1763 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1764 | int size_in_bits) { |
| 1765 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1766 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1767 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1768 | } |
| 1769 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1770 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1771 | Location source, |
| 1772 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1773 | if (source.Equals(destination)) { |
| 1774 | return; |
| 1775 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1776 | |
| 1777 | // A valid move can always be inferred from the destination and source |
| 1778 | // locations. When moving from and to a register, the argument type can be |
| 1779 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1780 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1781 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1782 | |
| 1783 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1784 | if (unspecified_type) { |
| 1785 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1786 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1787 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1788 | || src_cst->IsFloatConstant() |
| 1789 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1790 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1791 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1792 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1793 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1794 | // type is appropriate. Else the source is a register, and since the |
| 1795 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1796 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1797 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1798 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1799 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1800 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1801 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1802 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1803 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1804 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1805 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1806 | } else if (source.IsSIMDStackSlot()) { |
| 1807 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1808 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1809 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1810 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1811 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1812 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1813 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1814 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1815 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1816 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1817 | ? Primitive::kPrimLong |
| 1818 | : Primitive::kPrimInt; |
| 1819 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1820 | } |
| 1821 | } else { |
| 1822 | DCHECK(source.IsFpuRegister()); |
| 1823 | if (destination.IsRegister()) { |
| 1824 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1825 | ? Primitive::kPrimDouble |
| 1826 | : Primitive::kPrimFloat; |
| 1827 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1828 | } else { |
| 1829 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1830 | if (GetGraph()->HasSIMD()) { |
| 1831 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1832 | } else { |
| 1833 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | } else if (destination.IsSIMDStackSlot()) { |
| 1838 | if (source.IsFpuRegister()) { |
| 1839 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1840 | } else { |
| 1841 | DCHECK(source.IsSIMDStackSlot()); |
| 1842 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1843 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1844 | Register temp = temps.AcquireX(); |
| 1845 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1846 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1847 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1848 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1849 | } else { |
| 1850 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1851 | __ Ldr(temp, StackOperandFrom(source)); |
| 1852 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1853 | } |
| 1854 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1855 | } else { // The destination is not a register. It must be a stack slot. |
| 1856 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1857 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1858 | if (unspecified_type) { |
| 1859 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1860 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1861 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1862 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1863 | } |
| 1864 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1865 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1866 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1867 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1868 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1869 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1870 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1871 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1872 | HConstant* src_cst = source.GetConstant(); |
| 1873 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1874 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1875 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1876 | ? Register(xzr) |
| 1877 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1878 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1879 | if (src_cst->IsIntConstant()) { |
| 1880 | temp = temps.AcquireW(); |
| 1881 | } else if (src_cst->IsLongConstant()) { |
| 1882 | temp = temps.AcquireX(); |
| 1883 | } else if (src_cst->IsFloatConstant()) { |
| 1884 | temp = temps.AcquireS(); |
| 1885 | } else { |
| 1886 | DCHECK(src_cst->IsDoubleConstant()); |
| 1887 | temp = temps.AcquireD(); |
| 1888 | } |
| 1889 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1890 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1891 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1892 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1893 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1894 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1895 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1896 | // Use any scratch register (a core or a floating-point one) |
| 1897 | // from VIXL scratch register pools as a temporary. |
| 1898 | // |
| 1899 | // We used to only use the FP scratch register pool, but in some |
| 1900 | // rare cases the only register from this pool (D31) would |
| 1901 | // already be used (e.g. within a ParallelMove instruction, when |
| 1902 | // a move is blocked by a another move requiring a scratch FP |
| 1903 | // register, which would reserve D31). To prevent this issue, we |
| 1904 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1905 | // |
| 1906 | // 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] | 1907 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1908 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1909 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1910 | // allocates core scratch registers first. |
| 1911 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1912 | GetVIXLAssembler(), |
| 1913 | &temps, |
| 1914 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1915 | __ Ldr(temp, StackOperandFrom(source)); |
| 1916 | __ Str(temp, StackOperandFrom(destination)); |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1922 | CPURegister dst, |
| 1923 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1924 | switch (type) { |
| 1925 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1926 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1929 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1930 | break; |
| 1931 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1932 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1933 | break; |
| 1934 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1935 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1936 | break; |
| 1937 | case Primitive::kPrimInt: |
| 1938 | case Primitive::kPrimNot: |
| 1939 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1940 | case Primitive::kPrimFloat: |
| 1941 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1942 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1943 | __ Ldr(dst, src); |
| 1944 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1945 | case Primitive::kPrimVoid: |
| 1946 | LOG(FATAL) << "Unreachable type " << type; |
| 1947 | } |
| 1948 | } |
| 1949 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1950 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1951 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1952 | const MemOperand& src, |
| 1953 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1954 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1955 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1956 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1957 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1958 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1959 | DCHECK(!src.IsPreIndex()); |
| 1960 | DCHECK(!src.IsPostIndex()); |
| 1961 | |
| 1962 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1963 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1964 | { |
| 1965 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1966 | MemOperand base = MemOperand(temp_base); |
| 1967 | switch (type) { |
| 1968 | case Primitive::kPrimBoolean: |
| 1969 | { |
| 1970 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1971 | __ ldarb(Register(dst), base); |
| 1972 | if (needs_null_check) { |
| 1973 | MaybeRecordImplicitNullCheck(instruction); |
| 1974 | } |
| 1975 | } |
| 1976 | break; |
| 1977 | case Primitive::kPrimByte: |
| 1978 | { |
| 1979 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1980 | __ ldarb(Register(dst), base); |
| 1981 | if (needs_null_check) { |
| 1982 | MaybeRecordImplicitNullCheck(instruction); |
| 1983 | } |
| 1984 | } |
| 1985 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1986 | break; |
| 1987 | case Primitive::kPrimChar: |
| 1988 | { |
| 1989 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1990 | __ ldarh(Register(dst), base); |
| 1991 | if (needs_null_check) { |
| 1992 | MaybeRecordImplicitNullCheck(instruction); |
| 1993 | } |
| 1994 | } |
| 1995 | break; |
| 1996 | case Primitive::kPrimShort: |
| 1997 | { |
| 1998 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1999 | __ ldarh(Register(dst), base); |
| 2000 | if (needs_null_check) { |
| 2001 | MaybeRecordImplicitNullCheck(instruction); |
| 2002 | } |
| 2003 | } |
| 2004 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 2005 | break; |
| 2006 | case Primitive::kPrimInt: |
| 2007 | case Primitive::kPrimNot: |
| 2008 | case Primitive::kPrimLong: |
| 2009 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 2010 | { |
| 2011 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2012 | __ ldar(Register(dst), base); |
| 2013 | if (needs_null_check) { |
| 2014 | MaybeRecordImplicitNullCheck(instruction); |
| 2015 | } |
| 2016 | } |
| 2017 | break; |
| 2018 | case Primitive::kPrimFloat: |
| 2019 | case Primitive::kPrimDouble: { |
| 2020 | DCHECK(dst.IsFPRegister()); |
| 2021 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2022 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2023 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2024 | { |
| 2025 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2026 | __ ldar(temp, base); |
| 2027 | if (needs_null_check) { |
| 2028 | MaybeRecordImplicitNullCheck(instruction); |
| 2029 | } |
| 2030 | } |
| 2031 | __ Fmov(FPRegister(dst), temp); |
| 2032 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2033 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2034 | case Primitive::kPrimVoid: |
| 2035 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2036 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2040 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2041 | CPURegister src, |
| 2042 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2043 | switch (type) { |
| 2044 | case Primitive::kPrimBoolean: |
| 2045 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2046 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2047 | break; |
| 2048 | case Primitive::kPrimChar: |
| 2049 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2050 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2051 | break; |
| 2052 | case Primitive::kPrimInt: |
| 2053 | case Primitive::kPrimNot: |
| 2054 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2055 | case Primitive::kPrimFloat: |
| 2056 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2057 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2058 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2059 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2060 | case Primitive::kPrimVoid: |
| 2061 | LOG(FATAL) << "Unreachable type " << type; |
| 2062 | } |
| 2063 | } |
| 2064 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2065 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2066 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2067 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2068 | const MemOperand& dst, |
| 2069 | bool needs_null_check) { |
| 2070 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2071 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2072 | Register temp_base = temps.AcquireX(); |
| 2073 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2074 | DCHECK(!dst.IsPreIndex()); |
| 2075 | DCHECK(!dst.IsPostIndex()); |
| 2076 | |
| 2077 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2078 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2079 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2080 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2081 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2082 | switch (type) { |
| 2083 | case Primitive::kPrimBoolean: |
| 2084 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2085 | { |
| 2086 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2087 | __ stlrb(Register(src), base); |
| 2088 | if (needs_null_check) { |
| 2089 | MaybeRecordImplicitNullCheck(instruction); |
| 2090 | } |
| 2091 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | case Primitive::kPrimChar: |
| 2094 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2095 | { |
| 2096 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2097 | __ stlrh(Register(src), base); |
| 2098 | if (needs_null_check) { |
| 2099 | MaybeRecordImplicitNullCheck(instruction); |
| 2100 | } |
| 2101 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | case Primitive::kPrimInt: |
| 2104 | case Primitive::kPrimNot: |
| 2105 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2106 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2107 | { |
| 2108 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2109 | __ stlr(Register(src), base); |
| 2110 | if (needs_null_check) { |
| 2111 | MaybeRecordImplicitNullCheck(instruction); |
| 2112 | } |
| 2113 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2114 | break; |
| 2115 | case Primitive::kPrimFloat: |
| 2116 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2117 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2118 | Register temp_src; |
| 2119 | if (src.IsZero()) { |
| 2120 | // The zero register is used to avoid synthesizing zero constants. |
| 2121 | temp_src = Register(src); |
| 2122 | } else { |
| 2123 | DCHECK(src.IsFPRegister()); |
| 2124 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2125 | __ Fmov(temp_src, FPRegister(src)); |
| 2126 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2127 | { |
| 2128 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2129 | __ stlr(temp_src, base); |
| 2130 | if (needs_null_check) { |
| 2131 | MaybeRecordImplicitNullCheck(instruction); |
| 2132 | } |
| 2133 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2134 | break; |
| 2135 | } |
| 2136 | case Primitive::kPrimVoid: |
| 2137 | LOG(FATAL) << "Unreachable type " << type; |
| 2138 | } |
| 2139 | } |
| 2140 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2141 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2142 | HInstruction* instruction, |
| 2143 | uint32_t dex_pc, |
| 2144 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2145 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2146 | |
| 2147 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2148 | { |
| 2149 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2150 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2151 | __ blr(lr); |
| 2152 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2153 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2154 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2155 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2158 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2159 | HInstruction* instruction, |
| 2160 | SlowPathCode* slow_path) { |
| 2161 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2162 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2163 | __ Blr(lr); |
| 2164 | } |
| 2165 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2166 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2167 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2168 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2169 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2170 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2171 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2172 | // 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] | 2173 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2174 | __ Add(temp, class_reg, status_offset); |
| 2175 | __ Ldar(temp, HeapOperand(temp)); |
| 2176 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2177 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2178 | __ Bind(slow_path->GetExitLabel()); |
| 2179 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2180 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2181 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2182 | BarrierType type = BarrierAll; |
| 2183 | |
| 2184 | switch (kind) { |
| 2185 | case MemBarrierKind::kAnyAny: |
| 2186 | case MemBarrierKind::kAnyStore: { |
| 2187 | type = BarrierAll; |
| 2188 | break; |
| 2189 | } |
| 2190 | case MemBarrierKind::kLoadAny: { |
| 2191 | type = BarrierReads; |
| 2192 | break; |
| 2193 | } |
| 2194 | case MemBarrierKind::kStoreStore: { |
| 2195 | type = BarrierWrites; |
| 2196 | break; |
| 2197 | } |
| 2198 | default: |
| 2199 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2200 | } |
| 2201 | __ Dmb(InnerShareable, type); |
| 2202 | } |
| 2203 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2204 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2205 | HBasicBlock* successor) { |
| 2206 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2207 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2208 | if (slow_path == nullptr) { |
| 2209 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2210 | instruction->SetSlowPath(slow_path); |
| 2211 | codegen_->AddSlowPath(slow_path); |
| 2212 | if (successor != nullptr) { |
| 2213 | DCHECK(successor->IsLoopHeader()); |
| 2214 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2215 | } |
| 2216 | } else { |
| 2217 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2218 | } |
| 2219 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2220 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2221 | Register temp = temps.AcquireW(); |
| 2222 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2223 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2224 | if (successor == nullptr) { |
| 2225 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2226 | __ Bind(slow_path->GetReturnLabel()); |
| 2227 | } else { |
| 2228 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2229 | __ B(slow_path->GetEntryLabel()); |
| 2230 | // slow_path will return to GetLabelOf(successor). |
| 2231 | } |
| 2232 | } |
| 2233 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2234 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2235 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2236 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2237 | assembler_(codegen->GetAssembler()), |
| 2238 | codegen_(codegen) {} |
| 2239 | |
| 2240 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2241 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2242 | |
| 2243 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2244 | |
| 2245 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2246 | // Using a base helps identify when we hit such breakpoints. |
| 2247 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2248 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2249 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2250 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2251 | }; |
| 2252 | |
| 2253 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2254 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2255 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2256 | } \ |
| 2257 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2258 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2259 | locations->SetOut(Location::Any()); \ |
| 2260 | } |
| 2261 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2262 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2263 | |
| 2264 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2265 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2266 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2267 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2268 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2269 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2270 | Primitive::Type type = instr->GetResultType(); |
| 2271 | switch (type) { |
| 2272 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2273 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2274 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2275 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2276 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2277 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2278 | |
| 2279 | case Primitive::kPrimFloat: |
| 2280 | case Primitive::kPrimDouble: |
| 2281 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2282 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2283 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2284 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2285 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2286 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2287 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2288 | } |
| 2289 | } |
| 2290 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2291 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2292 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2293 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2294 | |
| 2295 | bool object_field_get_with_read_barrier = |
| 2296 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2297 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2298 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2299 | object_field_get_with_read_barrier ? |
| 2300 | LocationSummary::kCallOnSlowPath : |
| 2301 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2302 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2303 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2304 | // We need a temporary register for the read barrier marking slow |
| 2305 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2306 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2307 | !Runtime::Current()->UseJitCompilation() && |
| 2308 | !field_info.IsVolatile()) { |
| 2309 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2310 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2311 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2312 | locations->AddTemp(FixedTempLocation()); |
| 2313 | } |
| 2314 | } else { |
| 2315 | locations->AddTemp(Location::RequiresRegister()); |
| 2316 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2317 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2318 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2319 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2320 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2321 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2322 | // The output overlaps for an object field get when read barriers |
| 2323 | // are enabled: we do not want the load to overwrite the object's |
| 2324 | // location, as we need it to emit the read barrier. |
| 2325 | locations->SetOut( |
| 2326 | Location::RequiresRegister(), |
| 2327 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2332 | const FieldInfo& field_info) { |
| 2333 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2334 | LocationSummary* locations = instruction->GetLocations(); |
| 2335 | Location base_loc = locations->InAt(0); |
| 2336 | Location out = locations->Out(); |
| 2337 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2338 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2339 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2340 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2341 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2342 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2343 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2344 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2345 | Location maybe_temp = |
| 2346 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2347 | // Note that potential implicit null checks are handled in this |
| 2348 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2349 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2350 | instruction, |
| 2351 | out, |
| 2352 | base, |
| 2353 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2354 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2355 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2356 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2357 | } else { |
| 2358 | // General case. |
| 2359 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2360 | // Note that a potential implicit null check is handled in this |
| 2361 | // CodeGeneratorARM64::LoadAcquire call. |
| 2362 | // NB: LoadAcquire will record the pc info if needed. |
| 2363 | codegen_->LoadAcquire( |
| 2364 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2365 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2366 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2367 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2368 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2369 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2370 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2371 | if (field_type == Primitive::kPrimNot) { |
| 2372 | // If read barriers are enabled, emit read barriers other than |
| 2373 | // Baker's using a slow path (and also unpoison the loaded |
| 2374 | // reference, if heap poisoning is enabled). |
| 2375 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2376 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2377 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2381 | LocationSummary* locations = |
| 2382 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2383 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2384 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2385 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2386 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2387 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2388 | } else { |
| 2389 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2394 | const FieldInfo& field_info, |
| 2395 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2396 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2397 | |
| 2398 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2399 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2400 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2401 | Offset offset = field_info.GetFieldOffset(); |
| 2402 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2403 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2404 | { |
| 2405 | // We use a block to end the scratch scope before the write barrier, thus |
| 2406 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2407 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2408 | |
| 2409 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2410 | DCHECK(value.IsW()); |
| 2411 | Register temp = temps.AcquireW(); |
| 2412 | __ Mov(temp, value.W()); |
| 2413 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2414 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2415 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2416 | |
| 2417 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2418 | codegen_->StoreRelease( |
| 2419 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2420 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2421 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2422 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2423 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2424 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2425 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2429 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2433 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2434 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2435 | |
| 2436 | switch (type) { |
| 2437 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2438 | case Primitive::kPrimLong: { |
| 2439 | Register dst = OutputRegister(instr); |
| 2440 | Register lhs = InputRegisterAt(instr, 0); |
| 2441 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2442 | if (instr->IsAdd()) { |
| 2443 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2444 | } else if (instr->IsAnd()) { |
| 2445 | __ And(dst, lhs, rhs); |
| 2446 | } else if (instr->IsOr()) { |
| 2447 | __ Orr(dst, lhs, rhs); |
| 2448 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2449 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2450 | } else if (instr->IsRor()) { |
| 2451 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2452 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2453 | __ Ror(dst, lhs, shift); |
| 2454 | } else { |
| 2455 | // Ensure shift distance is in the same size register as the result. If |
| 2456 | // we are rotating a long and the shift comes in a w register originally, |
| 2457 | // we don't need to sxtw for use as an x since the shift distances are |
| 2458 | // all & reg_bits - 1. |
| 2459 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2460 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2461 | } else { |
| 2462 | DCHECK(instr->IsXor()); |
| 2463 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2464 | } |
| 2465 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2466 | } |
| 2467 | case Primitive::kPrimFloat: |
| 2468 | case Primitive::kPrimDouble: { |
| 2469 | FPRegister dst = OutputFPRegister(instr); |
| 2470 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2471 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2472 | if (instr->IsAdd()) { |
| 2473 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2474 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2475 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2476 | } else { |
| 2477 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2478 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2479 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2480 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2481 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2482 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2483 | } |
| 2484 | } |
| 2485 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2486 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2487 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2488 | |
| 2489 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2490 | Primitive::Type type = instr->GetResultType(); |
| 2491 | switch (type) { |
| 2492 | case Primitive::kPrimInt: |
| 2493 | case Primitive::kPrimLong: { |
| 2494 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2495 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2496 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2497 | break; |
| 2498 | } |
| 2499 | default: |
| 2500 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2505 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2506 | |
| 2507 | Primitive::Type type = instr->GetType(); |
| 2508 | switch (type) { |
| 2509 | case Primitive::kPrimInt: |
| 2510 | case Primitive::kPrimLong: { |
| 2511 | Register dst = OutputRegister(instr); |
| 2512 | Register lhs = InputRegisterAt(instr, 0); |
| 2513 | Operand rhs = InputOperandAt(instr, 1); |
| 2514 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2515 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2516 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2517 | if (instr->IsShl()) { |
| 2518 | __ Lsl(dst, lhs, shift_value); |
| 2519 | } else if (instr->IsShr()) { |
| 2520 | __ Asr(dst, lhs, shift_value); |
| 2521 | } else { |
| 2522 | __ Lsr(dst, lhs, shift_value); |
| 2523 | } |
| 2524 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2525 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2526 | |
| 2527 | if (instr->IsShl()) { |
| 2528 | __ Lsl(dst, lhs, rhs_reg); |
| 2529 | } else if (instr->IsShr()) { |
| 2530 | __ Asr(dst, lhs, rhs_reg); |
| 2531 | } else { |
| 2532 | __ Lsr(dst, lhs, rhs_reg); |
| 2533 | } |
| 2534 | } |
| 2535 | break; |
| 2536 | } |
| 2537 | default: |
| 2538 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2539 | } |
| 2540 | } |
| 2541 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2542 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2543 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2547 | HandleBinaryOp(instruction); |
| 2548 | } |
| 2549 | |
| 2550 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2551 | HandleBinaryOp(instruction); |
| 2552 | } |
| 2553 | |
| 2554 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2555 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2558 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2559 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2560 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2561 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2562 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2563 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2564 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2565 | } |
| 2566 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2567 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2568 | Register dst = OutputRegister(instr); |
| 2569 | Register lhs = InputRegisterAt(instr, 0); |
| 2570 | Register rhs = InputRegisterAt(instr, 1); |
| 2571 | |
| 2572 | switch (instr->GetOpKind()) { |
| 2573 | case HInstruction::kAnd: |
| 2574 | __ Bic(dst, lhs, rhs); |
| 2575 | break; |
| 2576 | case HInstruction::kOr: |
| 2577 | __ Orn(dst, lhs, rhs); |
| 2578 | break; |
| 2579 | case HInstruction::kXor: |
| 2580 | __ Eon(dst, lhs, rhs); |
| 2581 | break; |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unreachable"; |
| 2584 | } |
| 2585 | } |
| 2586 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2587 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2588 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2589 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2590 | instruction->GetType() == Primitive::kPrimLong); |
| 2591 | LocationSummary* locations = |
| 2592 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2593 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2594 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2595 | } else { |
| 2596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2597 | } |
| 2598 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2599 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2600 | } |
| 2601 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2602 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2603 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2604 | Primitive::Type type = instruction->GetType(); |
| 2605 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2606 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2607 | Register out = OutputRegister(instruction); |
| 2608 | Register left; |
| 2609 | if (kind != HInstruction::kNeg) { |
| 2610 | left = InputRegisterAt(instruction, 0); |
| 2611 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2612 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2613 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2614 | // conversion) can have a different type from the current instruction's type, |
| 2615 | // so we manually indicate the type. |
| 2616 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2617 | Operand right_operand(0); |
| 2618 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2619 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2620 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2621 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2622 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2623 | right_operand = Operand(right_reg, |
| 2624 | helpers::ShiftFromOpKind(op_kind), |
| 2625 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | // Logical binary operations do not support extension operations in the |
| 2629 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2630 | // the extension as a separate instruction. |
| 2631 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2632 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2633 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2634 | kind != HInstruction::kNeg)); |
| 2635 | switch (kind) { |
| 2636 | case HInstruction::kAdd: |
| 2637 | __ Add(out, left, right_operand); |
| 2638 | break; |
| 2639 | case HInstruction::kAnd: |
| 2640 | __ And(out, left, right_operand); |
| 2641 | break; |
| 2642 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2643 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2644 | __ Neg(out, right_operand); |
| 2645 | break; |
| 2646 | case HInstruction::kOr: |
| 2647 | __ Orr(out, left, right_operand); |
| 2648 | break; |
| 2649 | case HInstruction::kSub: |
| 2650 | __ Sub(out, left, right_operand); |
| 2651 | break; |
| 2652 | case HInstruction::kXor: |
| 2653 | __ Eor(out, left, right_operand); |
| 2654 | break; |
| 2655 | default: |
| 2656 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2657 | UNREACHABLE(); |
| 2658 | } |
| 2659 | } |
| 2660 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2661 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2662 | LocationSummary* locations = |
| 2663 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2665 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2666 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2667 | } |
| 2668 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2669 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2670 | __ Add(OutputRegister(instruction), |
| 2671 | InputRegisterAt(instruction, 0), |
| 2672 | Operand(InputOperandAt(instruction, 1))); |
| 2673 | } |
| 2674 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2675 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2676 | LocationSummary* locations = |
| 2677 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2678 | |
| 2679 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2680 | |
| 2681 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2682 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2683 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2684 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2685 | // loop. |
| 2686 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2687 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2688 | : Location::RequiresRegister()); |
| 2689 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2691 | } |
| 2692 | |
| 2693 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2694 | HIntermediateAddressIndex* instruction) { |
| 2695 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2696 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2697 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2698 | |
| 2699 | if (shift == 0) { |
| 2700 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2701 | } else { |
| 2702 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2703 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2704 | } |
| 2705 | } |
| 2706 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2707 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2708 | LocationSummary* locations = |
| 2709 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2710 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2711 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2712 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2713 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2714 | // Don't allocate register for Mneg instruction. |
| 2715 | } else { |
| 2716 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2717 | Location::RequiresRegister()); |
| 2718 | } |
| 2719 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2720 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2721 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2722 | } |
| 2723 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2724 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2725 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2726 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2727 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2728 | |
| 2729 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2730 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2731 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2732 | if (instr->GetType() == Primitive::kPrimLong && |
| 2733 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2734 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2735 | vixl::aarch64::Instruction* prev = |
| 2736 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2737 | if (prev->IsLoadOrStore()) { |
| 2738 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2739 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2740 | __ nop(); |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2745 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2746 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2747 | } else { |
| 2748 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2749 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2750 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2751 | __ Mneg(res, mul_left, mul_right); |
| 2752 | } else { |
| 2753 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2754 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2755 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2756 | } |
| 2757 | } |
| 2758 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2759 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2760 | bool object_array_get_with_read_barrier = |
| 2761 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2762 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2763 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2764 | object_array_get_with_read_barrier ? |
| 2765 | LocationSummary::kCallOnSlowPath : |
| 2766 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2767 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2768 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2769 | // We need a temporary register for the read barrier marking slow |
| 2770 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2771 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2772 | !Runtime::Current()->UseJitCompilation() && |
| 2773 | instruction->GetIndex()->IsConstant()) { |
| 2774 | // Array loads with constant index are treated as field loads. |
| 2775 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2776 | // constant index loads we need a temporary only if the offset is too big. |
| 2777 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2778 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2779 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2780 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2781 | locations->AddTemp(FixedTempLocation()); |
| 2782 | } |
| 2783 | } else { |
| 2784 | locations->AddTemp(Location::RequiresRegister()); |
| 2785 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2786 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2787 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2788 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2789 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2790 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2791 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2792 | // The output overlaps in the case of an object array get with |
| 2793 | // read barriers enabled: we do not want the move to overwrite the |
| 2794 | // array's location, as we need it to emit the read barrier. |
| 2795 | locations->SetOut( |
| 2796 | Location::RequiresRegister(), |
| 2797 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2798 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2802 | Primitive::Type type = instruction->GetType(); |
| 2803 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2804 | LocationSummary* locations = instruction->GetLocations(); |
| 2805 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2806 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2807 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2808 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2809 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2810 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2811 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2812 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2813 | // The read barrier instrumentation of object ArrayGet instructions |
| 2814 | // does not support the HIntermediateAddress instruction. |
| 2815 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2816 | instruction->GetArray()->IsIntermediateAddress() && |
| 2817 | kEmitCompilerReadBarrier)); |
| 2818 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2819 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2820 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2821 | // Note that a potential implicit null check is handled in the |
| 2822 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2823 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2824 | if (index.IsConstant()) { |
| 2825 | // Array load with a constant index can be treated as a field load. |
| 2826 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2827 | Location maybe_temp = |
| 2828 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2829 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2830 | out, |
| 2831 | obj.W(), |
| 2832 | offset, |
| 2833 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2834 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2835 | /* use_load_acquire */ false); |
| 2836 | } else { |
| 2837 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2838 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2839 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2840 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2841 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2842 | // General case. |
| 2843 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2844 | Register length; |
| 2845 | if (maybe_compressed_char_at) { |
| 2846 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2847 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2848 | { |
| 2849 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2850 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2851 | |
| 2852 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2853 | DCHECK_LT(count_offset, offset); |
| 2854 | int64_t adjusted_offset = |
| 2855 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2856 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2857 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2858 | } else { |
| 2859 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2860 | } |
| 2861 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2862 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2863 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2864 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2865 | if (maybe_compressed_char_at) { |
| 2866 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2867 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2868 | "Expecting 0=compressed, 1=uncompressed"); |
| 2869 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2870 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2871 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2872 | __ B(&done); |
| 2873 | __ Bind(&uncompressed_load); |
| 2874 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2875 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2876 | __ Bind(&done); |
| 2877 | } else { |
| 2878 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2879 | source = HeapOperand(obj, offset); |
| 2880 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2881 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2882 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2883 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2884 | // We do not need to compute the intermediate address from the array: the |
| 2885 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2886 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2887 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2888 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2889 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2890 | } |
| 2891 | temp = obj; |
| 2892 | } else { |
| 2893 | __ Add(temp, obj, offset); |
| 2894 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2895 | if (maybe_compressed_char_at) { |
| 2896 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2897 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2898 | "Expecting 0=compressed, 1=uncompressed"); |
| 2899 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2900 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2901 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2902 | __ B(&done); |
| 2903 | __ Bind(&uncompressed_load); |
| 2904 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2905 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2906 | __ Bind(&done); |
| 2907 | } else { |
| 2908 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2909 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2910 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2911 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2912 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2913 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2914 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2915 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2916 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2917 | |
| 2918 | if (type == Primitive::kPrimNot) { |
| 2919 | static_assert( |
| 2920 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2921 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2922 | Location obj_loc = locations->InAt(0); |
| 2923 | if (index.IsConstant()) { |
| 2924 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2925 | } else { |
| 2926 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2927 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2928 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2929 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2932 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2933 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2934 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2935 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2939 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2940 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2941 | { |
| 2942 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2943 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2944 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2945 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2946 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2947 | // Mask out compression flag from String's array length. |
| 2948 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2949 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2950 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2951 | } |
| 2952 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2953 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2954 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2955 | |
| 2956 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2957 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2958 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2959 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2960 | LocationSummary::kCallOnSlowPath : |
| 2961 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2962 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2963 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2964 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2965 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2966 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2967 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2968 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2969 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2974 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2975 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2976 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2977 | bool needs_write_barrier = |
| 2978 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2979 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2980 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2981 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2982 | CPURegister source = value; |
| 2983 | Location index = locations->InAt(1); |
| 2984 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2985 | MemOperand destination = HeapOperand(array); |
| 2986 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2987 | |
| 2988 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2989 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2990 | if (index.IsConstant()) { |
| 2991 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2992 | destination = HeapOperand(array, offset); |
| 2993 | } else { |
| 2994 | UseScratchRegisterScope temps(masm); |
| 2995 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2996 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2997 | // We do not need to compute the intermediate address from the array: the |
| 2998 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2999 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3000 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3001 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3002 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 3003 | } |
| 3004 | temp = array; |
| 3005 | } else { |
| 3006 | __ Add(temp, array, offset); |
| 3007 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3008 | destination = HeapOperand(temp, |
| 3009 | XRegisterFrom(index), |
| 3010 | LSL, |
| 3011 | Primitive::ComponentSizeShift(value_type)); |
| 3012 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3013 | { |
| 3014 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3015 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3016 | codegen_->Store(value_type, value, destination); |
| 3017 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3018 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3019 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3020 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3021 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3022 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3023 | { |
| 3024 | // We use a block to end the scratch scope before the write barrier, thus |
| 3025 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3026 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3027 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3028 | if (index.IsConstant()) { |
| 3029 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3030 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3031 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3032 | destination = HeapOperand(temp, |
| 3033 | XRegisterFrom(index), |
| 3034 | LSL, |
| 3035 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3038 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3039 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3040 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3041 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3042 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3043 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 3044 | codegen_->AddSlowPath(slow_path); |
| 3045 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3046 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3047 | __ Cbnz(Register(value), &non_zero); |
| 3048 | if (!index.IsConstant()) { |
| 3049 | __ Add(temp, array, offset); |
| 3050 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3051 | { |
| 3052 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3053 | // emitted. |
| 3054 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3055 | __ Str(wzr, destination); |
| 3056 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3057 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3058 | __ B(&done); |
| 3059 | __ Bind(&non_zero); |
| 3060 | } |
| 3061 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3062 | // Note that when Baker read barriers are enabled, the type |
| 3063 | // checks are performed without read barriers. This is fine, |
| 3064 | // even in the case where a class object is in the from-space |
| 3065 | // after the flip, as a comparison involving such a type would |
| 3066 | // not produce a false positive; it may of course produce a |
| 3067 | // false negative, in which case we would take the ArraySet |
| 3068 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3069 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3070 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3071 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3072 | { |
| 3073 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3074 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3075 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3077 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3078 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3079 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3080 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3081 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3082 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3083 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3084 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3085 | // nor `temp2`, as we are comparing two poisoned references. |
| 3086 | __ Cmp(temp, temp2); |
| 3087 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3088 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3089 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3090 | vixl::aarch64::Label do_put; |
| 3091 | __ B(eq, &do_put); |
| 3092 | // If heap poisoning is enabled, the `temp` reference has |
| 3093 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3094 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3095 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3096 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3097 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3098 | // If heap poisoning is enabled, no need to unpoison |
| 3099 | // `temp`, as we are comparing against null below. |
| 3100 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3101 | __ Bind(&do_put); |
| 3102 | } else { |
| 3103 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3108 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3109 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3110 | __ Mov(temp2, value.W()); |
| 3111 | GetAssembler()->PoisonHeapReference(temp2); |
| 3112 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | if (!index.IsConstant()) { |
| 3116 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3117 | } else { |
| 3118 | // We no longer need the `temp` here so release it as the store below may |
| 3119 | // need a scratch register (if the constant index makes the offset too large) |
| 3120 | // and the poisoned `source` could be using the other scratch register. |
| 3121 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3122 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3123 | { |
| 3124 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3125 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3126 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3127 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3128 | if (!may_need_runtime_call_for_type_check) { |
| 3129 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3130 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3131 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3132 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3133 | |
| 3134 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3135 | |
| 3136 | if (done.IsLinked()) { |
| 3137 | __ Bind(&done); |
| 3138 | } |
| 3139 | |
| 3140 | if (slow_path != nullptr) { |
| 3141 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3142 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3143 | } |
| 3144 | } |
| 3145 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3146 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3147 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3148 | InvokeRuntimeCallingConvention calling_convention; |
| 3149 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3150 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3151 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3152 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3153 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3157 | BoundsCheckSlowPathARM64* slow_path = |
| 3158 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3159 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3160 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3161 | __ B(slow_path->GetEntryLabel(), hs); |
| 3162 | } |
| 3163 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3164 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3165 | LocationSummary* locations = |
| 3166 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3167 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3168 | if (check->HasUses()) { |
| 3169 | locations->SetOut(Location::SameAsFirstInput()); |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3174 | // We assume the class is not null. |
| 3175 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3176 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3177 | codegen_->AddSlowPath(slow_path); |
| 3178 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3179 | } |
| 3180 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3181 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3182 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3183 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3184 | } |
| 3185 | |
| 3186 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3187 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3188 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3189 | if (rhs_loc.IsConstant()) { |
| 3190 | // 0.0 is the only immediate that can be encoded directly in |
| 3191 | // an FCMP instruction. |
| 3192 | // |
| 3193 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3194 | // specify that in a floating-point comparison, positive zero |
| 3195 | // and negative zero are considered equal, so we can use the |
| 3196 | // literal 0.0 for both cases here. |
| 3197 | // |
| 3198 | // Note however that some methods (Float.equal, Float.compare, |
| 3199 | // Float.compareTo, Double.equal, Double.compare, |
| 3200 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3201 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3202 | // -0.0. So if we ever translate calls to these methods into a |
| 3203 | // HCompare instruction, we must handle the -0.0 case with |
| 3204 | // care here. |
| 3205 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3206 | __ Fcmp(lhs_reg, 0.0); |
| 3207 | } else { |
| 3208 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3209 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3212 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3213 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3214 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3215 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3216 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3217 | case Primitive::kPrimBoolean: |
| 3218 | case Primitive::kPrimByte: |
| 3219 | case Primitive::kPrimShort: |
| 3220 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3221 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3222 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3223 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3224 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3225 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3226 | break; |
| 3227 | } |
| 3228 | case Primitive::kPrimFloat: |
| 3229 | case Primitive::kPrimDouble: { |
| 3230 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3231 | locations->SetInAt(1, |
| 3232 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3233 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3234 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3235 | locations->SetOut(Location::RequiresRegister()); |
| 3236 | break; |
| 3237 | } |
| 3238 | default: |
| 3239 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3244 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3245 | |
| 3246 | // 0 if: left == right |
| 3247 | // 1 if: left > right |
| 3248 | // -1 if: left < right |
| 3249 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3250 | case Primitive::kPrimBoolean: |
| 3251 | case Primitive::kPrimByte: |
| 3252 | case Primitive::kPrimShort: |
| 3253 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3254 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3255 | case Primitive::kPrimLong: { |
| 3256 | Register result = OutputRegister(compare); |
| 3257 | Register left = InputRegisterAt(compare, 0); |
| 3258 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3259 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3260 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3261 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3262 | break; |
| 3263 | } |
| 3264 | case Primitive::kPrimFloat: |
| 3265 | case Primitive::kPrimDouble: { |
| 3266 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3267 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3268 | __ Cset(result, ne); |
| 3269 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3270 | break; |
| 3271 | } |
| 3272 | default: |
| 3273 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3274 | } |
| 3275 | } |
| 3276 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3277 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3278 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3279 | |
| 3280 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3281 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3282 | locations->SetInAt(1, |
| 3283 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3284 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3285 | : Location::RequiresFpuRegister()); |
| 3286 | } else { |
| 3287 | // Integer cases. |
| 3288 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3289 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3290 | } |
| 3291 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3292 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3293 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3294 | } |
| 3295 | } |
| 3296 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3297 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3298 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3299 | return; |
| 3300 | } |
| 3301 | |
| 3302 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3303 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3304 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3305 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3306 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3307 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3308 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3309 | } else { |
| 3310 | // Integer cases. |
| 3311 | Register lhs = InputRegisterAt(instruction, 0); |
| 3312 | Operand rhs = InputOperandAt(instruction, 1); |
| 3313 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3314 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3315 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3319 | M(Equal) \ |
| 3320 | M(NotEqual) \ |
| 3321 | M(LessThan) \ |
| 3322 | M(LessThanOrEqual) \ |
| 3323 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3324 | M(GreaterThanOrEqual) \ |
| 3325 | M(Below) \ |
| 3326 | M(BelowOrEqual) \ |
| 3327 | M(Above) \ |
| 3328 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3329 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3330 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3331 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3332 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3333 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3334 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3335 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3336 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3337 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3338 | |
| 3339 | LocationSummary* locations = instruction->GetLocations(); |
| 3340 | Location second = locations->InAt(1); |
| 3341 | DCHECK(second.IsConstant()); |
| 3342 | |
| 3343 | Register out = OutputRegister(instruction); |
| 3344 | Register dividend = InputRegisterAt(instruction, 0); |
| 3345 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3346 | DCHECK(imm == 1 || imm == -1); |
| 3347 | |
| 3348 | if (instruction->IsRem()) { |
| 3349 | __ Mov(out, 0); |
| 3350 | } else { |
| 3351 | if (imm == 1) { |
| 3352 | __ Mov(out, dividend); |
| 3353 | } else { |
| 3354 | __ Neg(out, dividend); |
| 3355 | } |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3360 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3361 | |
| 3362 | LocationSummary* locations = instruction->GetLocations(); |
| 3363 | Location second = locations->InAt(1); |
| 3364 | DCHECK(second.IsConstant()); |
| 3365 | |
| 3366 | Register out = OutputRegister(instruction); |
| 3367 | Register dividend = InputRegisterAt(instruction, 0); |
| 3368 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3369 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3370 | int ctz_imm = CTZ(abs_imm); |
| 3371 | |
| 3372 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3373 | Register temp = temps.AcquireSameSizeAs(out); |
| 3374 | |
| 3375 | if (instruction->IsDiv()) { |
| 3376 | __ Add(temp, dividend, abs_imm - 1); |
| 3377 | __ Cmp(dividend, 0); |
| 3378 | __ Csel(out, temp, dividend, lt); |
| 3379 | if (imm > 0) { |
| 3380 | __ Asr(out, out, ctz_imm); |
| 3381 | } else { |
| 3382 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3383 | } |
| 3384 | } else { |
| 3385 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3386 | __ Asr(temp, dividend, bits - 1); |
| 3387 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3388 | __ Add(out, dividend, temp); |
| 3389 | __ And(out, out, abs_imm - 1); |
| 3390 | __ Sub(out, out, temp); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3395 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3396 | |
| 3397 | LocationSummary* locations = instruction->GetLocations(); |
| 3398 | Location second = locations->InAt(1); |
| 3399 | DCHECK(second.IsConstant()); |
| 3400 | |
| 3401 | Register out = OutputRegister(instruction); |
| 3402 | Register dividend = InputRegisterAt(instruction, 0); |
| 3403 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3404 | |
| 3405 | Primitive::Type type = instruction->GetResultType(); |
| 3406 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3407 | |
| 3408 | int64_t magic; |
| 3409 | int shift; |
| 3410 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3411 | |
| 3412 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3413 | Register temp = temps.AcquireSameSizeAs(out); |
| 3414 | |
| 3415 | // temp = get_high(dividend * magic) |
| 3416 | __ Mov(temp, magic); |
| 3417 | if (type == Primitive::kPrimLong) { |
| 3418 | __ Smulh(temp, dividend, temp); |
| 3419 | } else { |
| 3420 | __ Smull(temp.X(), dividend, temp); |
| 3421 | __ Lsr(temp.X(), temp.X(), 32); |
| 3422 | } |
| 3423 | |
| 3424 | if (imm > 0 && magic < 0) { |
| 3425 | __ Add(temp, temp, dividend); |
| 3426 | } else if (imm < 0 && magic > 0) { |
| 3427 | __ Sub(temp, temp, dividend); |
| 3428 | } |
| 3429 | |
| 3430 | if (shift != 0) { |
| 3431 | __ Asr(temp, temp, shift); |
| 3432 | } |
| 3433 | |
| 3434 | if (instruction->IsDiv()) { |
| 3435 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3436 | } else { |
| 3437 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3438 | // TODO: Strength reduction for msub. |
| 3439 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3440 | __ Mov(temp_imm, imm); |
| 3441 | __ Msub(out, temp, temp_imm, dividend); |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3446 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3447 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3448 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3449 | |
| 3450 | LocationSummary* locations = instruction->GetLocations(); |
| 3451 | Register out = OutputRegister(instruction); |
| 3452 | Location second = locations->InAt(1); |
| 3453 | |
| 3454 | if (second.IsConstant()) { |
| 3455 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3456 | |
| 3457 | if (imm == 0) { |
| 3458 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3459 | } else if (imm == 1 || imm == -1) { |
| 3460 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3461 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3462 | DivRemByPowerOfTwo(instruction); |
| 3463 | } else { |
| 3464 | DCHECK(imm <= -2 || imm >= 2); |
| 3465 | GenerateDivRemWithAnyConstant(instruction); |
| 3466 | } |
| 3467 | } else { |
| 3468 | Register dividend = InputRegisterAt(instruction, 0); |
| 3469 | Register divisor = InputRegisterAt(instruction, 1); |
| 3470 | if (instruction->IsDiv()) { |
| 3471 | __ Sdiv(out, dividend, divisor); |
| 3472 | } else { |
| 3473 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3474 | Register temp = temps.AcquireSameSizeAs(out); |
| 3475 | __ Sdiv(temp, dividend, divisor); |
| 3476 | __ Msub(out, temp, divisor, dividend); |
| 3477 | } |
| 3478 | } |
| 3479 | } |
| 3480 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3481 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3482 | LocationSummary* locations = |
| 3483 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3484 | switch (div->GetResultType()) { |
| 3485 | case Primitive::kPrimInt: |
| 3486 | case Primitive::kPrimLong: |
| 3487 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3488 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3489 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3490 | break; |
| 3491 | |
| 3492 | case Primitive::kPrimFloat: |
| 3493 | case Primitive::kPrimDouble: |
| 3494 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3495 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3496 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3497 | break; |
| 3498 | |
| 3499 | default: |
| 3500 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3505 | Primitive::Type type = div->GetResultType(); |
| 3506 | switch (type) { |
| 3507 | case Primitive::kPrimInt: |
| 3508 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3509 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3510 | break; |
| 3511 | |
| 3512 | case Primitive::kPrimFloat: |
| 3513 | case Primitive::kPrimDouble: |
| 3514 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3515 | break; |
| 3516 | |
| 3517 | default: |
| 3518 | LOG(FATAL) << "Unexpected div type " << type; |
| 3519 | } |
| 3520 | } |
| 3521 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3522 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3523 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3524 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3528 | SlowPathCodeARM64* slow_path = |
| 3529 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3530 | codegen_->AddSlowPath(slow_path); |
| 3531 | Location value = instruction->GetLocations()->InAt(0); |
| 3532 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3533 | Primitive::Type type = instruction->GetType(); |
| 3534 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3535 | if (!Primitive::IsIntegralType(type)) { |
| 3536 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3537 | return; |
| 3538 | } |
| 3539 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3540 | if (value.IsConstant()) { |
| 3541 | int64_t divisor = Int64ConstantFrom(value); |
| 3542 | if (divisor == 0) { |
| 3543 | __ B(slow_path->GetEntryLabel()); |
| 3544 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3545 | // A division by a non-null constant is valid. We don't need to perform |
| 3546 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3547 | } |
| 3548 | } else { |
| 3549 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3550 | } |
| 3551 | } |
| 3552 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3553 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3554 | LocationSummary* locations = |
| 3555 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3556 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3557 | } |
| 3558 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3559 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3560 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3561 | // Will be generated at use site. |
| 3562 | } |
| 3563 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3564 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3565 | exit->SetLocations(nullptr); |
| 3566 | } |
| 3567 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3568 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3569 | } |
| 3570 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3571 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3572 | LocationSummary* locations = |
| 3573 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3574 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3575 | } |
| 3576 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3577 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3578 | // Will be generated at use site. |
| 3579 | } |
| 3580 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3581 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3582 | DCHECK(!successor->IsExitBlock()); |
| 3583 | HBasicBlock* block = got->GetBlock(); |
| 3584 | HInstruction* previous = got->GetPrevious(); |
| 3585 | HLoopInformation* info = block->GetLoopInformation(); |
| 3586 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3587 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3588 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3589 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3590 | return; |
| 3591 | } |
| 3592 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3593 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3594 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3595 | } |
| 3596 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3597 | __ B(codegen_->GetLabelOf(successor)); |
| 3598 | } |
| 3599 | } |
| 3600 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3601 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3602 | got->SetLocations(nullptr); |
| 3603 | } |
| 3604 | |
| 3605 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3606 | HandleGoto(got, got->GetSuccessor()); |
| 3607 | } |
| 3608 | |
| 3609 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3610 | try_boundary->SetLocations(nullptr); |
| 3611 | } |
| 3612 | |
| 3613 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3614 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3615 | if (!successor->IsExitBlock()) { |
| 3616 | HandleGoto(try_boundary, successor); |
| 3617 | } |
| 3618 | } |
| 3619 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3620 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3621 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3622 | vixl::aarch64::Label* true_target, |
| 3623 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3624 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3625 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3626 | if (true_target == nullptr && false_target == nullptr) { |
| 3627 | // Nothing to do. The code always falls through. |
| 3628 | return; |
| 3629 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3630 | // Constant condition, statically compared against "true" (integer value 1). |
| 3631 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3632 | if (true_target != nullptr) { |
| 3633 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3634 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3635 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3636 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3637 | if (false_target != nullptr) { |
| 3638 | __ B(false_target); |
| 3639 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3640 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3641 | return; |
| 3642 | } |
| 3643 | |
| 3644 | // The following code generates these patterns: |
| 3645 | // (1) true_target == nullptr && false_target != nullptr |
| 3646 | // - opposite condition true => branch to false_target |
| 3647 | // (2) true_target != nullptr && false_target == nullptr |
| 3648 | // - condition true => branch to true_target |
| 3649 | // (3) true_target != nullptr && false_target != nullptr |
| 3650 | // - condition true => branch to true_target |
| 3651 | // - branch to false_target |
| 3652 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3653 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3654 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3655 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3656 | if (true_target == nullptr) { |
| 3657 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3658 | } else { |
| 3659 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3660 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3661 | } else { |
| 3662 | // The condition instruction has not been materialized, use its inputs as |
| 3663 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3664 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3665 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3666 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3667 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3668 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3670 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3671 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3672 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3673 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3674 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3675 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3676 | // Integer cases. |
| 3677 | Register lhs = InputRegisterAt(condition, 0); |
| 3678 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3679 | |
| 3680 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3681 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3682 | if (true_target == nullptr) { |
| 3683 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3684 | non_fallthrough_target = false_target; |
| 3685 | } else { |
| 3686 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3687 | non_fallthrough_target = true_target; |
| 3688 | } |
| 3689 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3690 | 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] | 3691 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3692 | switch (arm64_cond) { |
| 3693 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3694 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3695 | break; |
| 3696 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3697 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3698 | break; |
| 3699 | case lt: |
| 3700 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3701 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3702 | break; |
| 3703 | case ge: |
| 3704 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3705 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3706 | break; |
| 3707 | default: |
| 3708 | // Without the `static_cast` the compiler throws an error for |
| 3709 | // `-Werror=sign-promo`. |
| 3710 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3711 | } |
| 3712 | } else { |
| 3713 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3714 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3715 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3716 | } |
| 3717 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3718 | |
| 3719 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3720 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3721 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3722 | __ B(false_target); |
| 3723 | } |
| 3724 | } |
| 3725 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3726 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3727 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3728 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3729 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3730 | } |
| 3731 | } |
| 3732 | |
| 3733 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3734 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3735 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3736 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3737 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3738 | true_target = nullptr; |
| 3739 | } |
| 3740 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3741 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3742 | false_target = nullptr; |
| 3743 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3744 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3748 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3749 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3750 | InvokeRuntimeCallingConvention calling_convention; |
| 3751 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3752 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3753 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3754 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3760 | SlowPathCodeARM64* slow_path = |
| 3761 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3762 | GenerateTestAndBranch(deoptimize, |
| 3763 | /* condition_input_index */ 0, |
| 3764 | slow_path->GetEntryLabel(), |
| 3765 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3768 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3769 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3770 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3771 | locations->SetOut(Location::RequiresRegister()); |
| 3772 | } |
| 3773 | |
| 3774 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3775 | __ Ldr(OutputRegister(flag), |
| 3776 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3777 | } |
| 3778 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3779 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3780 | return condition->IsCondition() && |
| 3781 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3782 | } |
| 3783 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3784 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3785 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3786 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3787 | : ARM64Condition(cond); |
| 3788 | } |
| 3789 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3790 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3791 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3792 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3793 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3794 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3795 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3796 | } else { |
| 3797 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3798 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3799 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3800 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3801 | // Ask VIXL whether we should synthesize constants in registers. |
| 3802 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3803 | Operand true_op = is_true_value_constant ? |
| 3804 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3805 | Operand false_op = is_false_value_constant ? |
| 3806 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3807 | bool true_value_in_register = false; |
| 3808 | bool false_value_in_register = false; |
| 3809 | MacroAssembler::GetCselSynthesisInformation( |
| 3810 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3811 | true_value_in_register |= !is_true_value_constant; |
| 3812 | false_value_in_register |= !is_false_value_constant; |
| 3813 | |
| 3814 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3815 | : Location::ConstantLocation(cst_true_value)); |
| 3816 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3817 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3818 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3819 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3820 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3821 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3822 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3823 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3827 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3828 | Condition csel_cond; |
| 3829 | |
| 3830 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3831 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3832 | // Use the condition flags set by the previous instruction. |
| 3833 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3834 | } else { |
| 3835 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3836 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3839 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3840 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3841 | } else { |
| 3842 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3843 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3846 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3847 | __ Fcsel(OutputFPRegister(select), |
| 3848 | InputFPRegisterAt(select, 1), |
| 3849 | InputFPRegisterAt(select, 0), |
| 3850 | csel_cond); |
| 3851 | } else { |
| 3852 | __ Csel(OutputRegister(select), |
| 3853 | InputOperandAt(select, 1), |
| 3854 | InputOperandAt(select, 0), |
| 3855 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3856 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3859 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3860 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3861 | } |
| 3862 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3863 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3864 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | void CodeGeneratorARM64::GenerateNop() { |
| 3868 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3871 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3872 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3876 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3880 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3884 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3885 | } |
| 3886 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3887 | // Temp is used for read barrier. |
| 3888 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3889 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3890 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3891 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3892 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3893 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3894 | return 1; |
| 3895 | } |
| 3896 | return 0; |
| 3897 | } |
| 3898 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3899 | // 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] | 3900 | // interface pointer, one for loading the current interface. |
| 3901 | // The other checks have one temp for loading the object's class. |
| 3902 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3903 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3904 | return 3; |
| 3905 | } |
| 3906 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3909 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3910 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3911 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3912 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3913 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3914 | case TypeCheckKind::kExactCheck: |
| 3915 | case TypeCheckKind::kAbstractClassCheck: |
| 3916 | case TypeCheckKind::kClassHierarchyCheck: |
| 3917 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3918 | call_kind = |
| 3919 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3920 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3921 | break; |
| 3922 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3923 | case TypeCheckKind::kUnresolvedCheck: |
| 3924 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3925 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3926 | break; |
| 3927 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3928 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3929 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3930 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3931 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3932 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3934 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3935 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3936 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3937 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3938 | // Add temps if necessary for read barriers. |
| 3939 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3943 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3944 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3945 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | Register obj = InputRegisterAt(instruction, 0); |
| 3947 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3948 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3949 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3950 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3951 | DCHECK_LE(num_temps, 1u); |
| 3952 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3953 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3954 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3955 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3956 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3957 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3958 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3959 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3960 | |
| 3961 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3962 | // Avoid null check if we know `obj` is not null. |
| 3963 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3964 | __ Cbz(obj, &zero); |
| 3965 | } |
| 3966 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3967 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3968 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3969 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3970 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3971 | out_loc, |
| 3972 | obj_loc, |
| 3973 | class_offset, |
| 3974 | maybe_temp_loc, |
| 3975 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3976 | __ Cmp(out, cls); |
| 3977 | __ Cset(out, eq); |
| 3978 | if (zero.IsLinked()) { |
| 3979 | __ B(&done); |
| 3980 | } |
| 3981 | break; |
| 3982 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3983 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3984 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3985 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3986 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3987 | out_loc, |
| 3988 | obj_loc, |
| 3989 | class_offset, |
| 3990 | maybe_temp_loc, |
| 3991 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3992 | // If the class is abstract, we eagerly fetch the super class of the |
| 3993 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3994 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3995 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3996 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3997 | GenerateReferenceLoadOneRegister(instruction, |
| 3998 | out_loc, |
| 3999 | super_offset, |
| 4000 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4001 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4002 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4003 | __ Cbz(out, &done); |
| 4004 | __ Cmp(out, cls); |
| 4005 | __ B(ne, &loop); |
| 4006 | __ Mov(out, 1); |
| 4007 | if (zero.IsLinked()) { |
| 4008 | __ B(&done); |
| 4009 | } |
| 4010 | break; |
| 4011 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4012 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4013 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4014 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4015 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4016 | out_loc, |
| 4017 | obj_loc, |
| 4018 | class_offset, |
| 4019 | maybe_temp_loc, |
| 4020 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4021 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4022 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4023 | __ Bind(&loop); |
| 4024 | __ Cmp(out, cls); |
| 4025 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4026 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4027 | GenerateReferenceLoadOneRegister(instruction, |
| 4028 | out_loc, |
| 4029 | super_offset, |
| 4030 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4031 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4032 | __ Cbnz(out, &loop); |
| 4033 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4034 | __ B(&done); |
| 4035 | __ Bind(&success); |
| 4036 | __ Mov(out, 1); |
| 4037 | if (zero.IsLinked()) { |
| 4038 | __ B(&done); |
| 4039 | } |
| 4040 | break; |
| 4041 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4042 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4043 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4044 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4045 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4046 | out_loc, |
| 4047 | obj_loc, |
| 4048 | class_offset, |
| 4049 | maybe_temp_loc, |
| 4050 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4051 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4052 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4053 | __ Cmp(out, cls); |
| 4054 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4055 | // 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] | 4056 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4057 | GenerateReferenceLoadOneRegister(instruction, |
| 4058 | out_loc, |
| 4059 | component_offset, |
| 4060 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4061 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4062 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4063 | __ Cbz(out, &done); |
| 4064 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4065 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4066 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4067 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4068 | __ Mov(out, 1); |
| 4069 | __ B(&done); |
| 4070 | break; |
| 4071 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4072 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4073 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4074 | // No read barrier since the slow path will retry upon failure. |
| 4075 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4076 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4077 | out_loc, |
| 4078 | obj_loc, |
| 4079 | class_offset, |
| 4080 | maybe_temp_loc, |
| 4081 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4082 | __ Cmp(out, cls); |
| 4083 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4084 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4085 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4086 | codegen_->AddSlowPath(slow_path); |
| 4087 | __ B(ne, slow_path->GetEntryLabel()); |
| 4088 | __ Mov(out, 1); |
| 4089 | if (zero.IsLinked()) { |
| 4090 | __ B(&done); |
| 4091 | } |
| 4092 | break; |
| 4093 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4094 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4095 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4096 | case TypeCheckKind::kInterfaceCheck: { |
| 4097 | // Note that we indeed only call on slow path, but we always go |
| 4098 | // into the slow path for the unresolved and interface check |
| 4099 | // cases. |
| 4100 | // |
| 4101 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4102 | // entry point without resorting to a type checking slow path |
| 4103 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4104 | // require to assign fixed registers for the inputs of this |
| 4105 | // HInstanceOf instruction (following the runtime calling |
| 4106 | // convention), which might be cluttered by the potential first |
| 4107 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4108 | // |
| 4109 | // TODO: Introduce a new runtime entry point taking the object |
| 4110 | // to test (instead of its class) as argument, and let it deal |
| 4111 | // with the read barrier issues. This will let us refactor this |
| 4112 | // case of the `switch` code as it was previously (with a direct |
| 4113 | // call to the runtime not using a type checking slow path). |
| 4114 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4115 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4116 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4117 | /* is_fatal */ false); |
| 4118 | codegen_->AddSlowPath(slow_path); |
| 4119 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4120 | if (zero.IsLinked()) { |
| 4121 | __ B(&done); |
| 4122 | } |
| 4123 | break; |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | if (zero.IsLinked()) { |
| 4128 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4129 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | if (done.IsLinked()) { |
| 4133 | __ Bind(&done); |
| 4134 | } |
| 4135 | |
| 4136 | if (slow_path != nullptr) { |
| 4137 | __ Bind(slow_path->GetExitLabel()); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4142 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4143 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4144 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4145 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4146 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4147 | case TypeCheckKind::kExactCheck: |
| 4148 | case TypeCheckKind::kAbstractClassCheck: |
| 4149 | case TypeCheckKind::kClassHierarchyCheck: |
| 4150 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4151 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4152 | LocationSummary::kCallOnSlowPath : |
| 4153 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4154 | break; |
| 4155 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4156 | case TypeCheckKind::kUnresolvedCheck: |
| 4157 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4158 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4159 | break; |
| 4160 | } |
| 4161 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4162 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4164 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4165 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4166 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4170 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4171 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4172 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4173 | Register obj = InputRegisterAt(instruction, 0); |
| 4174 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4175 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4176 | DCHECK_GE(num_temps, 1u); |
| 4177 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4178 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4179 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4180 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4181 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4182 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4183 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4184 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4185 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4186 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4187 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4188 | const uint32_t object_array_data_offset = |
| 4189 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4190 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4191 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4192 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4193 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4194 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4195 | if (!kEmitCompilerReadBarrier) { |
| 4196 | is_type_check_slow_path_fatal = |
| 4197 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4198 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4199 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4200 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4201 | !instruction->CanThrowIntoCatchBlock(); |
| 4202 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4203 | SlowPathCodeARM64* type_check_slow_path = |
| 4204 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4205 | is_type_check_slow_path_fatal); |
| 4206 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4207 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4208 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4209 | // Avoid null check if we know obj is not null. |
| 4210 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4211 | __ Cbz(obj, &done); |
| 4212 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4213 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4214 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4215 | case TypeCheckKind::kExactCheck: |
| 4216 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4217 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4218 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4219 | temp_loc, |
| 4220 | obj_loc, |
| 4221 | class_offset, |
| 4222 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4223 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4224 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4225 | __ Cmp(temp, cls); |
| 4226 | // Jump to slow path for throwing the exception or doing a |
| 4227 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4228 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4229 | break; |
| 4230 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4231 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4232 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4233 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4234 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4235 | temp_loc, |
| 4236 | obj_loc, |
| 4237 | class_offset, |
| 4238 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4239 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4240 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4241 | // If the class is abstract, we eagerly fetch the super class of the |
| 4242 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4243 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4244 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4245 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4246 | GenerateReferenceLoadOneRegister(instruction, |
| 4247 | temp_loc, |
| 4248 | super_offset, |
| 4249 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4250 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4251 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4252 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4253 | // exception. |
| 4254 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4255 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4256 | __ Cmp(temp, cls); |
| 4257 | __ B(ne, &loop); |
| 4258 | break; |
| 4259 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4260 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4261 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4262 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4263 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4264 | temp_loc, |
| 4265 | obj_loc, |
| 4266 | class_offset, |
| 4267 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4268 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4269 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4270 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4271 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4272 | __ Bind(&loop); |
| 4273 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4274 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4275 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4276 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4277 | GenerateReferenceLoadOneRegister(instruction, |
| 4278 | temp_loc, |
| 4279 | super_offset, |
| 4280 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4281 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4282 | |
| 4283 | // If the class reference currently in `temp` is not null, jump |
| 4284 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4285 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4286 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4287 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4288 | break; |
| 4289 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4290 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4291 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4292 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4293 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4294 | temp_loc, |
| 4295 | obj_loc, |
| 4296 | class_offset, |
| 4297 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4298 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4299 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4300 | // Do an exact check. |
| 4301 | __ Cmp(temp, cls); |
| 4302 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4303 | |
| 4304 | // 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] | 4305 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4306 | GenerateReferenceLoadOneRegister(instruction, |
| 4307 | temp_loc, |
| 4308 | component_offset, |
| 4309 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4310 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4311 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4312 | // If the component type is null, jump to the slow path to throw the exception. |
| 4313 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4314 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4315 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4316 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4317 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4318 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4319 | break; |
| 4320 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4321 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4322 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4323 | // 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] | 4324 | // |
| 4325 | // We cannot directly call the CheckCast runtime entry point |
| 4326 | // without resorting to a type checking slow path here (i.e. by |
| 4327 | // calling InvokeRuntime directly), as it would require to |
| 4328 | // assign fixed registers for the inputs of this HInstanceOf |
| 4329 | // instruction (following the runtime calling convention), which |
| 4330 | // might be cluttered by the potential first read barrier |
| 4331 | // emission at the beginning of this method. |
| 4332 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4333 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4334 | case TypeCheckKind::kInterfaceCheck: { |
| 4335 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4336 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4337 | temp_loc, |
| 4338 | obj_loc, |
| 4339 | class_offset, |
| 4340 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4341 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4342 | |
| 4343 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4344 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4345 | temp_loc, |
| 4346 | temp_loc, |
| 4347 | iftable_offset, |
| 4348 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4349 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4350 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4351 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4352 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4353 | vixl::aarch64::Label start_loop; |
| 4354 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4355 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4356 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4357 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4358 | // Go to next interface. |
| 4359 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4360 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4361 | // Compare the classes and continue the loop if they do not match. |
| 4362 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4363 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4364 | break; |
| 4365 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4366 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4367 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4368 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4369 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4372 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4373 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4374 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4375 | } |
| 4376 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4377 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4378 | // Will be generated at use site. |
| 4379 | } |
| 4380 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4381 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4382 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4383 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4384 | } |
| 4385 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4386 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4387 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4390 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4391 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4392 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4393 | // the method_idx. |
| 4394 | HandleInvoke(invoke); |
| 4395 | } |
| 4396 | |
| 4397 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4398 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4399 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4400 | } |
| 4401 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4402 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4403 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4404 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4405 | } |
| 4406 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4407 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4408 | HandleInvoke(invoke); |
| 4409 | } |
| 4410 | |
| 4411 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4412 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4413 | LocationSummary* locations = invoke->GetLocations(); |
| 4414 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4415 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4416 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4417 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4418 | |
| 4419 | // The register ip1 is required to be used for the hidden argument in |
| 4420 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4421 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4422 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4423 | scratch_scope.Exclude(ip1); |
| 4424 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4425 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4426 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4427 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4428 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4429 | { |
| 4430 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4431 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4432 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4433 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4434 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4435 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4436 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4437 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4438 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4439 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4440 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4441 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4442 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4443 | // emit a read barrier for the previous class reference load. |
| 4444 | // However this is not required in practice, as this is an |
| 4445 | // intermediate/temporary reference and because the current |
| 4446 | // concurrent copying collector keeps the from-space memory |
| 4447 | // intact/accessible until the end of the marking phase (the |
| 4448 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4449 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4450 | __ Ldr(temp, |
| 4451 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4452 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4453 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4454 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4455 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4456 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4457 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4458 | |
| 4459 | { |
| 4460 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4461 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4462 | |
| 4463 | // lr(); |
| 4464 | __ blr(lr); |
| 4465 | DCHECK(!codegen_->IsLeafMethod()); |
| 4466 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4467 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4468 | |
| 4469 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4473 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4474 | if (intrinsic.TryDispatch(invoke)) { |
| 4475 | return; |
| 4476 | } |
| 4477 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4478 | HandleInvoke(invoke); |
| 4479 | } |
| 4480 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4481 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4482 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4483 | // art::PrepareForRegisterAllocation. |
| 4484 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4485 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4486 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4487 | if (intrinsic.TryDispatch(invoke)) { |
| 4488 | return; |
| 4489 | } |
| 4490 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4491 | HandleInvoke(invoke); |
| 4492 | } |
| 4493 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4494 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4495 | if (invoke->GetLocations()->Intrinsified()) { |
| 4496 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4497 | intrinsic.Dispatch(invoke); |
| 4498 | return true; |
| 4499 | } |
| 4500 | return false; |
| 4501 | } |
| 4502 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4503 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4504 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4505 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4506 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4507 | return desired_dispatch_info; |
| 4508 | } |
| 4509 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4510 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4511 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4512 | // 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] | 4513 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4514 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4515 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4516 | uint32_t offset = |
| 4517 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4518 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4519 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4520 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4521 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4522 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4523 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4524 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4525 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4526 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4527 | // Add ADRP with its PC-relative method patch. |
| 4528 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4529 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4530 | // Add ADD with its PC-relative method patch. |
| 4531 | vixl::aarch64::Label* add_label = |
| 4532 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4533 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4534 | break; |
| 4535 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4536 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4537 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4538 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4540 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4542 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4543 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4544 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4545 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4546 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4547 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4548 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4549 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4550 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4551 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4552 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4553 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | switch (invoke->GetCodePtrLocation()) { |
| 4558 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4559 | { |
| 4560 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4561 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4562 | kInstructionSize, |
| 4563 | CodeBufferCheckScope::kExactSize); |
| 4564 | __ bl(&frame_entry_label_); |
| 4565 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4566 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4567 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4568 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4569 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4570 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4571 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4572 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4573 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4574 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4575 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4576 | kInstructionSize, |
| 4577 | CodeBufferCheckScope::kExactSize); |
| 4578 | // lr() |
| 4579 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4580 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4581 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4582 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4583 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4584 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4585 | DCHECK(!IsLeafMethod()); |
| 4586 | } |
| 4587 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4588 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4589 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4590 | // Use the calling convention instead of the location of the receiver, as |
| 4591 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4592 | // slow path, the arguments have been moved to the right place, so here we are |
| 4593 | // guaranteed that the receiver is the first register of the calling convention. |
| 4594 | InvokeDexCallingConvention calling_convention; |
| 4595 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4596 | Register temp = XRegisterFrom(temp_in); |
| 4597 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4598 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4599 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4600 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4601 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4602 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4603 | |
| 4604 | { |
| 4605 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4606 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4607 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4608 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4609 | MaybeRecordImplicitNullCheck(invoke); |
| 4610 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4611 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4612 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4613 | // intermediate/temporary reference and because the current |
| 4614 | // concurrent copying collector keeps the from-space memory |
| 4615 | // intact/accessible until the end of the marking phase (the |
| 4616 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4617 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4618 | // temp = temp->GetMethodAt(method_offset); |
| 4619 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4620 | // lr = temp->GetEntryPoint(); |
| 4621 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4622 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4623 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4624 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4625 | // lr(); |
| 4626 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4627 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4628 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4631 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4632 | HandleInvoke(invoke); |
| 4633 | } |
| 4634 | |
| 4635 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4636 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4637 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4640 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4641 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4642 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4643 | return NewPcRelativePatch(*target_method.dex_file, |
| 4644 | target_method.dex_method_index, |
| 4645 | adrp_label, |
| 4646 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4649 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4650 | MethodReference target_method, |
| 4651 | vixl::aarch64::Label* adrp_label) { |
| 4652 | return NewPcRelativePatch(*target_method.dex_file, |
| 4653 | target_method.dex_method_index, |
| 4654 | adrp_label, |
| 4655 | &method_bss_entry_patches_); |
| 4656 | } |
| 4657 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4658 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4659 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4660 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4661 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4662 | 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] | 4663 | } |
| 4664 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4665 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4666 | const DexFile& dex_file, |
| 4667 | dex::TypeIndex type_index, |
| 4668 | vixl::aarch64::Label* adrp_label) { |
| 4669 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4670 | } |
| 4671 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4672 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4673 | const DexFile& dex_file, |
| 4674 | dex::StringIndex string_index, |
| 4675 | vixl::aarch64::Label* adrp_label) { |
| 4676 | return |
| 4677 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4678 | } |
| 4679 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4680 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4681 | const DexFile& dex_file, |
| 4682 | dex::StringIndex string_index, |
| 4683 | vixl::aarch64::Label* adrp_label) { |
| 4684 | return NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
| 4685 | } |
| 4686 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4687 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4688 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4689 | return &baker_read_barrier_patches_.back().label; |
| 4690 | } |
| 4691 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4692 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4693 | const DexFile& dex_file, |
| 4694 | uint32_t offset_or_index, |
| 4695 | vixl::aarch64::Label* adrp_label, |
| 4696 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4697 | // Add a patch entry and return the label. |
| 4698 | patches->emplace_back(dex_file, offset_or_index); |
| 4699 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4700 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4701 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4702 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4703 | return label; |
| 4704 | } |
| 4705 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4706 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4707 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4708 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4709 | } |
| 4710 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4711 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4712 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4713 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4714 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4715 | return jit_string_patches_.GetOrCreate( |
| 4716 | StringReference(&dex_file, string_index), |
| 4717 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4718 | } |
| 4719 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4720 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4721 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4722 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4723 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4724 | return jit_class_patches_.GetOrCreate( |
| 4725 | TypeReference(&dex_file, type_index), |
| 4726 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4727 | } |
| 4728 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4729 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4730 | vixl::aarch64::Register reg) { |
| 4731 | DCHECK(reg.IsX()); |
| 4732 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4733 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4734 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4738 | vixl::aarch64::Register out, |
| 4739 | vixl::aarch64::Register base) { |
| 4740 | DCHECK(out.IsX()); |
| 4741 | DCHECK(base.IsX()); |
| 4742 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4743 | __ Bind(fixup_label); |
| 4744 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4745 | } |
| 4746 | |
| 4747 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4748 | vixl::aarch64::Register out, |
| 4749 | vixl::aarch64::Register base) { |
| 4750 | DCHECK(base.IsX()); |
| 4751 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4752 | __ Bind(fixup_label); |
| 4753 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4754 | } |
| 4755 | |
| 4756 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4757 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4758 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4759 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4760 | for (const PcRelativePatchInfo& info : infos) { |
| 4761 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4762 | &info.target_dex_file, |
| 4763 | info.pc_insn_label->GetLocation(), |
| 4764 | info.offset_or_index)); |
| 4765 | } |
| 4766 | } |
| 4767 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4768 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4769 | DCHECK(linker_patches->empty()); |
| 4770 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4771 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4772 | method_bss_entry_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4773 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4774 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4775 | pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4776 | string_bss_entry_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4777 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4778 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4779 | if (GetCompilerOptions().IsBootImage()) { |
| 4780 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4781 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4782 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4783 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4784 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4785 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4786 | } else { |
| 4787 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame^] | 4788 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeClassTablePatch>(pc_relative_type_patches_, |
| 4789 | linker_patches); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4790 | EmitPcRelativeLinkerPatches<LinkerPatch::StringInternTablePatch>(pc_relative_string_patches_, |
| 4791 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4792 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4793 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 4794 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4795 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4796 | linker_patches); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4797 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_bss_entry_patches_, |
| 4798 | linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4799 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 4800 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 4801 | info.custom_data)); |
| 4802 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4803 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4806 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4807 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4808 | value, |
| 4809 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4810 | } |
| 4811 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4812 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4813 | return uint64_literals_.GetOrCreate( |
| 4814 | value, |
| 4815 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4816 | } |
| 4817 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4818 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4819 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4820 | // art::PrepareForRegisterAllocation. |
| 4821 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4822 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4823 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4824 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4825 | return; |
| 4826 | } |
| 4827 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4828 | { |
| 4829 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4830 | // are no pools emitted. |
| 4831 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4832 | LocationSummary* locations = invoke->GetLocations(); |
| 4833 | codegen_->GenerateStaticOrDirectCall( |
| 4834 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4835 | } |
| 4836 | |
| 4837 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4841 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4842 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4843 | return; |
| 4844 | } |
| 4845 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4846 | { |
| 4847 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4848 | // are no pools emitted. |
| 4849 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4850 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4851 | DCHECK(!codegen_->IsLeafMethod()); |
| 4852 | } |
| 4853 | |
| 4854 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4857 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4858 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4859 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4860 | case HLoadClass::LoadKind::kInvalid: |
| 4861 | LOG(FATAL) << "UNREACHABLE"; |
| 4862 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4863 | case HLoadClass::LoadKind::kReferrersClass: |
| 4864 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4865 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame^] | 4866 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4867 | case HLoadClass::LoadKind::kBssEntry: |
| 4868 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4869 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4870 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4871 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4872 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4873 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4874 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4875 | break; |
| 4876 | } |
| 4877 | return desired_class_load_kind; |
| 4878 | } |
| 4879 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4880 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4881 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4882 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4883 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4884 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4885 | cls, |
| 4886 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4887 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4888 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4889 | return; |
| 4890 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4891 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4892 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4893 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4894 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4895 | ? LocationSummary::kCallOnSlowPath |
| 4896 | : LocationSummary::kNoCall; |
| 4897 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4898 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4899 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4900 | } |
| 4901 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4902 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4904 | } |
| 4905 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4906 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4907 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4908 | // 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] | 4909 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4910 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4911 | InvokeRuntimeCallingConvention calling_convention; |
| 4912 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4913 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4914 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4915 | Primitive::kPrimNot).GetCode()); |
| 4916 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4917 | } else { |
| 4918 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4919 | } |
| 4920 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4923 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4924 | // move. |
| 4925 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4926 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4927 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4928 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4929 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4930 | return; |
| 4931 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4932 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4933 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4934 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4935 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4936 | Register bss_entry_temp; |
| 4937 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4938 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4939 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4940 | ? kWithoutReadBarrier |
| 4941 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4942 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4943 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4944 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4945 | DCHECK(!cls->CanCallRuntime()); |
| 4946 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4947 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4948 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4949 | GenerateGcRootFieldLoad(cls, |
| 4950 | out_loc, |
| 4951 | current_method, |
| 4952 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4953 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4954 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4955 | break; |
| 4956 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4957 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4958 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4959 | // Add ADRP with its PC-relative type patch. |
| 4960 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4961 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4962 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4963 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4964 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4965 | vixl::aarch64::Label* add_label = |
| 4966 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4967 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4968 | break; |
| 4969 | } |
| 4970 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4971 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4972 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4973 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4974 | DCHECK_NE(address, 0u); |
| 4975 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4976 | break; |
| 4977 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame^] | 4978 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 4979 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 4980 | // Add ADRP with its PC-relative type patch. |
| 4981 | const DexFile& dex_file = cls->GetDexFile(); |
| 4982 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| 4983 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
| 4984 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 4985 | // Add LDR with its PC-relative type patch. |
| 4986 | vixl::aarch64::Label* ldr_label = |
| 4987 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
| 4988 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 4989 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 4990 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 4991 | ComputeModifiedUtf8Hash(dex_file.StringByTypeIdx(type_index))); |
| 4992 | if (masked_hash != 0) { |
| 4993 | __ Sub(out.W(), out.W(), Operand(masked_hash)); |
| 4994 | } |
| 4995 | break; |
| 4996 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4997 | case HLoadClass::LoadKind::kBssEntry: { |
| 4998 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4999 | const DexFile& dex_file = cls->GetDexFile(); |
| 5000 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5001 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5002 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5003 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5004 | // Add LDR with its PC-relative Class patch. |
| 5005 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5006 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5007 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 5008 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5009 | out_loc, |
| 5010 | bss_entry_temp, |
| 5011 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5012 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5013 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5014 | generate_null_check = true; |
| 5015 | break; |
| 5016 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5017 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5018 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5019 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5020 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5021 | GenerateGcRootFieldLoad(cls, |
| 5022 | out_loc, |
| 5023 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5024 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5025 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5026 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5027 | break; |
| 5028 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5029 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5030 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5031 | LOG(FATAL) << "UNREACHABLE"; |
| 5032 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5033 | } |
| 5034 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5035 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5036 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5037 | DCHECK(cls->CanCallRuntime()); |
| 5038 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5039 | 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] | 5040 | codegen_->AddSlowPath(slow_path); |
| 5041 | if (generate_null_check) { |
| 5042 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5043 | } |
| 5044 | if (cls->MustGenerateClinitCheck()) { |
| 5045 | GenerateClassInitializationCheck(slow_path, out); |
| 5046 | } else { |
| 5047 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5048 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5049 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5050 | } |
| 5051 | } |
| 5052 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5053 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5054 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5055 | } |
| 5056 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5057 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5058 | LocationSummary* locations = |
| 5059 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5060 | locations->SetOut(Location::RequiresRegister()); |
| 5061 | } |
| 5062 | |
| 5063 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5064 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5065 | } |
| 5066 | |
| 5067 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5068 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5069 | } |
| 5070 | |
| 5071 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5072 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5073 | } |
| 5074 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5075 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5076 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5077 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5078 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5079 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5080 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5081 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5082 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5083 | case HLoadString::LoadKind::kJitTableAddress: |
| 5084 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5085 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5086 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5087 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5088 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5089 | } |
| 5090 | return desired_string_load_kind; |
| 5091 | } |
| 5092 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5093 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5094 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5095 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5096 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5097 | InvokeRuntimeCallingConvention calling_convention; |
| 5098 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5099 | } else { |
| 5100 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5101 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5102 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5103 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5104 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5105 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5106 | InvokeRuntimeCallingConvention calling_convention; |
| 5107 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5108 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5109 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5110 | Primitive::kPrimNot).GetCode()); |
| 5111 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5112 | } else { |
| 5113 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5114 | } |
| 5115 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5116 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5119 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5120 | // move. |
| 5121 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5122 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5123 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5124 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5125 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5126 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5127 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5128 | // Add ADRP with its PC-relative String patch. |
| 5129 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5130 | const dex::StringIndex string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5131 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5132 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5133 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5134 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5135 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5136 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5137 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5138 | } |
| 5139 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5140 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5141 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5142 | DCHECK_NE(address, 0u); |
| 5143 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5144 | return; |
| 5145 | } |
| 5146 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5147 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5148 | // Add ADRP with its PC-relative String patch. |
| 5149 | const DexFile& dex_file = load->GetDexFile(); |
| 5150 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 5151 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 5152 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 5153 | // Add LDR with its PC-relative String patch. |
| 5154 | vixl::aarch64::Label* ldr_label = |
| 5155 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 5156 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5157 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5158 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5159 | case HLoadString::LoadKind::kBssEntry: { |
| 5160 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5161 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5162 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5163 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5164 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5165 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5166 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5167 | // Add LDR with its .bss entry String patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5168 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5169 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5170 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5171 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5172 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5173 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5174 | /* offset placeholder */ 0u, |
| 5175 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5176 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5177 | SlowPathCodeARM64* slow_path = |
| 5178 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5179 | codegen_->AddSlowPath(slow_path); |
| 5180 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5181 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5182 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5183 | return; |
| 5184 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5185 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5186 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5187 | load->GetStringIndex(), |
| 5188 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5189 | GenerateGcRootFieldLoad(load, |
| 5190 | out_loc, |
| 5191 | out.X(), |
| 5192 | /* offset */ 0, |
| 5193 | /* fixup_label */ nullptr, |
| 5194 | kCompilerReadBarrierOption); |
| 5195 | return; |
| 5196 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5197 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5198 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5199 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5200 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5201 | // 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] | 5202 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5203 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5204 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5205 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5206 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5207 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5210 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5211 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5212 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5213 | } |
| 5214 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5215 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5216 | // Will be generated at use site. |
| 5217 | } |
| 5218 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5219 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5220 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5221 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5222 | InvokeRuntimeCallingConvention calling_convention; |
| 5223 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5224 | } |
| 5225 | |
| 5226 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5227 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5228 | instruction, |
| 5229 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5230 | if (instruction->IsEnter()) { |
| 5231 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5232 | } else { |
| 5233 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5234 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5235 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5236 | } |
| 5237 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5238 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5239 | LocationSummary* locations = |
| 5240 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5241 | switch (mul->GetResultType()) { |
| 5242 | case Primitive::kPrimInt: |
| 5243 | case Primitive::kPrimLong: |
| 5244 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5245 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5246 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5247 | break; |
| 5248 | |
| 5249 | case Primitive::kPrimFloat: |
| 5250 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5251 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5252 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5253 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5254 | break; |
| 5255 | |
| 5256 | default: |
| 5257 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5258 | } |
| 5259 | } |
| 5260 | |
| 5261 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5262 | switch (mul->GetResultType()) { |
| 5263 | case Primitive::kPrimInt: |
| 5264 | case Primitive::kPrimLong: |
| 5265 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5266 | break; |
| 5267 | |
| 5268 | case Primitive::kPrimFloat: |
| 5269 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5270 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5271 | break; |
| 5272 | |
| 5273 | default: |
| 5274 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5275 | } |
| 5276 | } |
| 5277 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5278 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5279 | LocationSummary* locations = |
| 5280 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5281 | switch (neg->GetResultType()) { |
| 5282 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5283 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5284 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5285 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5286 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5287 | |
| 5288 | case Primitive::kPrimFloat: |
| 5289 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5290 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5291 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5292 | break; |
| 5293 | |
| 5294 | default: |
| 5295 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5300 | switch (neg->GetResultType()) { |
| 5301 | case Primitive::kPrimInt: |
| 5302 | case Primitive::kPrimLong: |
| 5303 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5304 | break; |
| 5305 | |
| 5306 | case Primitive::kPrimFloat: |
| 5307 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5308 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5309 | break; |
| 5310 | |
| 5311 | default: |
| 5312 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5317 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5318 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5319 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5320 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5321 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5322 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5326 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5327 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5328 | QuickEntrypointEnum entrypoint = |
| 5329 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5330 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5331 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5332 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5335 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5336 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5337 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5338 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5339 | if (instruction->IsStringAlloc()) { |
| 5340 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5341 | } else { |
| 5342 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5343 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5344 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5345 | } |
| 5346 | |
| 5347 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5348 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5349 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5350 | if (instruction->IsStringAlloc()) { |
| 5351 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5352 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5353 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5354 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5355 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5356 | |
| 5357 | { |
| 5358 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5359 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5360 | kInstructionSize, |
| 5361 | CodeBufferCheckScope::kExactSize); |
| 5362 | __ blr(lr); |
| 5363 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5364 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5365 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5366 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5367 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5368 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5369 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5373 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5374 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5375 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5379 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5380 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5381 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5382 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5383 | break; |
| 5384 | |
| 5385 | default: |
| 5386 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5387 | } |
| 5388 | } |
| 5389 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5390 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5391 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5392 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5393 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5394 | } |
| 5395 | |
| 5396 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5397 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5398 | } |
| 5399 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5400 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5401 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5402 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5403 | } |
| 5404 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5405 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5406 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5407 | return; |
| 5408 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5409 | { |
| 5410 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5411 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5412 | Location obj = instruction->GetLocations()->InAt(0); |
| 5413 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5414 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5415 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5416 | } |
| 5417 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5418 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5419 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5420 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5421 | |
| 5422 | LocationSummary* locations = instruction->GetLocations(); |
| 5423 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5424 | |
| 5425 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5426 | } |
| 5427 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5428 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5429 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5432 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5433 | HandleBinaryOp(instruction); |
| 5434 | } |
| 5435 | |
| 5436 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5437 | HandleBinaryOp(instruction); |
| 5438 | } |
| 5439 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5440 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5441 | LOG(FATAL) << "Unreachable"; |
| 5442 | } |
| 5443 | |
| 5444 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5445 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5446 | } |
| 5447 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5448 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5449 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5450 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5451 | if (location.IsStackSlot()) { |
| 5452 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5453 | } else if (location.IsDoubleStackSlot()) { |
| 5454 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5455 | } |
| 5456 | locations->SetOut(location); |
| 5457 | } |
| 5458 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5459 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5460 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5461 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5465 | LocationSummary* locations = |
| 5466 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5467 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5471 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5472 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5473 | } |
| 5474 | |
| 5475 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5477 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5478 | locations->SetInAt(i, Location::Any()); |
| 5479 | } |
| 5480 | locations->SetOut(Location::Any()); |
| 5481 | } |
| 5482 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5483 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5484 | LOG(FATAL) << "Unreachable"; |
| 5485 | } |
| 5486 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5487 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5488 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5489 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5490 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5491 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5492 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5493 | |
| 5494 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5495 | case Primitive::kPrimInt: |
| 5496 | case Primitive::kPrimLong: |
| 5497 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5498 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5499 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5500 | break; |
| 5501 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5502 | case Primitive::kPrimFloat: |
| 5503 | case Primitive::kPrimDouble: { |
| 5504 | InvokeRuntimeCallingConvention calling_convention; |
| 5505 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5506 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5507 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5508 | |
| 5509 | break; |
| 5510 | } |
| 5511 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5512 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5513 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5518 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5519 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5520 | switch (type) { |
| 5521 | case Primitive::kPrimInt: |
| 5522 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5523 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5524 | break; |
| 5525 | } |
| 5526 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5527 | case Primitive::kPrimFloat: |
| 5528 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5529 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5530 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5531 | if (type == Primitive::kPrimFloat) { |
| 5532 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5533 | } else { |
| 5534 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5535 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5536 | break; |
| 5537 | } |
| 5538 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5539 | default: |
| 5540 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5541 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5542 | } |
| 5543 | } |
| 5544 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5545 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5546 | constructor_fence->SetLocations(nullptr); |
| 5547 | } |
| 5548 | |
| 5549 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5550 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5551 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5552 | } |
| 5553 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5554 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5555 | memory_barrier->SetLocations(nullptr); |
| 5556 | } |
| 5557 | |
| 5558 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5559 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5560 | } |
| 5561 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5562 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5563 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5564 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5565 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5566 | } |
| 5567 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5568 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5569 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5573 | instruction->SetLocations(nullptr); |
| 5574 | } |
| 5575 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5576 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5577 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5578 | } |
| 5579 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5580 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5581 | HandleBinaryOp(ror); |
| 5582 | } |
| 5583 | |
| 5584 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5585 | HandleBinaryOp(ror); |
| 5586 | } |
| 5587 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5588 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5589 | HandleShift(shl); |
| 5590 | } |
| 5591 | |
| 5592 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5593 | HandleShift(shl); |
| 5594 | } |
| 5595 | |
| 5596 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5597 | HandleShift(shr); |
| 5598 | } |
| 5599 | |
| 5600 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5601 | HandleShift(shr); |
| 5602 | } |
| 5603 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5604 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5605 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5606 | } |
| 5607 | |
| 5608 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5609 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5610 | } |
| 5611 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5612 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5613 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5617 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5621 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5622 | } |
| 5623 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5624 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5625 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5626 | } |
| 5627 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5628 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5629 | HUnresolvedInstanceFieldGet* instruction) { |
| 5630 | FieldAccessCallingConventionARM64 calling_convention; |
| 5631 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5632 | instruction, instruction->GetFieldType(), calling_convention); |
| 5633 | } |
| 5634 | |
| 5635 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5636 | HUnresolvedInstanceFieldGet* instruction) { |
| 5637 | FieldAccessCallingConventionARM64 calling_convention; |
| 5638 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5639 | instruction->GetFieldType(), |
| 5640 | instruction->GetFieldIndex(), |
| 5641 | instruction->GetDexPc(), |
| 5642 | calling_convention); |
| 5643 | } |
| 5644 | |
| 5645 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5646 | HUnresolvedInstanceFieldSet* instruction) { |
| 5647 | FieldAccessCallingConventionARM64 calling_convention; |
| 5648 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5649 | instruction, instruction->GetFieldType(), calling_convention); |
| 5650 | } |
| 5651 | |
| 5652 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5653 | HUnresolvedInstanceFieldSet* instruction) { |
| 5654 | FieldAccessCallingConventionARM64 calling_convention; |
| 5655 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5656 | instruction->GetFieldType(), |
| 5657 | instruction->GetFieldIndex(), |
| 5658 | instruction->GetDexPc(), |
| 5659 | calling_convention); |
| 5660 | } |
| 5661 | |
| 5662 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5663 | HUnresolvedStaticFieldGet* instruction) { |
| 5664 | FieldAccessCallingConventionARM64 calling_convention; |
| 5665 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5666 | instruction, instruction->GetFieldType(), calling_convention); |
| 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5670 | HUnresolvedStaticFieldGet* instruction) { |
| 5671 | FieldAccessCallingConventionARM64 calling_convention; |
| 5672 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5673 | instruction->GetFieldType(), |
| 5674 | instruction->GetFieldIndex(), |
| 5675 | instruction->GetDexPc(), |
| 5676 | calling_convention); |
| 5677 | } |
| 5678 | |
| 5679 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5680 | HUnresolvedStaticFieldSet* instruction) { |
| 5681 | FieldAccessCallingConventionARM64 calling_convention; |
| 5682 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5683 | instruction, instruction->GetFieldType(), calling_convention); |
| 5684 | } |
| 5685 | |
| 5686 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5687 | HUnresolvedStaticFieldSet* instruction) { |
| 5688 | FieldAccessCallingConventionARM64 calling_convention; |
| 5689 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5690 | instruction->GetFieldType(), |
| 5691 | instruction->GetFieldIndex(), |
| 5692 | instruction->GetDexPc(), |
| 5693 | calling_convention); |
| 5694 | } |
| 5695 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5696 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5697 | LocationSummary* locations = |
| 5698 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5699 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5700 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5701 | // registers in full width (since the runtime only saves/restores lower part). |
| 5702 | locations->SetCustomSlowPathCallerSaves( |
| 5703 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5707 | HBasicBlock* block = instruction->GetBlock(); |
| 5708 | if (block->GetLoopInformation() != nullptr) { |
| 5709 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5710 | // The back edge will generate the suspend check. |
| 5711 | return; |
| 5712 | } |
| 5713 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5714 | // The goto will generate the suspend check. |
| 5715 | return; |
| 5716 | } |
| 5717 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5718 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5719 | } |
| 5720 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5721 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5722 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5723 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5724 | InvokeRuntimeCallingConvention calling_convention; |
| 5725 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5726 | } |
| 5727 | |
| 5728 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5729 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5730 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5734 | LocationSummary* locations = |
| 5735 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5736 | Primitive::Type input_type = conversion->GetInputType(); |
| 5737 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5738 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5739 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5740 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5741 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5742 | } |
| 5743 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5744 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5745 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5746 | } else { |
| 5747 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5748 | } |
| 5749 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5750 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5751 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5752 | } else { |
| 5753 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5758 | Primitive::Type result_type = conversion->GetResultType(); |
| 5759 | Primitive::Type input_type = conversion->GetInputType(); |
| 5760 | |
| 5761 | DCHECK_NE(input_type, result_type); |
| 5762 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5763 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5764 | int result_size = Primitive::ComponentSize(result_type); |
| 5765 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5766 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5767 | Register output = OutputRegister(conversion); |
| 5768 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5769 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5770 | // 'int' values are used directly as W registers, discarding the top |
| 5771 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5772 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5773 | // top 32 bits of the target register. We theoretically could leave those |
| 5774 | // bits unchanged, but we would have to make sure that no code uses a |
| 5775 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5776 | // zero. |
| 5777 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5778 | } else if (result_type == Primitive::kPrimChar || |
| 5779 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5780 | __ Ubfx(output, |
| 5781 | output.IsX() ? source.X() : source.W(), |
| 5782 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5783 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5784 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5785 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5786 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5787 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5788 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5789 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5790 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5791 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5792 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5793 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5794 | } else { |
| 5795 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5796 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5797 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5798 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5799 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5800 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5801 | HandleShift(ushr); |
| 5802 | } |
| 5803 | |
| 5804 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5805 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5809 | HandleBinaryOp(instruction); |
| 5810 | } |
| 5811 | |
| 5812 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5813 | HandleBinaryOp(instruction); |
| 5814 | } |
| 5815 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5816 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5817 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5818 | LOG(FATAL) << "Unreachable"; |
| 5819 | } |
| 5820 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5821 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5822 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5823 | LOG(FATAL) << "Unreachable"; |
| 5824 | } |
| 5825 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5826 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5827 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5828 | LocationSummary* locations = |
| 5829 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5830 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5831 | } |
| 5832 | |
| 5833 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5834 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5835 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5836 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5837 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5838 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5839 | // 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] | 5840 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5841 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5842 | // make sure we don't emit it if the target may run out of range. |
| 5843 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5844 | // ranges and emit the tables only as required. |
| 5845 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5846 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5847 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5848 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5849 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5850 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5851 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5852 | Register temp = temps.AcquireW(); |
| 5853 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5854 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5855 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5856 | // Jump to successors[0] if value == lower_bound. |
| 5857 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5858 | int32_t last_index = 0; |
| 5859 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5860 | __ Subs(temp, temp, Operand(2)); |
| 5861 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5862 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5863 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5864 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5865 | } |
| 5866 | if (num_entries - last_index == 2) { |
| 5867 | // The last missing case_value. |
| 5868 | __ Cmp(temp, Operand(1)); |
| 5869 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | // And the default for any other value. |
| 5873 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5874 | __ B(codegen_->GetLabelOf(default_block)); |
| 5875 | } |
| 5876 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5877 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5878 | |
| 5879 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5880 | |
| 5881 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5882 | // registers, we are free to block one. |
| 5883 | Register temp_w = temps.AcquireW(); |
| 5884 | Register index; |
| 5885 | // Remove the bias. |
| 5886 | if (lower_bound != 0) { |
| 5887 | index = temp_w; |
| 5888 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5889 | } else { |
| 5890 | index = value_reg; |
| 5891 | } |
| 5892 | |
| 5893 | // Jump to default block if index is out of the range. |
| 5894 | __ Cmp(index, Operand(num_entries)); |
| 5895 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5896 | |
| 5897 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5898 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5899 | // register pressure. |
| 5900 | Register table_base = temps.AcquireX(); |
| 5901 | // Load jump offset from the table. |
| 5902 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5903 | Register jump_offset = temp_w; |
| 5904 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5905 | |
| 5906 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5907 | Register target_address = table_base; |
| 5908 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5909 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5910 | } |
| 5911 | } |
| 5912 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5913 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5914 | HInstruction* instruction, |
| 5915 | Location out, |
| 5916 | uint32_t offset, |
| 5917 | Location maybe_temp, |
| 5918 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5919 | Primitive::Type type = Primitive::kPrimNot; |
| 5920 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5921 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5922 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5923 | if (kUseBakerReadBarrier) { |
| 5924 | // Load with fast path based Baker's read barrier. |
| 5925 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5926 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5927 | out, |
| 5928 | out_reg, |
| 5929 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5930 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5931 | /* needs_null_check */ false, |
| 5932 | /* use_load_acquire */ false); |
| 5933 | } else { |
| 5934 | // Load with slow path based read barrier. |
| 5935 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5936 | // in the following move operation, as we will need it for the |
| 5937 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5938 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5939 | __ Mov(temp_reg, out_reg); |
| 5940 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5941 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5942 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5943 | } |
| 5944 | } else { |
| 5945 | // Plain load with no read barrier. |
| 5946 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5947 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5948 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5949 | } |
| 5950 | } |
| 5951 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5952 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5953 | HInstruction* instruction, |
| 5954 | Location out, |
| 5955 | Location obj, |
| 5956 | uint32_t offset, |
| 5957 | Location maybe_temp, |
| 5958 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5959 | Primitive::Type type = Primitive::kPrimNot; |
| 5960 | Register out_reg = RegisterFrom(out, type); |
| 5961 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5962 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5963 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5964 | if (kUseBakerReadBarrier) { |
| 5965 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5966 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5967 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5968 | out, |
| 5969 | obj_reg, |
| 5970 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5971 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5972 | /* needs_null_check */ false, |
| 5973 | /* use_load_acquire */ false); |
| 5974 | } else { |
| 5975 | // Load with slow path based read barrier. |
| 5976 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5977 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5978 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5979 | } |
| 5980 | } else { |
| 5981 | // Plain load with no read barrier. |
| 5982 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5983 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5984 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5985 | } |
| 5986 | } |
| 5987 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5988 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5989 | HInstruction* instruction, |
| 5990 | Location root, |
| 5991 | Register obj, |
| 5992 | uint32_t offset, |
| 5993 | vixl::aarch64::Label* fixup_label, |
| 5994 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5995 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5996 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5997 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5998 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5999 | if (kUseBakerReadBarrier) { |
| 6000 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6001 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6002 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 6003 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6004 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6005 | // the Marking Register) to decide whether we need to enter |
| 6006 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6007 | // |
| 6008 | // We use link-time generated thunks for the slow path. That thunk |
| 6009 | // checks the reference and jumps to the entrypoint if needed. |
| 6010 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6011 | // lr = &return_address; |
| 6012 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6013 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6014 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6015 | // } |
| 6016 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6017 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6018 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6019 | DCHECK(temps.IsAvailable(ip0)); |
| 6020 | DCHECK(temps.IsAvailable(ip1)); |
| 6021 | temps.Exclude(ip0, ip1); |
| 6022 | uint32_t custom_data = |
| 6023 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 6024 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6025 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6026 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6027 | vixl::aarch64::Label return_address; |
| 6028 | __ adr(lr, &return_address); |
| 6029 | if (fixup_label != nullptr) { |
| 6030 | __ Bind(fixup_label); |
| 6031 | } |
| 6032 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6033 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6034 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6035 | __ Bind(cbnz_label); |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6036 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6037 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6038 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6039 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6040 | // the Marking Register) to decide whether we need to enter |
| 6041 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6042 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6043 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6044 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6045 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6046 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6047 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6048 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6049 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6050 | // Slow path marking the GC root `root`. The entrypoint will |
| 6051 | // be loaded by the slow path code. |
| 6052 | SlowPathCodeARM64* slow_path = |
| 6053 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6054 | codegen_->AddSlowPath(slow_path); |
| 6055 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6056 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6057 | if (fixup_label == nullptr) { |
| 6058 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6059 | } else { |
| 6060 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6061 | } |
| 6062 | static_assert( |
| 6063 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6064 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6065 | "have different sizes."); |
| 6066 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6067 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6068 | "have different sizes."); |
| 6069 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6070 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6071 | __ Bind(slow_path->GetExitLabel()); |
| 6072 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6073 | } else { |
| 6074 | // GC root loaded through a slow path for read barriers other |
| 6075 | // than Baker's. |
| 6076 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6077 | if (fixup_label == nullptr) { |
| 6078 | __ Add(root_reg.X(), obj.X(), offset); |
| 6079 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6080 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6081 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6082 | // /* mirror::Object* */ root = root->Read() |
| 6083 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6084 | } |
| 6085 | } else { |
| 6086 | // Plain GC root load with no read barrier. |
| 6087 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6088 | if (fixup_label == nullptr) { |
| 6089 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6090 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6091 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6092 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6093 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6094 | // do not have to unpoison `root_reg` here. |
| 6095 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6096 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6100 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6101 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6102 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6103 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6104 | bool needs_null_check, |
| 6105 | bool use_load_acquire) { |
| 6106 | DCHECK(kEmitCompilerReadBarrier); |
| 6107 | DCHECK(kUseBakerReadBarrier); |
| 6108 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6109 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6110 | !use_load_acquire && |
| 6111 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6112 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6113 | // Marking Register) to decide whether we need to enter the slow |
| 6114 | // path to mark the reference. Then, in the slow path, check the |
| 6115 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6116 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6117 | // |
| 6118 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6119 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6120 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6121 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6122 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6123 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6124 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6125 | // } |
| 6126 | // not_gray_return_address: |
| 6127 | // // Original reference load. If the offset is too large to fit |
| 6128 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6129 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6130 | // gray_return_address: |
| 6131 | |
| 6132 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6133 | Register base = obj; |
| 6134 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6135 | DCHECK(maybe_temp.IsRegister()); |
| 6136 | base = WRegisterFrom(maybe_temp); |
| 6137 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6138 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6139 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6140 | } |
| 6141 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6142 | DCHECK(temps.IsAvailable(ip0)); |
| 6143 | DCHECK(temps.IsAvailable(ip1)); |
| 6144 | temps.Exclude(ip0, ip1); |
| 6145 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6146 | base.GetCode(), |
| 6147 | obj.GetCode()); |
| 6148 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6149 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6150 | { |
| 6151 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6152 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6153 | vixl::aarch64::Label return_address; |
| 6154 | __ adr(lr, &return_address); |
| 6155 | __ Bind(cbnz_label); |
| 6156 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6157 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6158 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6159 | " 2 instructions (8B) for heap poisoning."); |
| 6160 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6161 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6162 | if (needs_null_check) { |
| 6163 | MaybeRecordImplicitNullCheck(instruction); |
| 6164 | } |
| 6165 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6166 | __ Bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6167 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6168 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6169 | return; |
| 6170 | } |
| 6171 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6172 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6173 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6174 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6175 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6176 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6177 | ref, |
| 6178 | obj, |
| 6179 | offset, |
| 6180 | no_index, |
| 6181 | no_scale_factor, |
| 6182 | temp, |
| 6183 | needs_null_check, |
| 6184 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6188 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6189 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6190 | uint32_t data_offset, |
| 6191 | Location index, |
| 6192 | Register temp, |
| 6193 | bool needs_null_check) { |
| 6194 | DCHECK(kEmitCompilerReadBarrier); |
| 6195 | DCHECK(kUseBakerReadBarrier); |
| 6196 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6197 | static_assert( |
| 6198 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6199 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6200 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6201 | |
| 6202 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6203 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6204 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6205 | // Marking Register) to decide whether we need to enter the slow |
| 6206 | // path to mark the reference. Then, in the slow path, check the |
| 6207 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6208 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6209 | // |
| 6210 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6211 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6212 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6213 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6214 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6215 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6216 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6217 | // } |
| 6218 | // not_gray_return_address: |
| 6219 | // // Original reference load. If the offset is too large to fit |
| 6220 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6221 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6222 | // gray_return_address: |
| 6223 | |
| 6224 | DCHECK(index.IsValid()); |
| 6225 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 6226 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6227 | |
| 6228 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6229 | DCHECK(temps.IsAvailable(ip0)); |
| 6230 | DCHECK(temps.IsAvailable(ip1)); |
| 6231 | temps.Exclude(ip0, ip1); |
| 6232 | uint32_t custom_data = |
| 6233 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6234 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6235 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6236 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6237 | { |
| 6238 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6239 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6240 | vixl::aarch64::Label return_address; |
| 6241 | __ adr(lr, &return_address); |
| 6242 | __ Bind(cbnz_label); |
| 6243 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6244 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6245 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6246 | " 2 instructions (8B) for heap poisoning."); |
| 6247 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6248 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6249 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6250 | __ Bind(&return_address); |
| 6251 | } |
| 6252 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6253 | return; |
| 6254 | } |
| 6255 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6256 | // Array cells are never volatile variables, therefore array loads |
| 6257 | // never use Load-Acquire instructions on ARM64. |
| 6258 | const bool use_load_acquire = false; |
| 6259 | |
| 6260 | // /* HeapReference<Object> */ ref = |
| 6261 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6262 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6263 | ref, |
| 6264 | obj, |
| 6265 | data_offset, |
| 6266 | index, |
| 6267 | scale_factor, |
| 6268 | temp, |
| 6269 | needs_null_check, |
| 6270 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6274 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6275 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6276 | uint32_t offset, |
| 6277 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6278 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6279 | Register temp, |
| 6280 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6281 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6282 | DCHECK(kEmitCompilerReadBarrier); |
| 6283 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6284 | // If we are emitting an array load, we should not be using a |
| 6285 | // Load Acquire instruction. In other words: |
| 6286 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6287 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6288 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6289 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6290 | // Marking Register) to decide whether we need to enter the slow |
| 6291 | // path to mark the reference. Then, in the slow path, check the |
| 6292 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6293 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6294 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6295 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6296 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6297 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6298 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6299 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6300 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6301 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6302 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6303 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6304 | // } |
| 6305 | // } else { |
| 6306 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6307 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6308 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6309 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6310 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6311 | SlowPathCodeARM64* slow_path = |
| 6312 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6313 | instruction, |
| 6314 | ref, |
| 6315 | obj, |
| 6316 | offset, |
| 6317 | index, |
| 6318 | scale_factor, |
| 6319 | needs_null_check, |
| 6320 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6321 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6322 | AddSlowPath(slow_path); |
| 6323 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6324 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6325 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6326 | GenerateRawReferenceLoad( |
| 6327 | 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] | 6328 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6329 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6330 | } |
| 6331 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6332 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6333 | Location ref, |
| 6334 | Register obj, |
| 6335 | Location field_offset, |
| 6336 | Register temp, |
| 6337 | bool needs_null_check, |
| 6338 | bool use_load_acquire) { |
| 6339 | DCHECK(kEmitCompilerReadBarrier); |
| 6340 | DCHECK(kUseBakerReadBarrier); |
| 6341 | // If we are emitting an array load, we should not be using a |
| 6342 | // Load Acquire instruction. In other words: |
| 6343 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6344 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6345 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6346 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6347 | // Marking Register) to decide whether we need to enter the slow |
| 6348 | // path to update the reference field within `obj`. Then, in the |
| 6349 | // slow path, check the gray bit in the lock word of the reference's |
| 6350 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6351 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6352 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6353 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6354 | // // Slow path. |
| 6355 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6356 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6357 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6358 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6359 | // if (is_gray) { |
| 6360 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6361 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6362 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6363 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6364 | // } |
| 6365 | // } |
| 6366 | |
| 6367 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6368 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6369 | SlowPathCodeARM64* slow_path = |
| 6370 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6371 | instruction, |
| 6372 | ref, |
| 6373 | obj, |
| 6374 | /* offset */ 0u, |
| 6375 | /* index */ field_offset, |
| 6376 | /* scale_factor */ 0u /* "times 1" */, |
| 6377 | needs_null_check, |
| 6378 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6379 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6380 | AddSlowPath(slow_path); |
| 6381 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6382 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6383 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6384 | // up-to-date, and we don't need to load the reference). |
| 6385 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6386 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6387 | } |
| 6388 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6389 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6390 | Location ref, |
| 6391 | Register obj, |
| 6392 | uint32_t offset, |
| 6393 | Location index, |
| 6394 | size_t scale_factor, |
| 6395 | bool needs_null_check, |
| 6396 | bool use_load_acquire) { |
| 6397 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6398 | Primitive::Type type = Primitive::kPrimNot; |
| 6399 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6400 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6401 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6402 | // that no pools are emitted between the load (macro) instruction |
| 6403 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6404 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6405 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6406 | // Load types involving an "index": ArrayGet, |
| 6407 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6408 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6409 | if (use_load_acquire) { |
| 6410 | // UnsafeGetObjectVolatile intrinsic case. |
| 6411 | // Register `index` is not an index in an object array, but an |
| 6412 | // offset to an object reference field within object `obj`. |
| 6413 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6414 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6415 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6416 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6417 | DCHECK_EQ(offset, 0u); |
| 6418 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6419 | DCHECK_EQ(needs_null_check, false); |
| 6420 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6421 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6422 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6423 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6424 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6425 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6426 | if (index.IsConstant()) { |
| 6427 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6428 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6429 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6430 | if (needs_null_check) { |
| 6431 | MaybeRecordImplicitNullCheck(instruction); |
| 6432 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6433 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6434 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6435 | Register temp = temps.AcquireW(); |
| 6436 | __ Add(temp, obj, offset); |
| 6437 | { |
| 6438 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6439 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6440 | if (needs_null_check) { |
| 6441 | MaybeRecordImplicitNullCheck(instruction); |
| 6442 | } |
| 6443 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6444 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6445 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6446 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6447 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6448 | MemOperand field = HeapOperand(obj, offset); |
| 6449 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6450 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6451 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6452 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6453 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6454 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6455 | if (needs_null_check) { |
| 6456 | MaybeRecordImplicitNullCheck(instruction); |
| 6457 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6458 | } |
| 6459 | } |
| 6460 | |
| 6461 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6462 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6465 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6466 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6467 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6468 | // The following condition is a run-time one; it is executed after the |
| 6469 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6470 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6471 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6472 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6473 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6474 | } |
| 6475 | } |
| 6476 | } |
| 6477 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6478 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6479 | Location out, |
| 6480 | Location ref, |
| 6481 | Location obj, |
| 6482 | uint32_t offset, |
| 6483 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6484 | DCHECK(kEmitCompilerReadBarrier); |
| 6485 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6486 | // Insert a slow path based read barrier *after* the reference load. |
| 6487 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6488 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6489 | // reference will be carried out by the runtime within the slow |
| 6490 | // path. |
| 6491 | // |
| 6492 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6493 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6494 | // not used by the artReadBarrierSlow entry point. |
| 6495 | // |
| 6496 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6497 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6498 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6499 | AddSlowPath(slow_path); |
| 6500 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6501 | __ B(slow_path->GetEntryLabel()); |
| 6502 | __ Bind(slow_path->GetExitLabel()); |
| 6503 | } |
| 6504 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6505 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6506 | Location out, |
| 6507 | Location ref, |
| 6508 | Location obj, |
| 6509 | uint32_t offset, |
| 6510 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6511 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6512 | // Baker's read barriers shall be handled by the fast path |
| 6513 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6514 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6515 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6516 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6517 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6518 | } else if (kPoisonHeapReferences) { |
| 6519 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6520 | } |
| 6521 | } |
| 6522 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6523 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6524 | Location out, |
| 6525 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6526 | DCHECK(kEmitCompilerReadBarrier); |
| 6527 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6528 | // Insert a slow path based read barrier *after* the GC root load. |
| 6529 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6530 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6531 | // not need to do anything special for this here. |
| 6532 | SlowPathCodeARM64* slow_path = |
| 6533 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6534 | AddSlowPath(slow_path); |
| 6535 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6536 | __ B(slow_path->GetEntryLabel()); |
| 6537 | __ Bind(slow_path->GetExitLabel()); |
| 6538 | } |
| 6539 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6540 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6541 | LocationSummary* locations = |
| 6542 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6544 | locations->SetOut(Location::RequiresRegister()); |
| 6545 | } |
| 6546 | |
| 6547 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6548 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6549 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6550 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6551 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6552 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6553 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6554 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6555 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6556 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6557 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6558 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6559 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6560 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6561 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6562 | } |
| 6563 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6564 | static void PatchJitRootUse(uint8_t* code, |
| 6565 | const uint8_t* roots_data, |
| 6566 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6567 | uint64_t index_in_table) { |
| 6568 | uint32_t literal_offset = literal->GetOffset(); |
| 6569 | uintptr_t address = |
| 6570 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6571 | uint8_t* data = code + literal_offset; |
| 6572 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6573 | } |
| 6574 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6575 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6576 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6577 | const StringReference& string_reference = entry.first; |
| 6578 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6579 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6580 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6581 | uint64_t index_in_table = it->second; |
| 6582 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6583 | } |
| 6584 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6585 | const TypeReference& type_reference = entry.first; |
| 6586 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6587 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6588 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6589 | uint64_t index_in_table = it->second; |
| 6590 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6591 | } |
| 6592 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6593 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6594 | #undef __ |
| 6595 | #undef QUICK_ENTRY_POINT |
| 6596 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6597 | } // namespace arm64 |
| 6598 | } // namespace art |