Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 25 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 29 | #include "intrinsics.h" |
| 30 | #include "intrinsics_arm64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 31 | #include "linker/arm64/relative_patcher_arm64.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 32 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 34 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 35 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "thread.h" |
| 37 | #include "utils/arm64/assembler_arm64.h" |
| 38 | #include "utils/assembler.h" |
| 39 | #include "utils/stack_checks.h" |
| 40 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 41 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 42 | using vixl::ExactAssemblyScope; |
| 43 | using vixl::CodeBufferCheckScope; |
| 44 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 45 | |
| 46 | #ifdef __ |
| 47 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 48 | #endif |
| 49 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 50 | namespace art { |
| 51 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 52 | template<class MirrorType> |
| 53 | class GcRoot; |
| 54 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 55 | namespace arm64 { |
| 56 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 57 | using helpers::ARM64EncodableConstantOrRegister; |
| 58 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 59 | using helpers::CPURegisterFrom; |
| 60 | using helpers::DRegisterFrom; |
| 61 | using helpers::FPRegisterFrom; |
| 62 | using helpers::HeapOperand; |
| 63 | using helpers::HeapOperandFrom; |
| 64 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 65 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 66 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 67 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | using helpers::LocationFrom; |
| 72 | using helpers::OperandFromMemOperand; |
| 73 | using helpers::OutputCPURegister; |
| 74 | using helpers::OutputFPRegister; |
| 75 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 76 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 77 | using helpers::RegisterFrom; |
| 78 | using helpers::StackOperandFrom; |
| 79 | using helpers::VIXLRegCodeFromART; |
| 80 | using helpers::WRegisterFrom; |
| 81 | using helpers::XRegisterFrom; |
| 82 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 83 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 84 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 85 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 86 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 87 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 88 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 89 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 90 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 91 | // the offset explicitly. |
| 92 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 93 | |
| 94 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 95 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 96 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 97 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 98 | |
| 99 | // Some instructions have special requirements for a temporary, for example |
| 100 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 101 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 102 | // loads with large offsets need a fixed register to limit the number of link-time |
| 103 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 104 | // register that's neither callee-save nor an argument register. We choose x15. |
| 105 | inline Location FixedTempLocation() { |
| 106 | return Location::RegisterLocation(x15.GetCode()); |
| 107 | } |
| 108 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 109 | inline Condition ARM64Condition(IfCondition cond) { |
| 110 | switch (cond) { |
| 111 | case kCondEQ: return eq; |
| 112 | case kCondNE: return ne; |
| 113 | case kCondLT: return lt; |
| 114 | case kCondLE: return le; |
| 115 | case kCondGT: return gt; |
| 116 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 117 | case kCondB: return lo; |
| 118 | case kCondBE: return ls; |
| 119 | case kCondA: return hi; |
| 120 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 121 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 122 | LOG(FATAL) << "Unreachable"; |
| 123 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 126 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 127 | // The ARM64 condition codes can express all the necessary branches, see the |
| 128 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 129 | // There is no dex instruction or HIR that would need the missing conditions |
| 130 | // "equal or unordered" or "not equal". |
| 131 | switch (cond) { |
| 132 | case kCondEQ: return eq; |
| 133 | case kCondNE: return ne /* unordered */; |
| 134 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 135 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 136 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 137 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 138 | default: |
| 139 | LOG(FATAL) << "UNREACHABLE"; |
| 140 | UNREACHABLE(); |
| 141 | } |
| 142 | } |
| 143 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 144 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 145 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 146 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 147 | // but we use the exact registers for clarity. |
| 148 | if (return_type == Primitive::kPrimFloat) { |
| 149 | return LocationFrom(s0); |
| 150 | } else if (return_type == Primitive::kPrimDouble) { |
| 151 | return LocationFrom(d0); |
| 152 | } else if (return_type == Primitive::kPrimLong) { |
| 153 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 154 | } else if (return_type == Primitive::kPrimVoid) { |
| 155 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 156 | } else { |
| 157 | return LocationFrom(w0); |
| 158 | } |
| 159 | } |
| 160 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 161 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 162 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 165 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 166 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 167 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 168 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 169 | // Calculate memory accessing operand for save/restore live registers. |
| 170 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 171 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 172 | int64_t spill_offset, |
| 173 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 174 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 175 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 176 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 177 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 179 | codegen->GetNumberOfFloatingPointRegisters())); |
| 180 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 181 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 182 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 183 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 184 | |
| 185 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 186 | UseScratchRegisterScope temps(masm); |
| 187 | |
| 188 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 189 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 190 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 191 | int64_t reg_size = kXRegSizeInBytes; |
| 192 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 193 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 194 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 195 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 196 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 197 | // to compute the base address(float point registers spill base address). |
| 198 | Register new_base = temps.AcquireSameSizeAs(base); |
| 199 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 200 | base = new_base; |
| 201 | spill_offset = -core_spill_size; |
| 202 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 203 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 204 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 205 | } |
| 206 | |
| 207 | if (is_save) { |
| 208 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 209 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 210 | } else { |
| 211 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 212 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 217 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 218 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 219 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 220 | // If the register holds an object, update the stack mask. |
| 221 | if (locations->RegisterContainsObject(i)) { |
| 222 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 223 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 224 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 225 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 226 | saved_core_stack_offsets_[i] = stack_offset; |
| 227 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 230 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 231 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 232 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 233 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 234 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 235 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 236 | } |
| 237 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 238 | SaveRestoreLiveRegistersHelper(codegen, |
| 239 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 240 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 241 | } |
| 242 | |
| 243 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 244 | SaveRestoreLiveRegistersHelper(codegen, |
| 245 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 246 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 247 | } |
| 248 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 250 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 251 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 254 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 255 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 256 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 257 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 258 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 259 | // Live registers will be restored in the catch block if caught. |
| 260 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 261 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 262 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 263 | // move resolver. |
| 264 | InvokeRuntimeCallingConvention calling_convention; |
| 265 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 266 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 267 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 268 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 269 | ? kQuickThrowStringBounds |
| 270 | : kQuickThrowArrayBounds; |
| 271 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 272 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 273 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 276 | bool IsFatal() const OVERRIDE { return true; } |
| 277 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 278 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 279 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 280 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 282 | }; |
| 283 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 285 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 286 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | |
| 288 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 289 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 290 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 291 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 292 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 295 | bool IsFatal() const OVERRIDE { return true; } |
| 296 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 297 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 298 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 301 | }; |
| 302 | |
| 303 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 304 | public: |
| 305 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 306 | HInstruction* at, |
| 307 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 308 | bool do_clinit, |
| 309 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 310 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 311 | : SlowPathCodeARM64(at), |
| 312 | cls_(cls), |
| 313 | dex_pc_(dex_pc), |
| 314 | do_clinit_(do_clinit), |
| 315 | bss_entry_temp_(bss_entry_temp), |
| 316 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 317 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 318 | } |
| 319 | |
| 320 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 321 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 322 | Location out = locations->Out(); |
| 323 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 324 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 325 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 326 | InvokeRuntimeCallingConvention calling_convention; |
| 327 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 328 | // register, make sure it's not clobbered by the call or by saving/restoring registers. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 329 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 330 | bool is_load_class_bss_entry = |
| 331 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 332 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 333 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 334 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 335 | DCHECK( |
| 336 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 339 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 340 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 341 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 342 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 343 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 344 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 345 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 346 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 347 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 348 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 349 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 350 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 351 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 352 | |
| 353 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | if (out.IsValid()) { |
| 355 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 356 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 357 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 359 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 360 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 361 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 362 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 363 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 364 | if (call_saves_everything_except_r0_ip0) { |
| 365 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 366 | } else { |
| 367 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 368 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 369 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 370 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 371 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 372 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 373 | { |
| 374 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 375 | __ Bind(strp_label); |
| 376 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 377 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 380 | __ B(GetExitLabel()); |
| 381 | } |
| 382 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 383 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 384 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 385 | private: |
| 386 | // The class this slow path will load. |
| 387 | HLoadClass* const cls_; |
| 388 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 389 | // The dex PC of `at_`. |
| 390 | const uint32_t dex_pc_; |
| 391 | |
| 392 | // Whether to initialize the class. |
| 393 | const bool do_clinit_; |
| 394 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 395 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 396 | vixl::aarch64::Register bss_entry_temp_; |
| 397 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 398 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 400 | }; |
| 401 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 402 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 403 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 404 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 405 | : SlowPathCodeARM64(instruction), |
| 406 | temp_(temp), |
| 407 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 408 | |
| 409 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 410 | LocationSummary* locations = instruction_->GetLocations(); |
| 411 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 412 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 413 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 414 | InvokeRuntimeCallingConvention calling_convention; |
| 415 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 416 | DCHECK(temp_.IsValid()); |
| 417 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 418 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 419 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 420 | __ Bind(GetEntryLabel()); |
| 421 | SaveLiveRegisters(codegen, locations); |
| 422 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 423 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 424 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 425 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 426 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 427 | Primitive::Type type = instruction_->GetType(); |
| 428 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 429 | |
| 430 | RestoreLiveRegisters(codegen, locations); |
| 431 | |
| 432 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 433 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 434 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 435 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 436 | } else { |
| 437 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 438 | adrp_label_ = arm64_codegen->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 439 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 440 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 441 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 442 | arm64_codegen->NewStringBssEntryPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 443 | { |
| 444 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 445 | __ Bind(strp_label); |
| 446 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 447 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | __ B(GetExitLabel()); |
| 451 | } |
| 452 | |
| 453 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 454 | |
| 455 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 456 | const Register temp_; |
| 457 | vixl::aarch64::Label* adrp_label_; |
| 458 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 459 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 460 | }; |
| 461 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 462 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 463 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 464 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 465 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 466 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 467 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 468 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 469 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 470 | // Live registers will be restored in the catch block if caught. |
| 471 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 472 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 473 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 474 | instruction_, |
| 475 | instruction_->GetDexPc(), |
| 476 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 477 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 478 | } |
| 479 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 480 | bool IsFatal() const OVERRIDE { return true; } |
| 481 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 482 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 483 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 484 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 486 | }; |
| 487 | |
| 488 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 489 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 490 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 491 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 492 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 493 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 494 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 495 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 496 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 497 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 499 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 500 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 501 | if (successor_ == nullptr) { |
| 502 | __ B(GetReturnLabel()); |
| 503 | } else { |
| 504 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 505 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 508 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 509 | DCHECK(successor_ == nullptr); |
| 510 | return &return_label_; |
| 511 | } |
| 512 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 513 | HBasicBlock* GetSuccessor() const { |
| 514 | return successor_; |
| 515 | } |
| 516 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 517 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 518 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 519 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 520 | // If not null, the block to branch to after the suspend check. |
| 521 | HBasicBlock* const successor_; |
| 522 | |
| 523 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 524 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 525 | |
| 526 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 527 | }; |
| 528 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 529 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 530 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 531 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 532 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 533 | |
| 534 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 535 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 536 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 537 | DCHECK(instruction_->IsCheckCast() |
| 538 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 539 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 540 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 542 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 543 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 544 | if (!is_fatal_) { |
| 545 | SaveLiveRegisters(codegen, locations); |
| 546 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 547 | |
| 548 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 549 | // move resolver. |
| 550 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 551 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 552 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 553 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 554 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 555 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 556 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 557 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 558 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 559 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 560 | Primitive::Type ret_type = instruction_->GetType(); |
| 561 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 562 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 563 | } else { |
| 564 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 565 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 566 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 569 | if (!is_fatal_) { |
| 570 | RestoreLiveRegisters(codegen, locations); |
| 571 | __ B(GetExitLabel()); |
| 572 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 575 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 576 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 577 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 578 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 579 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 580 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 581 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 582 | }; |
| 583 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 584 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 585 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 586 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 587 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 588 | |
| 589 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 590 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 591 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 592 | LocationSummary* locations = instruction_->GetLocations(); |
| 593 | SaveLiveRegisters(codegen, locations); |
| 594 | InvokeRuntimeCallingConvention calling_convention; |
| 595 | __ Mov(calling_convention.GetRegisterAt(0), |
| 596 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 597 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 598 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 601 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 602 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 603 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 604 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 605 | }; |
| 606 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 607 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 608 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 609 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 610 | |
| 611 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 612 | LocationSummary* locations = instruction_->GetLocations(); |
| 613 | __ Bind(GetEntryLabel()); |
| 614 | SaveLiveRegisters(codegen, locations); |
| 615 | |
| 616 | InvokeRuntimeCallingConvention calling_convention; |
| 617 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 618 | parallel_move.AddMove( |
| 619 | locations->InAt(0), |
| 620 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 621 | Primitive::kPrimNot, |
| 622 | nullptr); |
| 623 | parallel_move.AddMove( |
| 624 | locations->InAt(1), |
| 625 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 626 | Primitive::kPrimInt, |
| 627 | nullptr); |
| 628 | parallel_move.AddMove( |
| 629 | locations->InAt(2), |
| 630 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 631 | Primitive::kPrimNot, |
| 632 | nullptr); |
| 633 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 634 | |
| 635 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 636 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 637 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 638 | RestoreLiveRegisters(codegen, locations); |
| 639 | __ B(GetExitLabel()); |
| 640 | } |
| 641 | |
| 642 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 643 | |
| 644 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 645 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 646 | }; |
| 647 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 648 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 649 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 650 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 651 | |
| 652 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 653 | // underlying code buffer and we have generated the jump table with right size. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 654 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 655 | num_entries * sizeof(int32_t), |
| 656 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 657 | |
| 658 | __ Bind(&table_start_); |
| 659 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 660 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 661 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 662 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 663 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 664 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 665 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 666 | Literal<int32_t> literal(jump_offset); |
| 667 | __ place(&literal); |
| 668 | } |
| 669 | } |
| 670 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 671 | // Abstract base class for read barrier slow paths marking a reference |
| 672 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 673 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 674 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 675 | // barrier marking runtime entry point to be invoked or an empty |
| 676 | // location; in the latter case, the read barrier marking runtime |
| 677 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 678 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 679 | protected: |
| 680 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 681 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 682 | DCHECK(kEmitCompilerReadBarrier); |
| 683 | } |
| 684 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 685 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 686 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 687 | // Generate assembly code calling the read barrier marking runtime |
| 688 | // entry point (ReadBarrierMarkRegX). |
| 689 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 690 | // No need to save live registers; it's taken care of by the |
| 691 | // entrypoint. Also, there is no need to update the stack mask, |
| 692 | // as this runtime call will not trigger a garbage collection. |
| 693 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 694 | DCHECK_NE(ref_.reg(), LR); |
| 695 | DCHECK_NE(ref_.reg(), WSP); |
| 696 | DCHECK_NE(ref_.reg(), WZR); |
| 697 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 698 | // as a temporary, it cannot be the entry point's input/output. |
| 699 | DCHECK_NE(ref_.reg(), IP0); |
| 700 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 701 | // "Compact" slow path, saving two moves. |
| 702 | // |
| 703 | // Instead of using the standard runtime calling convention (input |
| 704 | // and output in W0): |
| 705 | // |
| 706 | // W0 <- ref |
| 707 | // W0 <- ReadBarrierMark(W0) |
| 708 | // ref <- W0 |
| 709 | // |
| 710 | // we just use rX (the register containing `ref`) as input and output |
| 711 | // of a dedicated entrypoint: |
| 712 | // |
| 713 | // rX <- ReadBarrierMarkRegX(rX) |
| 714 | // |
| 715 | if (entrypoint_.IsValid()) { |
| 716 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 717 | __ Blr(XRegisterFrom(entrypoint_)); |
| 718 | } else { |
| 719 | // Entrypoint is not already loaded, load from the thread. |
| 720 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 721 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 722 | // This runtime call does not require a stack map. |
| 723 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | // The location (register) of the marked object reference. |
| 728 | const Location ref_; |
| 729 | |
| 730 | // The location of the entrypoint if it is already loaded. |
| 731 | const Location entrypoint_; |
| 732 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 733 | private: |
| 734 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 735 | }; |
| 736 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 737 | // Slow path marking an object reference `ref` during a read |
| 738 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 739 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 740 | // |
| 741 | // This means that after the execution of this slow path, `ref` will |
| 742 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 743 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 744 | // probably still be a from-space reference (unless it gets updated by |
| 745 | // another thread, or if another thread installed another object |
| 746 | // reference (different from `ref`) in `obj.field`). |
| 747 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 748 | // Argument `entrypoint` must be a register location holding the read |
| 749 | // barrier marking runtime entry point to be invoked or an empty |
| 750 | // location; in the latter case, the read barrier marking runtime |
| 751 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 752 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 753 | public: |
| 754 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 755 | Location ref, |
| 756 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 757 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 758 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 762 | |
| 763 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 764 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 765 | DCHECK(locations->CanCall()); |
| 766 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 767 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 768 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 769 | << "Unexpected instruction in read barrier marking slow path: " |
| 770 | << instruction_->DebugName(); |
| 771 | |
| 772 | __ Bind(GetEntryLabel()); |
| 773 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 774 | __ B(GetExitLabel()); |
| 775 | } |
| 776 | |
| 777 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 778 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 779 | }; |
| 780 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 781 | // Slow path loading `obj`'s lock word, loading a reference from |
| 782 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 783 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 784 | // read barrier). The field `obj.field` in the object `obj` holding |
| 785 | // this reference does not get updated by this slow path after marking |
| 786 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 787 | // below for that). |
| 788 | // |
| 789 | // This means that after the execution of this slow path, `ref` will |
| 790 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 791 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 792 | // probably still be a from-space reference (unless it gets updated by |
| 793 | // another thread, or if another thread installed another object |
| 794 | // reference (different from `ref`) in `obj.field`). |
| 795 | // |
| 796 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 797 | // barrier marking runtime entry point to be invoked or an empty |
| 798 | // location; in the latter case, the read barrier marking runtime |
| 799 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 800 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 801 | public: |
| 802 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 803 | Location ref, |
| 804 | Register obj, |
| 805 | uint32_t offset, |
| 806 | Location index, |
| 807 | size_t scale_factor, |
| 808 | bool needs_null_check, |
| 809 | bool use_load_acquire, |
| 810 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 811 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 812 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 813 | obj_(obj), |
| 814 | offset_(offset), |
| 815 | index_(index), |
| 816 | scale_factor_(scale_factor), |
| 817 | needs_null_check_(needs_null_check), |
| 818 | use_load_acquire_(use_load_acquire), |
| 819 | temp_(temp) { |
| 820 | DCHECK(kEmitCompilerReadBarrier); |
| 821 | DCHECK(kUseBakerReadBarrier); |
| 822 | } |
| 823 | |
| 824 | const char* GetDescription() const OVERRIDE { |
| 825 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 826 | } |
| 827 | |
| 828 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 829 | LocationSummary* locations = instruction_->GetLocations(); |
| 830 | DCHECK(locations->CanCall()); |
| 831 | DCHECK(ref_.IsRegister()) << ref_; |
| 832 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 833 | DCHECK(obj_.IsW()); |
| 834 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 835 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 836 | instruction_->IsStaticFieldGet() || |
| 837 | instruction_->IsArrayGet() || |
| 838 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 839 | instruction_->IsInstanceOf() || |
| 840 | instruction_->IsCheckCast() || |
| 841 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 842 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 843 | << "Unexpected instruction in read barrier marking slow path: " |
| 844 | << instruction_->DebugName(); |
| 845 | // The read barrier instrumentation of object ArrayGet |
| 846 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 847 | // instruction. |
| 848 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 849 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 850 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 851 | // Temporary register `temp_`, used to store the lock word, must |
| 852 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 853 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 854 | // need the lock word to still be in `temp_` after the reference |
| 855 | // load. |
| 856 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 857 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 858 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 859 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 860 | |
| 861 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 862 | // inserted after the original load. However, in fast path based |
| 863 | // Baker's read barriers, we need to perform the load of |
| 864 | // mirror::Object::monitor_ *before* the original reference load. |
| 865 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 866 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 867 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 868 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 869 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 870 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 871 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 872 | // if (is_gray) { |
| 873 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 874 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 875 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 876 | // Note: the original implementation in ReadBarrier::Barrier is |
| 877 | // slightly more complex as it performs additional checks that we do |
| 878 | // not do here for performance reasons. |
| 879 | |
| 880 | // /* int32_t */ monitor = obj->monitor_ |
| 881 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 882 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 883 | if (needs_null_check_) { |
| 884 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 885 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 886 | // /* LockWord */ lock_word = LockWord(monitor) |
| 887 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 888 | "art::LockWord and int32_t have different sizes."); |
| 889 | |
| 890 | // Introduce a dependency on the lock_word including rb_state, |
| 891 | // to prevent load-load reordering, and without using |
| 892 | // a memory barrier (which would be more expensive). |
| 893 | // `obj` is unchanged by this operation, but its value now depends |
| 894 | // on `temp`. |
| 895 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 896 | |
| 897 | // The actual reference load. |
| 898 | // A possible implicit null check has already been handled above. |
| 899 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 900 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 901 | ref_, |
| 902 | obj_, |
| 903 | offset_, |
| 904 | index_, |
| 905 | scale_factor_, |
| 906 | /* needs_null_check */ false, |
| 907 | use_load_acquire_); |
| 908 | |
| 909 | // Mark the object `ref` when `obj` is gray. |
| 910 | // |
| 911 | // if (rb_state == ReadBarrier::GrayState()) |
| 912 | // ref = ReadBarrier::Mark(ref); |
| 913 | // |
| 914 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 915 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 916 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 917 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 918 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 919 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 920 | __ B(GetExitLabel()); |
| 921 | } |
| 922 | |
| 923 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 924 | // The register containing the object holding the marked object reference field. |
| 925 | Register obj_; |
| 926 | // The offset, index and scale factor to access the reference in `obj_`. |
| 927 | uint32_t offset_; |
| 928 | Location index_; |
| 929 | size_t scale_factor_; |
| 930 | // Is a null check required? |
| 931 | bool needs_null_check_; |
| 932 | // Should this reference load use Load-Acquire semantics? |
| 933 | bool use_load_acquire_; |
| 934 | // A temporary register used to hold the lock word of `obj_`. |
| 935 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 936 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 937 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 938 | }; |
| 939 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | // Slow path loading `obj`'s lock word, loading a reference from |
| 941 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 942 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 943 | // read barrier). If needed, this slow path also atomically updates |
| 944 | // the field `obj.field` in the object `obj` holding this reference |
| 945 | // after marking (contrary to |
| 946 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 947 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 948 | // |
| 949 | // This means that after the execution of this slow path, both `ref` |
| 950 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 951 | // hold the same to-space reference (unless another thread installed |
| 952 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 953 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 954 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 955 | // barrier marking runtime entry point to be invoked or an empty |
| 956 | // location; in the latter case, the read barrier marking runtime |
| 957 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 958 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 959 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 960 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 961 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 962 | HInstruction* instruction, |
| 963 | Location ref, |
| 964 | Register obj, |
| 965 | uint32_t offset, |
| 966 | Location index, |
| 967 | size_t scale_factor, |
| 968 | bool needs_null_check, |
| 969 | bool use_load_acquire, |
| 970 | Register temp, |
| 971 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 972 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 973 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 974 | offset_(offset), |
| 975 | index_(index), |
| 976 | scale_factor_(scale_factor), |
| 977 | needs_null_check_(needs_null_check), |
| 978 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 979 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 980 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 981 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 985 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 989 | LocationSummary* locations = instruction_->GetLocations(); |
| 990 | Register ref_reg = WRegisterFrom(ref_); |
| 991 | DCHECK(locations->CanCall()); |
| 992 | DCHECK(ref_.IsRegister()) << ref_; |
| 993 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 994 | DCHECK(obj_.IsW()); |
| 995 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 996 | |
| 997 | // 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] | 998 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 999 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1000 | << instruction_->DebugName(); |
| 1001 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1002 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1003 | DCHECK_EQ(offset_, 0u); |
| 1004 | DCHECK_EQ(scale_factor_, 0u); |
| 1005 | DCHECK_EQ(use_load_acquire_, false); |
| 1006 | // The location of the offset of the marked reference field within `obj_`. |
| 1007 | Location field_offset = index_; |
| 1008 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 1009 | |
| 1010 | // Temporary register `temp_`, used to store the lock word, must |
| 1011 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1012 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1013 | // need the lock word to still be in `temp_` after the reference |
| 1014 | // load. |
| 1015 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1016 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1017 | |
| 1018 | __ Bind(GetEntryLabel()); |
| 1019 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1020 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1021 | // |
| 1022 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1023 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1024 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1025 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1026 | // if (is_gray) { |
| 1027 | // old_ref = ref; |
| 1028 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1029 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1030 | // } |
| 1031 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1032 | // /* int32_t */ monitor = obj->monitor_ |
| 1033 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1034 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1035 | if (needs_null_check_) { |
| 1036 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1037 | } |
| 1038 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1039 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1040 | "art::LockWord and int32_t have different sizes."); |
| 1041 | |
| 1042 | // Introduce a dependency on the lock_word including rb_state, |
| 1043 | // to prevent load-load reordering, and without using |
| 1044 | // a memory barrier (which would be more expensive). |
| 1045 | // `obj` is unchanged by this operation, but its value now depends |
| 1046 | // on `temp`. |
| 1047 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1048 | |
| 1049 | // The actual reference load. |
| 1050 | // A possible implicit null check has already been handled above. |
| 1051 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1052 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1053 | ref_, |
| 1054 | obj_, |
| 1055 | offset_, |
| 1056 | index_, |
| 1057 | scale_factor_, |
| 1058 | /* needs_null_check */ false, |
| 1059 | use_load_acquire_); |
| 1060 | |
| 1061 | // Mark the object `ref` when `obj` is gray. |
| 1062 | // |
| 1063 | // if (rb_state == ReadBarrier::GrayState()) |
| 1064 | // ref = ReadBarrier::Mark(ref); |
| 1065 | // |
| 1066 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1067 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1068 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1069 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1070 | |
| 1071 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1072 | // Note that we cannot use IP to save the old reference, as IP is |
| 1073 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1074 | // need the old reference after the call to that entry point. |
| 1075 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1076 | __ Mov(temp_.W(), ref_reg); |
| 1077 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1078 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1079 | |
| 1080 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1081 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1082 | // |
| 1083 | // Note that this field could also hold a different object, if |
| 1084 | // another thread had concurrently changed it. In that case, the |
| 1085 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1086 | // (CAS) operation below would abort the CAS, leaving the field |
| 1087 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1088 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1089 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1090 | |
| 1091 | // Update the the holder's field atomically. This may fail if |
| 1092 | // mutator updates before us, but it's OK. This is achieved |
| 1093 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1094 | // memory synchronization ordering, where the expected value is |
| 1095 | // the old reference and the desired value is the new reference. |
| 1096 | |
| 1097 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1098 | UseScratchRegisterScope temps(masm); |
| 1099 | |
| 1100 | // Convenience aliases. |
| 1101 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1102 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1103 | Register expected = temp_.W(); |
| 1104 | Register value = ref_reg; |
| 1105 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1106 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1107 | |
| 1108 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1109 | |
| 1110 | if (kPoisonHeapReferences) { |
| 1111 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1112 | if (value.Is(expected)) { |
| 1113 | // Do not poison `value`, as it is the same register as |
| 1114 | // `expected`, which has just been poisoned. |
| 1115 | } else { |
| 1116 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | // do { |
| 1121 | // tmp_value = [tmp_ptr] - expected; |
| 1122 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1123 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1124 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1125 | __ Bind(&loop_head); |
| 1126 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1127 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1128 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1129 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1130 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1131 | __ B(&exit_loop); |
| 1132 | __ Bind(&comparison_failed); |
| 1133 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1134 | __ Bind(&exit_loop); |
| 1135 | |
| 1136 | if (kPoisonHeapReferences) { |
| 1137 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1138 | if (value.Is(expected)) { |
| 1139 | // Do not unpoison `value`, as it is the same register as |
| 1140 | // `expected`, which has just been unpoisoned. |
| 1141 | } else { |
| 1142 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1143 | } |
| 1144 | } |
| 1145 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1146 | __ B(GetExitLabel()); |
| 1147 | } |
| 1148 | |
| 1149 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1150 | // The register containing the object holding the marked object reference field. |
| 1151 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1152 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1153 | uint32_t offset_; |
| 1154 | Location index_; |
| 1155 | size_t scale_factor_; |
| 1156 | // Is a null check required? |
| 1157 | bool needs_null_check_; |
| 1158 | // Should this reference load use Load-Acquire semantics? |
| 1159 | bool use_load_acquire_; |
| 1160 | // A temporary register used to hold the lock word of `obj_`; and |
| 1161 | // also to hold the original reference value, when the reference is |
| 1162 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1163 | const Register temp_; |
| 1164 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1165 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1166 | }; |
| 1167 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1168 | // Slow path generating a read barrier for a heap reference. |
| 1169 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1170 | public: |
| 1171 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1172 | Location out, |
| 1173 | Location ref, |
| 1174 | Location obj, |
| 1175 | uint32_t offset, |
| 1176 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1177 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1178 | out_(out), |
| 1179 | ref_(ref), |
| 1180 | obj_(obj), |
| 1181 | offset_(offset), |
| 1182 | index_(index) { |
| 1183 | DCHECK(kEmitCompilerReadBarrier); |
| 1184 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1185 | // has been overwritten by (or after) the heap object reference load |
| 1186 | // to be instrumented, e.g.: |
| 1187 | // |
| 1188 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1189 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1190 | // |
| 1191 | // In that case, we have lost the information about the original |
| 1192 | // object, and the emitted read barrier cannot work properly. |
| 1193 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1194 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1195 | } |
| 1196 | |
| 1197 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1198 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1199 | LocationSummary* locations = instruction_->GetLocations(); |
| 1200 | Primitive::Type type = Primitive::kPrimNot; |
| 1201 | DCHECK(locations->CanCall()); |
| 1202 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1203 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1204 | instruction_->IsStaticFieldGet() || |
| 1205 | instruction_->IsArrayGet() || |
| 1206 | instruction_->IsInstanceOf() || |
| 1207 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1208 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1209 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1210 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1211 | // The read barrier instrumentation of object ArrayGet |
| 1212 | // instructions does not support the HIntermediateAddress |
| 1213 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1214 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1215 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1216 | |
| 1217 | __ Bind(GetEntryLabel()); |
| 1218 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1219 | SaveLiveRegisters(codegen, locations); |
| 1220 | |
| 1221 | // We may have to change the index's value, but as `index_` is a |
| 1222 | // constant member (like other "inputs" of this slow path), |
| 1223 | // introduce a copy of it, `index`. |
| 1224 | Location index = index_; |
| 1225 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1226 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1227 | if (instruction_->IsArrayGet()) { |
| 1228 | // Compute the actual memory offset and store it in `index`. |
| 1229 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1230 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1231 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1232 | // We are about to change the value of `index_reg` (see the |
| 1233 | // calls to vixl::MacroAssembler::Lsl and |
| 1234 | // vixl::MacroAssembler::Mov below), but it has |
| 1235 | // not been saved by the previous call to |
| 1236 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1237 | // callee-save register -- |
| 1238 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1239 | // callee-save registers, as it has been designed with the |
| 1240 | // assumption that callee-save registers are supposed to be |
| 1241 | // handled by the called function. So, as a callee-save |
| 1242 | // register, `index_reg` _would_ eventually be saved onto |
| 1243 | // the stack, but it would be too late: we would have |
| 1244 | // changed its value earlier. Therefore, we manually save |
| 1245 | // it here into another freely available register, |
| 1246 | // `free_reg`, chosen of course among the caller-save |
| 1247 | // registers (as a callee-save `free_reg` register would |
| 1248 | // exhibit the same problem). |
| 1249 | // |
| 1250 | // Note we could have requested a temporary register from |
| 1251 | // the register allocator instead; but we prefer not to, as |
| 1252 | // this is a slow path, and we know we can find a |
| 1253 | // caller-save register that is available. |
| 1254 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1255 | __ Mov(free_reg.W(), index_reg); |
| 1256 | index_reg = free_reg; |
| 1257 | index = LocationFrom(index_reg); |
| 1258 | } else { |
| 1259 | // The initial register stored in `index_` has already been |
| 1260 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1261 | // (as it is not a callee-save register), so we can freely |
| 1262 | // use it. |
| 1263 | } |
| 1264 | // Shifting the index value contained in `index_reg` by the scale |
| 1265 | // factor (2) cannot overflow in practice, as the runtime is |
| 1266 | // unable to allocate object arrays with a size larger than |
| 1267 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1268 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1269 | static_assert( |
| 1270 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1271 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1272 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1273 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1274 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1275 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1276 | // (as in the case of ArrayGet), as it is actually an offset |
| 1277 | // to an object field within an object. |
| 1278 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1279 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1280 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1281 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1282 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1283 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1284 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | // We're moving two or three locations to locations that could |
| 1289 | // overlap, so we need a parallel move resolver. |
| 1290 | InvokeRuntimeCallingConvention calling_convention; |
| 1291 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1292 | parallel_move.AddMove(ref_, |
| 1293 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1294 | type, |
| 1295 | nullptr); |
| 1296 | parallel_move.AddMove(obj_, |
| 1297 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1298 | type, |
| 1299 | nullptr); |
| 1300 | if (index.IsValid()) { |
| 1301 | parallel_move.AddMove(index, |
| 1302 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1303 | Primitive::kPrimInt, |
| 1304 | nullptr); |
| 1305 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1306 | } else { |
| 1307 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1308 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1309 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1310 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1311 | instruction_, |
| 1312 | instruction_->GetDexPc(), |
| 1313 | this); |
| 1314 | CheckEntrypointTypes< |
| 1315 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1316 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1317 | |
| 1318 | RestoreLiveRegisters(codegen, locations); |
| 1319 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1320 | __ B(GetExitLabel()); |
| 1321 | } |
| 1322 | |
| 1323 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1324 | |
| 1325 | private: |
| 1326 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1327 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1328 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1329 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1330 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1331 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1332 | } |
| 1333 | } |
| 1334 | // We shall never fail to find a free caller-save register, as |
| 1335 | // there are more than two core caller-save registers on ARM64 |
| 1336 | // (meaning it is possible to find one which is different from |
| 1337 | // `ref` and `obj`). |
| 1338 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1339 | LOG(FATAL) << "Could not find a free register"; |
| 1340 | UNREACHABLE(); |
| 1341 | } |
| 1342 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1343 | const Location out_; |
| 1344 | const Location ref_; |
| 1345 | const Location obj_; |
| 1346 | const uint32_t offset_; |
| 1347 | // An additional location containing an index to an array. |
| 1348 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1349 | // UnsafeGetObjectVolatile intrinsics. |
| 1350 | const Location index_; |
| 1351 | |
| 1352 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1353 | }; |
| 1354 | |
| 1355 | // Slow path generating a read barrier for a GC root. |
| 1356 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1357 | public: |
| 1358 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1359 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1360 | DCHECK(kEmitCompilerReadBarrier); |
| 1361 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1362 | |
| 1363 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1364 | LocationSummary* locations = instruction_->GetLocations(); |
| 1365 | Primitive::Type type = Primitive::kPrimNot; |
| 1366 | DCHECK(locations->CanCall()); |
| 1367 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1368 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1369 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1370 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1371 | |
| 1372 | __ Bind(GetEntryLabel()); |
| 1373 | SaveLiveRegisters(codegen, locations); |
| 1374 | |
| 1375 | InvokeRuntimeCallingConvention calling_convention; |
| 1376 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1377 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1378 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1379 | // thus we need a 64-bit move here, and we cannot use |
| 1380 | // |
| 1381 | // arm64_codegen->MoveLocation( |
| 1382 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1383 | // root_, |
| 1384 | // type); |
| 1385 | // |
| 1386 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1387 | // reference type (`Primitive::kPrimNot`). |
| 1388 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1389 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1390 | instruction_, |
| 1391 | instruction_->GetDexPc(), |
| 1392 | this); |
| 1393 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1394 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1395 | |
| 1396 | RestoreLiveRegisters(codegen, locations); |
| 1397 | __ B(GetExitLabel()); |
| 1398 | } |
| 1399 | |
| 1400 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1401 | |
| 1402 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1403 | const Location out_; |
| 1404 | const Location root_; |
| 1405 | |
| 1406 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1407 | }; |
| 1408 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1409 | #undef __ |
| 1410 | |
| 1411 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1412 | Location next_location; |
| 1413 | if (type == Primitive::kPrimVoid) { |
| 1414 | LOG(FATAL) << "Unreachable type " << type; |
| 1415 | } |
| 1416 | |
| 1417 | if (Primitive::IsFloatingPointType(type) && |
| 1418 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1419 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1420 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1421 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1422 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1423 | } else { |
| 1424 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1425 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1426 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1429 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1430 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1431 | return next_location; |
| 1432 | } |
| 1433 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1434 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1435 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1436 | } |
| 1437 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1438 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1439 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1440 | const CompilerOptions& compiler_options, |
| 1441 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1442 | : CodeGenerator(graph, |
| 1443 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1444 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1445 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1446 | callee_saved_core_registers.GetList(), |
| 1447 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1448 | compiler_options, |
| 1449 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1450 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1451 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1452 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1453 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1454 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1455 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1456 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1457 | uint32_literals_(std::less<uint32_t>(), |
| 1458 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1459 | uint64_literals_(std::less<uint64_t>(), |
| 1460 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1461 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1462 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1463 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1464 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1465 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 1466 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1467 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1468 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1469 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1470 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1471 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1472 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1473 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1474 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1475 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1476 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1477 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1478 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1479 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1480 | jump_table->EmitTable(this); |
| 1481 | } |
| 1482 | } |
| 1483 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1484 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1485 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1486 | // Ensure we emit the literal pool. |
| 1487 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1488 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1489 | CodeGenerator::Finalize(allocator); |
| 1490 | } |
| 1491 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1492 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1493 | // Note: There are 6 kinds of moves: |
| 1494 | // 1. constant -> GPR/FPR (non-cycle) |
| 1495 | // 2. constant -> stack (non-cycle) |
| 1496 | // 3. GPR/FPR -> GPR/FPR |
| 1497 | // 4. GPR/FPR -> stack |
| 1498 | // 5. stack -> GPR/FPR |
| 1499 | // 6. stack -> stack (non-cycle) |
| 1500 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1501 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1502 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1503 | // dependency. |
| 1504 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1505 | } |
| 1506 | |
| 1507 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1508 | vixl_temps_.Close(); |
| 1509 | } |
| 1510 | |
| 1511 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1512 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1513 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1514 | || kind == Location::kSIMDStackSlot); |
| 1515 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1516 | ? Location::kFpuRegister |
| 1517 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1518 | Location scratch = GetScratchLocation(kind); |
| 1519 | if (!scratch.Equals(Location::NoLocation())) { |
| 1520 | return scratch; |
| 1521 | } |
| 1522 | // Allocate from VIXL temp registers. |
| 1523 | if (kind == Location::kRegister) { |
| 1524 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1525 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1526 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1527 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1528 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1529 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1530 | } |
| 1531 | AddScratchLocation(scratch); |
| 1532 | return scratch; |
| 1533 | } |
| 1534 | |
| 1535 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1536 | if (loc.IsRegister()) { |
| 1537 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1538 | } else { |
| 1539 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1540 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1541 | } |
| 1542 | RemoveScratchLocation(loc); |
| 1543 | } |
| 1544 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1545 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1546 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1547 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1550 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1551 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1552 | __ Bind(&frame_entry_label_); |
| 1553 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1554 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1555 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1556 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1557 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1558 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1559 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1560 | { |
| 1561 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1562 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1563 | kInstructionSize, |
| 1564 | CodeBufferCheckScope::kExactSize); |
| 1565 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1566 | RecordPcInfo(nullptr, 0); |
| 1567 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1568 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1569 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1570 | if (!HasEmptyFrame()) { |
| 1571 | int frame_size = GetFrameSize(); |
| 1572 | // Stack layout: |
| 1573 | // sp[frame_size - 8] : lr. |
| 1574 | // ... : other preserved core registers. |
| 1575 | // ... : other preserved fp registers. |
| 1576 | // ... : reserved frame space. |
| 1577 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1578 | |
| 1579 | // Save the current method if we need it. Note that we do not |
| 1580 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1581 | // in the SSA graph. |
| 1582 | if (RequiresCurrentMethod()) { |
| 1583 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1584 | } else { |
| 1585 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1586 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1587 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1588 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1589 | frame_size - GetCoreSpillSize()); |
| 1590 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1591 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1592 | |
| 1593 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1594 | // Initialize should_deoptimize flag to 0. |
| 1595 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1596 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1597 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1598 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1599 | |
| 1600 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1604 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1605 | if (!HasEmptyFrame()) { |
| 1606 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1607 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1608 | frame_size - FrameEntrySpillSize()); |
| 1609 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1610 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1611 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1612 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1613 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1614 | __ Ret(); |
| 1615 | GetAssembler()->cfi().RestoreState(); |
| 1616 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1619 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1620 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1621 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1622 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1623 | } |
| 1624 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1625 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1626 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1627 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1628 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1629 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1630 | } |
| 1631 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1632 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1633 | __ Bind(GetLabelOf(block)); |
| 1634 | } |
| 1635 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1636 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1637 | DCHECK(location.IsRegister()); |
| 1638 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1639 | } |
| 1640 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1641 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1642 | if (location.IsRegister()) { |
| 1643 | locations->AddTemp(location); |
| 1644 | } else { |
| 1645 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1646 | } |
| 1647 | } |
| 1648 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1649 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1650 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1651 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1652 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1653 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1654 | if (value_can_be_null) { |
| 1655 | __ Cbz(value, &done); |
| 1656 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1657 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1658 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1659 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1660 | if (value_can_be_null) { |
| 1661 | __ Bind(&done); |
| 1662 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1663 | } |
| 1664 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1665 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1666 | // Blocked core registers: |
| 1667 | // lr : Runtime reserved. |
| 1668 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1669 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1670 | // ip1 : VIXL core temp. |
| 1671 | // ip0 : VIXL core temp. |
| 1672 | // |
| 1673 | // Blocked fp registers: |
| 1674 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1675 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1676 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1677 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1678 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1679 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1680 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1681 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1682 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1683 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1684 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1685 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1686 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1687 | // Stubs do not save callee-save floating point registers. If the graph |
| 1688 | // is debuggable, we need to deal with these registers differently. For |
| 1689 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1690 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1691 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1692 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1693 | } |
| 1694 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1697 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1698 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1699 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1700 | return kArm64WordSize; |
| 1701 | } |
| 1702 | |
| 1703 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1704 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1705 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1706 | return kArm64WordSize; |
| 1707 | } |
| 1708 | |
| 1709 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1710 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1711 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1712 | return kArm64WordSize; |
| 1713 | } |
| 1714 | |
| 1715 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1716 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1717 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1718 | return kArm64WordSize; |
| 1719 | } |
| 1720 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1721 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1722 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1726 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1727 | } |
| 1728 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1729 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1730 | if (constant->IsIntConstant()) { |
| 1731 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1732 | } else if (constant->IsLongConstant()) { |
| 1733 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1734 | } else if (constant->IsNullConstant()) { |
| 1735 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1736 | } else if (constant->IsFloatConstant()) { |
| 1737 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1738 | } else { |
| 1739 | DCHECK(constant->IsDoubleConstant()); |
| 1740 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1741 | } |
| 1742 | } |
| 1743 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1744 | |
| 1745 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1746 | DCHECK(constant.IsConstant()); |
| 1747 | HConstant* cst = constant.GetConstant(); |
| 1748 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1749 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1750 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1751 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1752 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1753 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1754 | } |
| 1755 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1756 | // Allocate a scratch register from the VIXL pool, querying first |
| 1757 | // the floating-point register pool, and then the core register |
| 1758 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1759 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1760 | // using a different allocation strategy. |
| 1761 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1762 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1763 | int size_in_bits) { |
| 1764 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1765 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1766 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1767 | } |
| 1768 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1769 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1770 | Location source, |
| 1771 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1772 | if (source.Equals(destination)) { |
| 1773 | return; |
| 1774 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1775 | |
| 1776 | // A valid move can always be inferred from the destination and source |
| 1777 | // locations. When moving from and to a register, the argument type can be |
| 1778 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1779 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1780 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1781 | |
| 1782 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1783 | if (unspecified_type) { |
| 1784 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1785 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1786 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1787 | || src_cst->IsFloatConstant() |
| 1788 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1789 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1790 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1791 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1792 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1793 | // type is appropriate. Else the source is a register, and since the |
| 1794 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1795 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1796 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1797 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1798 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1799 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1800 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1801 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1802 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1803 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1804 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1805 | } else if (source.IsSIMDStackSlot()) { |
| 1806 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1807 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1808 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1809 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1810 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1811 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1812 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1813 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1814 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1815 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1816 | ? Primitive::kPrimLong |
| 1817 | : Primitive::kPrimInt; |
| 1818 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1819 | } |
| 1820 | } else { |
| 1821 | DCHECK(source.IsFpuRegister()); |
| 1822 | if (destination.IsRegister()) { |
| 1823 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1824 | ? Primitive::kPrimDouble |
| 1825 | : Primitive::kPrimFloat; |
| 1826 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1827 | } else { |
| 1828 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1829 | if (GetGraph()->HasSIMD()) { |
| 1830 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1831 | } else { |
| 1832 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | } else if (destination.IsSIMDStackSlot()) { |
| 1837 | if (source.IsFpuRegister()) { |
| 1838 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1839 | } else { |
| 1840 | DCHECK(source.IsSIMDStackSlot()); |
| 1841 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1842 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1843 | Register temp = temps.AcquireX(); |
| 1844 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1845 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1846 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1847 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1848 | } else { |
| 1849 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1850 | __ Ldr(temp, StackOperandFrom(source)); |
| 1851 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1852 | } |
| 1853 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1854 | } else { // The destination is not a register. It must be a stack slot. |
| 1855 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1856 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1857 | if (unspecified_type) { |
| 1858 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1859 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1860 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1861 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1864 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1865 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1866 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1867 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1868 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1869 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1870 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1871 | HConstant* src_cst = source.GetConstant(); |
| 1872 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1873 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1874 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1875 | ? Register(xzr) |
| 1876 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1877 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1878 | if (src_cst->IsIntConstant()) { |
| 1879 | temp = temps.AcquireW(); |
| 1880 | } else if (src_cst->IsLongConstant()) { |
| 1881 | temp = temps.AcquireX(); |
| 1882 | } else if (src_cst->IsFloatConstant()) { |
| 1883 | temp = temps.AcquireS(); |
| 1884 | } else { |
| 1885 | DCHECK(src_cst->IsDoubleConstant()); |
| 1886 | temp = temps.AcquireD(); |
| 1887 | } |
| 1888 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1889 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1890 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1891 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1892 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1893 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1894 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1895 | // Use any scratch register (a core or a floating-point one) |
| 1896 | // from VIXL scratch register pools as a temporary. |
| 1897 | // |
| 1898 | // We used to only use the FP scratch register pool, but in some |
| 1899 | // rare cases the only register from this pool (D31) would |
| 1900 | // already be used (e.g. within a ParallelMove instruction, when |
| 1901 | // a move is blocked by a another move requiring a scratch FP |
| 1902 | // register, which would reserve D31). To prevent this issue, we |
| 1903 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1904 | // |
| 1905 | // 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] | 1906 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1907 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1908 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1909 | // allocates core scratch registers first. |
| 1910 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1911 | GetVIXLAssembler(), |
| 1912 | &temps, |
| 1913 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1914 | __ Ldr(temp, StackOperandFrom(source)); |
| 1915 | __ Str(temp, StackOperandFrom(destination)); |
| 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1921 | CPURegister dst, |
| 1922 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1923 | switch (type) { |
| 1924 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1925 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1926 | break; |
| 1927 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1928 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1931 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1932 | break; |
| 1933 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1934 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1935 | break; |
| 1936 | case Primitive::kPrimInt: |
| 1937 | case Primitive::kPrimNot: |
| 1938 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1939 | case Primitive::kPrimFloat: |
| 1940 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1941 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1942 | __ Ldr(dst, src); |
| 1943 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1944 | case Primitive::kPrimVoid: |
| 1945 | LOG(FATAL) << "Unreachable type " << type; |
| 1946 | } |
| 1947 | } |
| 1948 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1949 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1950 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1951 | const MemOperand& src, |
| 1952 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1953 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1954 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1955 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1956 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1957 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1958 | DCHECK(!src.IsPreIndex()); |
| 1959 | DCHECK(!src.IsPostIndex()); |
| 1960 | |
| 1961 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1962 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1963 | { |
| 1964 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1965 | MemOperand base = MemOperand(temp_base); |
| 1966 | switch (type) { |
| 1967 | case Primitive::kPrimBoolean: |
| 1968 | { |
| 1969 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1970 | __ ldarb(Register(dst), base); |
| 1971 | if (needs_null_check) { |
| 1972 | MaybeRecordImplicitNullCheck(instruction); |
| 1973 | } |
| 1974 | } |
| 1975 | break; |
| 1976 | case Primitive::kPrimByte: |
| 1977 | { |
| 1978 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1979 | __ ldarb(Register(dst), base); |
| 1980 | if (needs_null_check) { |
| 1981 | MaybeRecordImplicitNullCheck(instruction); |
| 1982 | } |
| 1983 | } |
| 1984 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1985 | break; |
| 1986 | case Primitive::kPrimChar: |
| 1987 | { |
| 1988 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1989 | __ ldarh(Register(dst), base); |
| 1990 | if (needs_null_check) { |
| 1991 | MaybeRecordImplicitNullCheck(instruction); |
| 1992 | } |
| 1993 | } |
| 1994 | break; |
| 1995 | case Primitive::kPrimShort: |
| 1996 | { |
| 1997 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1998 | __ ldarh(Register(dst), base); |
| 1999 | if (needs_null_check) { |
| 2000 | MaybeRecordImplicitNullCheck(instruction); |
| 2001 | } |
| 2002 | } |
| 2003 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 2004 | break; |
| 2005 | case Primitive::kPrimInt: |
| 2006 | case Primitive::kPrimNot: |
| 2007 | case Primitive::kPrimLong: |
| 2008 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 2009 | { |
| 2010 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2011 | __ ldar(Register(dst), base); |
| 2012 | if (needs_null_check) { |
| 2013 | MaybeRecordImplicitNullCheck(instruction); |
| 2014 | } |
| 2015 | } |
| 2016 | break; |
| 2017 | case Primitive::kPrimFloat: |
| 2018 | case Primitive::kPrimDouble: { |
| 2019 | DCHECK(dst.IsFPRegister()); |
| 2020 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2021 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2022 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2023 | { |
| 2024 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2025 | __ ldar(temp, base); |
| 2026 | if (needs_null_check) { |
| 2027 | MaybeRecordImplicitNullCheck(instruction); |
| 2028 | } |
| 2029 | } |
| 2030 | __ Fmov(FPRegister(dst), temp); |
| 2031 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2032 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2033 | case Primitive::kPrimVoid: |
| 2034 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2035 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2036 | } |
| 2037 | } |
| 2038 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2039 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2040 | CPURegister src, |
| 2041 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2042 | switch (type) { |
| 2043 | case Primitive::kPrimBoolean: |
| 2044 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2045 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2046 | break; |
| 2047 | case Primitive::kPrimChar: |
| 2048 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2049 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | case Primitive::kPrimInt: |
| 2052 | case Primitive::kPrimNot: |
| 2053 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2054 | case Primitive::kPrimFloat: |
| 2055 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2056 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2057 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2058 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2059 | case Primitive::kPrimVoid: |
| 2060 | LOG(FATAL) << "Unreachable type " << type; |
| 2061 | } |
| 2062 | } |
| 2063 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2064 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2065 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2066 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | const MemOperand& dst, |
| 2068 | bool needs_null_check) { |
| 2069 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2070 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2071 | Register temp_base = temps.AcquireX(); |
| 2072 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2073 | DCHECK(!dst.IsPreIndex()); |
| 2074 | DCHECK(!dst.IsPostIndex()); |
| 2075 | |
| 2076 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2077 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2078 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2079 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2080 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2081 | switch (type) { |
| 2082 | case Primitive::kPrimBoolean: |
| 2083 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2084 | { |
| 2085 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2086 | __ stlrb(Register(src), base); |
| 2087 | if (needs_null_check) { |
| 2088 | MaybeRecordImplicitNullCheck(instruction); |
| 2089 | } |
| 2090 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2091 | break; |
| 2092 | case Primitive::kPrimChar: |
| 2093 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2094 | { |
| 2095 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2096 | __ stlrh(Register(src), base); |
| 2097 | if (needs_null_check) { |
| 2098 | MaybeRecordImplicitNullCheck(instruction); |
| 2099 | } |
| 2100 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | case Primitive::kPrimInt: |
| 2103 | case Primitive::kPrimNot: |
| 2104 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2105 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2106 | { |
| 2107 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2108 | __ stlr(Register(src), base); |
| 2109 | if (needs_null_check) { |
| 2110 | MaybeRecordImplicitNullCheck(instruction); |
| 2111 | } |
| 2112 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2113 | break; |
| 2114 | case Primitive::kPrimFloat: |
| 2115 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2116 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2117 | Register temp_src; |
| 2118 | if (src.IsZero()) { |
| 2119 | // The zero register is used to avoid synthesizing zero constants. |
| 2120 | temp_src = Register(src); |
| 2121 | } else { |
| 2122 | DCHECK(src.IsFPRegister()); |
| 2123 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2124 | __ Fmov(temp_src, FPRegister(src)); |
| 2125 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2126 | { |
| 2127 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2128 | __ stlr(temp_src, base); |
| 2129 | if (needs_null_check) { |
| 2130 | MaybeRecordImplicitNullCheck(instruction); |
| 2131 | } |
| 2132 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2133 | break; |
| 2134 | } |
| 2135 | case Primitive::kPrimVoid: |
| 2136 | LOG(FATAL) << "Unreachable type " << type; |
| 2137 | } |
| 2138 | } |
| 2139 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2140 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2141 | HInstruction* instruction, |
| 2142 | uint32_t dex_pc, |
| 2143 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2144 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2145 | |
| 2146 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2147 | { |
| 2148 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2149 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2150 | __ blr(lr); |
| 2151 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2152 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2153 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2154 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2157 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2158 | HInstruction* instruction, |
| 2159 | SlowPathCode* slow_path) { |
| 2160 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2161 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2162 | __ Blr(lr); |
| 2163 | } |
| 2164 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2165 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2166 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2167 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2168 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2169 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2170 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2171 | // 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] | 2172 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2173 | __ Add(temp, class_reg, status_offset); |
| 2174 | __ Ldar(temp, HeapOperand(temp)); |
| 2175 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2176 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2177 | __ Bind(slow_path->GetExitLabel()); |
| 2178 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2179 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2180 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2181 | BarrierType type = BarrierAll; |
| 2182 | |
| 2183 | switch (kind) { |
| 2184 | case MemBarrierKind::kAnyAny: |
| 2185 | case MemBarrierKind::kAnyStore: { |
| 2186 | type = BarrierAll; |
| 2187 | break; |
| 2188 | } |
| 2189 | case MemBarrierKind::kLoadAny: { |
| 2190 | type = BarrierReads; |
| 2191 | break; |
| 2192 | } |
| 2193 | case MemBarrierKind::kStoreStore: { |
| 2194 | type = BarrierWrites; |
| 2195 | break; |
| 2196 | } |
| 2197 | default: |
| 2198 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2199 | } |
| 2200 | __ Dmb(InnerShareable, type); |
| 2201 | } |
| 2202 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2203 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2204 | HBasicBlock* successor) { |
| 2205 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2206 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2207 | if (slow_path == nullptr) { |
| 2208 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2209 | instruction->SetSlowPath(slow_path); |
| 2210 | codegen_->AddSlowPath(slow_path); |
| 2211 | if (successor != nullptr) { |
| 2212 | DCHECK(successor->IsLoopHeader()); |
| 2213 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2214 | } |
| 2215 | } else { |
| 2216 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2217 | } |
| 2218 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2219 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2220 | Register temp = temps.AcquireW(); |
| 2221 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2222 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2223 | if (successor == nullptr) { |
| 2224 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2225 | __ Bind(slow_path->GetReturnLabel()); |
| 2226 | } else { |
| 2227 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2228 | __ B(slow_path->GetEntryLabel()); |
| 2229 | // slow_path will return to GetLabelOf(successor). |
| 2230 | } |
| 2231 | } |
| 2232 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2233 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2234 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2235 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2236 | assembler_(codegen->GetAssembler()), |
| 2237 | codegen_(codegen) {} |
| 2238 | |
| 2239 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2240 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2241 | |
| 2242 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2243 | |
| 2244 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2245 | // Using a base helps identify when we hit such breakpoints. |
| 2246 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2247 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2248 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2249 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2250 | }; |
| 2251 | |
| 2252 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2253 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2254 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2255 | } \ |
| 2256 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2257 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2258 | locations->SetOut(Location::Any()); \ |
| 2259 | } |
| 2260 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2261 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2262 | |
| 2263 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2264 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2265 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2266 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2267 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2268 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2269 | Primitive::Type type = instr->GetResultType(); |
| 2270 | switch (type) { |
| 2271 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2273 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2274 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2275 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2276 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2277 | |
| 2278 | case Primitive::kPrimFloat: |
| 2279 | case Primitive::kPrimDouble: |
| 2280 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2281 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2282 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2283 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2284 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2285 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2286 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2290 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2291 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2292 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2293 | |
| 2294 | bool object_field_get_with_read_barrier = |
| 2295 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2296 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2297 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2298 | object_field_get_with_read_barrier ? |
| 2299 | LocationSummary::kCallOnSlowPath : |
| 2300 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2301 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2302 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2303 | // We need a temporary register for the read barrier marking slow |
| 2304 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2305 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2306 | !Runtime::Current()->UseJitCompilation() && |
| 2307 | !field_info.IsVolatile()) { |
| 2308 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2309 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2310 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2311 | locations->AddTemp(FixedTempLocation()); |
| 2312 | } |
| 2313 | } else { |
| 2314 | locations->AddTemp(Location::RequiresRegister()); |
| 2315 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2316 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2318 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2319 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2320 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2321 | // The output overlaps for an object field get when read barriers |
| 2322 | // are enabled: we do not want the load to overwrite the object's |
| 2323 | // location, as we need it to emit the read barrier. |
| 2324 | locations->SetOut( |
| 2325 | Location::RequiresRegister(), |
| 2326 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2331 | const FieldInfo& field_info) { |
| 2332 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2333 | LocationSummary* locations = instruction->GetLocations(); |
| 2334 | Location base_loc = locations->InAt(0); |
| 2335 | Location out = locations->Out(); |
| 2336 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2337 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2338 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2339 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2340 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2341 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2342 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2343 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2344 | Location maybe_temp = |
| 2345 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2346 | // Note that potential implicit null checks are handled in this |
| 2347 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2348 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2349 | instruction, |
| 2350 | out, |
| 2351 | base, |
| 2352 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2353 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2354 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2355 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2356 | } else { |
| 2357 | // General case. |
| 2358 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2359 | // Note that a potential implicit null check is handled in this |
| 2360 | // CodeGeneratorARM64::LoadAcquire call. |
| 2361 | // NB: LoadAcquire will record the pc info if needed. |
| 2362 | codegen_->LoadAcquire( |
| 2363 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2364 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2365 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2366 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2367 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2368 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2369 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2370 | if (field_type == Primitive::kPrimNot) { |
| 2371 | // If read barriers are enabled, emit read barriers other than |
| 2372 | // Baker's using a slow path (and also unpoison the loaded |
| 2373 | // reference, if heap poisoning is enabled). |
| 2374 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2375 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2376 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2380 | LocationSummary* locations = |
| 2381 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2382 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2383 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2384 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2385 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2386 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2387 | } else { |
| 2388 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2393 | const FieldInfo& field_info, |
| 2394 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2395 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2396 | |
| 2397 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2398 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2399 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2400 | Offset offset = field_info.GetFieldOffset(); |
| 2401 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2402 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2403 | { |
| 2404 | // We use a block to end the scratch scope before the write barrier, thus |
| 2405 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2406 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2407 | |
| 2408 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2409 | DCHECK(value.IsW()); |
| 2410 | Register temp = temps.AcquireW(); |
| 2411 | __ Mov(temp, value.W()); |
| 2412 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2413 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2414 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2415 | |
| 2416 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2417 | codegen_->StoreRelease( |
| 2418 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2419 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2420 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2421 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2422 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2423 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2424 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2428 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2432 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2433 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2434 | |
| 2435 | switch (type) { |
| 2436 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2437 | case Primitive::kPrimLong: { |
| 2438 | Register dst = OutputRegister(instr); |
| 2439 | Register lhs = InputRegisterAt(instr, 0); |
| 2440 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2441 | if (instr->IsAdd()) { |
| 2442 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2443 | } else if (instr->IsAnd()) { |
| 2444 | __ And(dst, lhs, rhs); |
| 2445 | } else if (instr->IsOr()) { |
| 2446 | __ Orr(dst, lhs, rhs); |
| 2447 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2448 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2449 | } else if (instr->IsRor()) { |
| 2450 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2451 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2452 | __ Ror(dst, lhs, shift); |
| 2453 | } else { |
| 2454 | // Ensure shift distance is in the same size register as the result. If |
| 2455 | // we are rotating a long and the shift comes in a w register originally, |
| 2456 | // we don't need to sxtw for use as an x since the shift distances are |
| 2457 | // all & reg_bits - 1. |
| 2458 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2459 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2460 | } else { |
| 2461 | DCHECK(instr->IsXor()); |
| 2462 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2463 | } |
| 2464 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2465 | } |
| 2466 | case Primitive::kPrimFloat: |
| 2467 | case Primitive::kPrimDouble: { |
| 2468 | FPRegister dst = OutputFPRegister(instr); |
| 2469 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2470 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2471 | if (instr->IsAdd()) { |
| 2472 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2473 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2474 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2475 | } else { |
| 2476 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2477 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2478 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2479 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2480 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2481 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2485 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2486 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2487 | |
| 2488 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2489 | Primitive::Type type = instr->GetResultType(); |
| 2490 | switch (type) { |
| 2491 | case Primitive::kPrimInt: |
| 2492 | case Primitive::kPrimLong: { |
| 2493 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2494 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2495 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2496 | break; |
| 2497 | } |
| 2498 | default: |
| 2499 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2504 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2505 | |
| 2506 | Primitive::Type type = instr->GetType(); |
| 2507 | switch (type) { |
| 2508 | case Primitive::kPrimInt: |
| 2509 | case Primitive::kPrimLong: { |
| 2510 | Register dst = OutputRegister(instr); |
| 2511 | Register lhs = InputRegisterAt(instr, 0); |
| 2512 | Operand rhs = InputOperandAt(instr, 1); |
| 2513 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2514 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2515 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2516 | if (instr->IsShl()) { |
| 2517 | __ Lsl(dst, lhs, shift_value); |
| 2518 | } else if (instr->IsShr()) { |
| 2519 | __ Asr(dst, lhs, shift_value); |
| 2520 | } else { |
| 2521 | __ Lsr(dst, lhs, shift_value); |
| 2522 | } |
| 2523 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2524 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2525 | |
| 2526 | if (instr->IsShl()) { |
| 2527 | __ Lsl(dst, lhs, rhs_reg); |
| 2528 | } else if (instr->IsShr()) { |
| 2529 | __ Asr(dst, lhs, rhs_reg); |
| 2530 | } else { |
| 2531 | __ Lsr(dst, lhs, rhs_reg); |
| 2532 | } |
| 2533 | } |
| 2534 | break; |
| 2535 | } |
| 2536 | default: |
| 2537 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2538 | } |
| 2539 | } |
| 2540 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2541 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2542 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2546 | HandleBinaryOp(instruction); |
| 2547 | } |
| 2548 | |
| 2549 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2550 | HandleBinaryOp(instruction); |
| 2551 | } |
| 2552 | |
| 2553 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2554 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2557 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2558 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2559 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2561 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2562 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2563 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2564 | } |
| 2565 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2566 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2567 | Register dst = OutputRegister(instr); |
| 2568 | Register lhs = InputRegisterAt(instr, 0); |
| 2569 | Register rhs = InputRegisterAt(instr, 1); |
| 2570 | |
| 2571 | switch (instr->GetOpKind()) { |
| 2572 | case HInstruction::kAnd: |
| 2573 | __ Bic(dst, lhs, rhs); |
| 2574 | break; |
| 2575 | case HInstruction::kOr: |
| 2576 | __ Orn(dst, lhs, rhs); |
| 2577 | break; |
| 2578 | case HInstruction::kXor: |
| 2579 | __ Eon(dst, lhs, rhs); |
| 2580 | break; |
| 2581 | default: |
| 2582 | LOG(FATAL) << "Unreachable"; |
| 2583 | } |
| 2584 | } |
| 2585 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2586 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2587 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2588 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2589 | instruction->GetType() == Primitive::kPrimLong); |
| 2590 | LocationSummary* locations = |
| 2591 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2592 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2593 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2594 | } else { |
| 2595 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2596 | } |
| 2597 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2598 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2599 | } |
| 2600 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2601 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2602 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2603 | Primitive::Type type = instruction->GetType(); |
| 2604 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2605 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2606 | Register out = OutputRegister(instruction); |
| 2607 | Register left; |
| 2608 | if (kind != HInstruction::kNeg) { |
| 2609 | left = InputRegisterAt(instruction, 0); |
| 2610 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2611 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2612 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2613 | // conversion) can have a different type from the current instruction's type, |
| 2614 | // so we manually indicate the type. |
| 2615 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2616 | Operand right_operand(0); |
| 2617 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2618 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2619 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2620 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2621 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2622 | right_operand = Operand(right_reg, |
| 2623 | helpers::ShiftFromOpKind(op_kind), |
| 2624 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | // Logical binary operations do not support extension operations in the |
| 2628 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2629 | // the extension as a separate instruction. |
| 2630 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2631 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2632 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2633 | kind != HInstruction::kNeg)); |
| 2634 | switch (kind) { |
| 2635 | case HInstruction::kAdd: |
| 2636 | __ Add(out, left, right_operand); |
| 2637 | break; |
| 2638 | case HInstruction::kAnd: |
| 2639 | __ And(out, left, right_operand); |
| 2640 | break; |
| 2641 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2642 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2643 | __ Neg(out, right_operand); |
| 2644 | break; |
| 2645 | case HInstruction::kOr: |
| 2646 | __ Orr(out, left, right_operand); |
| 2647 | break; |
| 2648 | case HInstruction::kSub: |
| 2649 | __ Sub(out, left, right_operand); |
| 2650 | break; |
| 2651 | case HInstruction::kXor: |
| 2652 | __ Eor(out, left, right_operand); |
| 2653 | break; |
| 2654 | default: |
| 2655 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2656 | UNREACHABLE(); |
| 2657 | } |
| 2658 | } |
| 2659 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2660 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2661 | LocationSummary* locations = |
| 2662 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2663 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2664 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2665 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2666 | } |
| 2667 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2668 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2669 | __ Add(OutputRegister(instruction), |
| 2670 | InputRegisterAt(instruction, 0), |
| 2671 | Operand(InputOperandAt(instruction, 1))); |
| 2672 | } |
| 2673 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2674 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2675 | LocationSummary* locations = |
| 2676 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2677 | |
| 2678 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2679 | |
| 2680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2681 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2682 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2683 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2684 | // loop. |
| 2685 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2686 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2687 | : Location::RequiresRegister()); |
| 2688 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2689 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2690 | } |
| 2691 | |
| 2692 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2693 | HIntermediateAddressIndex* instruction) { |
| 2694 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2695 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2696 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2697 | |
| 2698 | if (shift == 0) { |
| 2699 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2700 | } else { |
| 2701 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2702 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2703 | } |
| 2704 | } |
| 2705 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2706 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2707 | LocationSummary* locations = |
| 2708 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2709 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2710 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2711 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2712 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2713 | // Don't allocate register for Mneg instruction. |
| 2714 | } else { |
| 2715 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2716 | Location::RequiresRegister()); |
| 2717 | } |
| 2718 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2719 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2720 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2721 | } |
| 2722 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2723 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2724 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2725 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2726 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2727 | |
| 2728 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2729 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2730 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2731 | if (instr->GetType() == Primitive::kPrimLong && |
| 2732 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2733 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2734 | vixl::aarch64::Instruction* prev = |
| 2735 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2736 | if (prev->IsLoadOrStore()) { |
| 2737 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2738 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2739 | __ nop(); |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2744 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2745 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2746 | } else { |
| 2747 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2748 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2749 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2750 | __ Mneg(res, mul_left, mul_right); |
| 2751 | } else { |
| 2752 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2753 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2754 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2755 | } |
| 2756 | } |
| 2757 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2758 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2759 | bool object_array_get_with_read_barrier = |
| 2760 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2761 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2762 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2763 | object_array_get_with_read_barrier ? |
| 2764 | LocationSummary::kCallOnSlowPath : |
| 2765 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2766 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2767 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2768 | // We need a temporary register for the read barrier marking slow |
| 2769 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2770 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2771 | !Runtime::Current()->UseJitCompilation() && |
| 2772 | instruction->GetIndex()->IsConstant()) { |
| 2773 | // Array loads with constant index are treated as field loads. |
| 2774 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2775 | // constant index loads we need a temporary only if the offset is too big. |
| 2776 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2777 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2778 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2779 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2780 | locations->AddTemp(FixedTempLocation()); |
| 2781 | } |
| 2782 | } else { |
| 2783 | locations->AddTemp(Location::RequiresRegister()); |
| 2784 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2785 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2786 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2787 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2788 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2789 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2790 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2791 | // The output overlaps in the case of an object array get with |
| 2792 | // read barriers enabled: we do not want the move to overwrite the |
| 2793 | // array's location, as we need it to emit the read barrier. |
| 2794 | locations->SetOut( |
| 2795 | Location::RequiresRegister(), |
| 2796 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2797 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2801 | Primitive::Type type = instruction->GetType(); |
| 2802 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2803 | LocationSummary* locations = instruction->GetLocations(); |
| 2804 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2805 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2806 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2807 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2808 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2809 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2810 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2811 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2812 | // The read barrier instrumentation of object ArrayGet instructions |
| 2813 | // does not support the HIntermediateAddress instruction. |
| 2814 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2815 | instruction->GetArray()->IsIntermediateAddress() && |
| 2816 | kEmitCompilerReadBarrier)); |
| 2817 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2818 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2819 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2820 | // Note that a potential implicit null check is handled in the |
| 2821 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2822 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2823 | if (index.IsConstant()) { |
| 2824 | // Array load with a constant index can be treated as a field load. |
| 2825 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2826 | Location maybe_temp = |
| 2827 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2828 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2829 | out, |
| 2830 | obj.W(), |
| 2831 | offset, |
| 2832 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2833 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2834 | /* use_load_acquire */ false); |
| 2835 | } else { |
| 2836 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2837 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2838 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2839 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2840 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2841 | // General case. |
| 2842 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2843 | Register length; |
| 2844 | if (maybe_compressed_char_at) { |
| 2845 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2846 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2847 | { |
| 2848 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2849 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2850 | |
| 2851 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2852 | DCHECK_LT(count_offset, offset); |
| 2853 | int64_t adjusted_offset = |
| 2854 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2855 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2856 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2857 | } else { |
| 2858 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2859 | } |
| 2860 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2861 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2862 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2863 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2864 | if (maybe_compressed_char_at) { |
| 2865 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2866 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2867 | "Expecting 0=compressed, 1=uncompressed"); |
| 2868 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2869 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2870 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2871 | __ B(&done); |
| 2872 | __ Bind(&uncompressed_load); |
| 2873 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2874 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2875 | __ Bind(&done); |
| 2876 | } else { |
| 2877 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2878 | source = HeapOperand(obj, offset); |
| 2879 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2880 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2881 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2882 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2883 | // We do not need to compute the intermediate address from the array: the |
| 2884 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2885 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2886 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2887 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2888 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2889 | } |
| 2890 | temp = obj; |
| 2891 | } else { |
| 2892 | __ Add(temp, obj, offset); |
| 2893 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2894 | if (maybe_compressed_char_at) { |
| 2895 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2896 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2897 | "Expecting 0=compressed, 1=uncompressed"); |
| 2898 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2899 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2900 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2901 | __ B(&done); |
| 2902 | __ Bind(&uncompressed_load); |
| 2903 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2904 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2905 | __ Bind(&done); |
| 2906 | } else { |
| 2907 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2908 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2909 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2910 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2911 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2912 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2913 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2914 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2915 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2916 | |
| 2917 | if (type == Primitive::kPrimNot) { |
| 2918 | static_assert( |
| 2919 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2920 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2921 | Location obj_loc = locations->InAt(0); |
| 2922 | if (index.IsConstant()) { |
| 2923 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2924 | } else { |
| 2925 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2926 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2927 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2928 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2931 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2932 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2933 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2934 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2938 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2939 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2940 | { |
| 2941 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2942 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2943 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2944 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2945 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2946 | // Mask out compression flag from String's array length. |
| 2947 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2948 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2949 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2950 | } |
| 2951 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2952 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2953 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2954 | |
| 2955 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2956 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2957 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2958 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2959 | LocationSummary::kCallOnSlowPath : |
| 2960 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2961 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2962 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2963 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2964 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2965 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2966 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2967 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2968 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2973 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2974 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2975 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2976 | bool needs_write_barrier = |
| 2977 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2978 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2979 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2980 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2981 | CPURegister source = value; |
| 2982 | Location index = locations->InAt(1); |
| 2983 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2984 | MemOperand destination = HeapOperand(array); |
| 2985 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2986 | |
| 2987 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2988 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2989 | if (index.IsConstant()) { |
| 2990 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2991 | destination = HeapOperand(array, offset); |
| 2992 | } else { |
| 2993 | UseScratchRegisterScope temps(masm); |
| 2994 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2995 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2996 | // We do not need to compute the intermediate address from the array: the |
| 2997 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2998 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2999 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3000 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3001 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 3002 | } |
| 3003 | temp = array; |
| 3004 | } else { |
| 3005 | __ Add(temp, array, offset); |
| 3006 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3007 | destination = HeapOperand(temp, |
| 3008 | XRegisterFrom(index), |
| 3009 | LSL, |
| 3010 | Primitive::ComponentSizeShift(value_type)); |
| 3011 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3012 | { |
| 3013 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3014 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3015 | codegen_->Store(value_type, value, destination); |
| 3016 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3017 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3018 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3019 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3020 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3021 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3022 | { |
| 3023 | // We use a block to end the scratch scope before the write barrier, thus |
| 3024 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3025 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3026 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3027 | if (index.IsConstant()) { |
| 3028 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3029 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3030 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3031 | destination = HeapOperand(temp, |
| 3032 | XRegisterFrom(index), |
| 3033 | LSL, |
| 3034 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3035 | } |
| 3036 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3037 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3038 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3039 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3040 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3041 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3042 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 3043 | codegen_->AddSlowPath(slow_path); |
| 3044 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3045 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3046 | __ Cbnz(Register(value), &non_zero); |
| 3047 | if (!index.IsConstant()) { |
| 3048 | __ Add(temp, array, offset); |
| 3049 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3050 | { |
| 3051 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3052 | // emitted. |
| 3053 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3054 | __ Str(wzr, destination); |
| 3055 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3056 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3057 | __ B(&done); |
| 3058 | __ Bind(&non_zero); |
| 3059 | } |
| 3060 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3061 | // Note that when Baker read barriers are enabled, the type |
| 3062 | // checks are performed without read barriers. This is fine, |
| 3063 | // even in the case where a class object is in the from-space |
| 3064 | // after the flip, as a comparison involving such a type would |
| 3065 | // not produce a false positive; it may of course produce a |
| 3066 | // false negative, in which case we would take the ArraySet |
| 3067 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3068 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3069 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3070 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3071 | { |
| 3072 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3073 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3074 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3075 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3076 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3077 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3078 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3079 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3080 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3081 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3082 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3083 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3084 | // nor `temp2`, as we are comparing two poisoned references. |
| 3085 | __ Cmp(temp, temp2); |
| 3086 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3087 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3088 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3089 | vixl::aarch64::Label do_put; |
| 3090 | __ B(eq, &do_put); |
| 3091 | // If heap poisoning is enabled, the `temp` reference has |
| 3092 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3093 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3094 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3095 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3096 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3097 | // If heap poisoning is enabled, no need to unpoison |
| 3098 | // `temp`, as we are comparing against null below. |
| 3099 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3100 | __ Bind(&do_put); |
| 3101 | } else { |
| 3102 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3107 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3108 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3109 | __ Mov(temp2, value.W()); |
| 3110 | GetAssembler()->PoisonHeapReference(temp2); |
| 3111 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | if (!index.IsConstant()) { |
| 3115 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3116 | } else { |
| 3117 | // We no longer need the `temp` here so release it as the store below may |
| 3118 | // need a scratch register (if the constant index makes the offset too large) |
| 3119 | // and the poisoned `source` could be using the other scratch register. |
| 3120 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3121 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3122 | { |
| 3123 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3124 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3125 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3126 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3127 | if (!may_need_runtime_call_for_type_check) { |
| 3128 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3129 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3130 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3131 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3132 | |
| 3133 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3134 | |
| 3135 | if (done.IsLinked()) { |
| 3136 | __ Bind(&done); |
| 3137 | } |
| 3138 | |
| 3139 | if (slow_path != nullptr) { |
| 3140 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3141 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3145 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3146 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3147 | InvokeRuntimeCallingConvention calling_convention; |
| 3148 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3149 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3150 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3151 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3152 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3156 | BoundsCheckSlowPathARM64* slow_path = |
| 3157 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3158 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3159 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3160 | __ B(slow_path->GetEntryLabel(), hs); |
| 3161 | } |
| 3162 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3163 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3164 | LocationSummary* locations = |
| 3165 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3167 | if (check->HasUses()) { |
| 3168 | locations->SetOut(Location::SameAsFirstInput()); |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3173 | // We assume the class is not null. |
| 3174 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3175 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3176 | codegen_->AddSlowPath(slow_path); |
| 3177 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3178 | } |
| 3179 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3180 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3181 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3182 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3183 | } |
| 3184 | |
| 3185 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3186 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3187 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3188 | if (rhs_loc.IsConstant()) { |
| 3189 | // 0.0 is the only immediate that can be encoded directly in |
| 3190 | // an FCMP instruction. |
| 3191 | // |
| 3192 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3193 | // specify that in a floating-point comparison, positive zero |
| 3194 | // and negative zero are considered equal, so we can use the |
| 3195 | // literal 0.0 for both cases here. |
| 3196 | // |
| 3197 | // Note however that some methods (Float.equal, Float.compare, |
| 3198 | // Float.compareTo, Double.equal, Double.compare, |
| 3199 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3200 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3201 | // -0.0. So if we ever translate calls to these methods into a |
| 3202 | // HCompare instruction, we must handle the -0.0 case with |
| 3203 | // care here. |
| 3204 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3205 | __ Fcmp(lhs_reg, 0.0); |
| 3206 | } else { |
| 3207 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3208 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3211 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3212 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3213 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3214 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3215 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3216 | case Primitive::kPrimBoolean: |
| 3217 | case Primitive::kPrimByte: |
| 3218 | case Primitive::kPrimShort: |
| 3219 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3220 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3221 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3222 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3223 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3224 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3225 | break; |
| 3226 | } |
| 3227 | case Primitive::kPrimFloat: |
| 3228 | case Primitive::kPrimDouble: { |
| 3229 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3230 | locations->SetInAt(1, |
| 3231 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3232 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3233 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3234 | locations->SetOut(Location::RequiresRegister()); |
| 3235 | break; |
| 3236 | } |
| 3237 | default: |
| 3238 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3243 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3244 | |
| 3245 | // 0 if: left == right |
| 3246 | // 1 if: left > right |
| 3247 | // -1 if: left < right |
| 3248 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3249 | case Primitive::kPrimBoolean: |
| 3250 | case Primitive::kPrimByte: |
| 3251 | case Primitive::kPrimShort: |
| 3252 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3253 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3254 | case Primitive::kPrimLong: { |
| 3255 | Register result = OutputRegister(compare); |
| 3256 | Register left = InputRegisterAt(compare, 0); |
| 3257 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3258 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3259 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3260 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3261 | break; |
| 3262 | } |
| 3263 | case Primitive::kPrimFloat: |
| 3264 | case Primitive::kPrimDouble: { |
| 3265 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3266 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3267 | __ Cset(result, ne); |
| 3268 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3269 | break; |
| 3270 | } |
| 3271 | default: |
| 3272 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3273 | } |
| 3274 | } |
| 3275 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3276 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3277 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3278 | |
| 3279 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3280 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3281 | locations->SetInAt(1, |
| 3282 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3283 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3284 | : Location::RequiresFpuRegister()); |
| 3285 | } else { |
| 3286 | // Integer cases. |
| 3287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3288 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3289 | } |
| 3290 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3291 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3292 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3293 | } |
| 3294 | } |
| 3295 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3296 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3297 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3298 | return; |
| 3299 | } |
| 3300 | |
| 3301 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3302 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3303 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3304 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3305 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3306 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3307 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3308 | } else { |
| 3309 | // Integer cases. |
| 3310 | Register lhs = InputRegisterAt(instruction, 0); |
| 3311 | Operand rhs = InputOperandAt(instruction, 1); |
| 3312 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3313 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3314 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3318 | M(Equal) \ |
| 3319 | M(NotEqual) \ |
| 3320 | M(LessThan) \ |
| 3321 | M(LessThanOrEqual) \ |
| 3322 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3323 | M(GreaterThanOrEqual) \ |
| 3324 | M(Below) \ |
| 3325 | M(BelowOrEqual) \ |
| 3326 | M(Above) \ |
| 3327 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3328 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3329 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3330 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3331 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3332 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3333 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3334 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3335 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3336 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3337 | |
| 3338 | LocationSummary* locations = instruction->GetLocations(); |
| 3339 | Location second = locations->InAt(1); |
| 3340 | DCHECK(second.IsConstant()); |
| 3341 | |
| 3342 | Register out = OutputRegister(instruction); |
| 3343 | Register dividend = InputRegisterAt(instruction, 0); |
| 3344 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3345 | DCHECK(imm == 1 || imm == -1); |
| 3346 | |
| 3347 | if (instruction->IsRem()) { |
| 3348 | __ Mov(out, 0); |
| 3349 | } else { |
| 3350 | if (imm == 1) { |
| 3351 | __ Mov(out, dividend); |
| 3352 | } else { |
| 3353 | __ Neg(out, dividend); |
| 3354 | } |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3359 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3360 | |
| 3361 | LocationSummary* locations = instruction->GetLocations(); |
| 3362 | Location second = locations->InAt(1); |
| 3363 | DCHECK(second.IsConstant()); |
| 3364 | |
| 3365 | Register out = OutputRegister(instruction); |
| 3366 | Register dividend = InputRegisterAt(instruction, 0); |
| 3367 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3368 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3369 | int ctz_imm = CTZ(abs_imm); |
| 3370 | |
| 3371 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3372 | Register temp = temps.AcquireSameSizeAs(out); |
| 3373 | |
| 3374 | if (instruction->IsDiv()) { |
| 3375 | __ Add(temp, dividend, abs_imm - 1); |
| 3376 | __ Cmp(dividend, 0); |
| 3377 | __ Csel(out, temp, dividend, lt); |
| 3378 | if (imm > 0) { |
| 3379 | __ Asr(out, out, ctz_imm); |
| 3380 | } else { |
| 3381 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3382 | } |
| 3383 | } else { |
| 3384 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3385 | __ Asr(temp, dividend, bits - 1); |
| 3386 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3387 | __ Add(out, dividend, temp); |
| 3388 | __ And(out, out, abs_imm - 1); |
| 3389 | __ Sub(out, out, temp); |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3394 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3395 | |
| 3396 | LocationSummary* locations = instruction->GetLocations(); |
| 3397 | Location second = locations->InAt(1); |
| 3398 | DCHECK(second.IsConstant()); |
| 3399 | |
| 3400 | Register out = OutputRegister(instruction); |
| 3401 | Register dividend = InputRegisterAt(instruction, 0); |
| 3402 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3403 | |
| 3404 | Primitive::Type type = instruction->GetResultType(); |
| 3405 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3406 | |
| 3407 | int64_t magic; |
| 3408 | int shift; |
| 3409 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3410 | |
| 3411 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3412 | Register temp = temps.AcquireSameSizeAs(out); |
| 3413 | |
| 3414 | // temp = get_high(dividend * magic) |
| 3415 | __ Mov(temp, magic); |
| 3416 | if (type == Primitive::kPrimLong) { |
| 3417 | __ Smulh(temp, dividend, temp); |
| 3418 | } else { |
| 3419 | __ Smull(temp.X(), dividend, temp); |
| 3420 | __ Lsr(temp.X(), temp.X(), 32); |
| 3421 | } |
| 3422 | |
| 3423 | if (imm > 0 && magic < 0) { |
| 3424 | __ Add(temp, temp, dividend); |
| 3425 | } else if (imm < 0 && magic > 0) { |
| 3426 | __ Sub(temp, temp, dividend); |
| 3427 | } |
| 3428 | |
| 3429 | if (shift != 0) { |
| 3430 | __ Asr(temp, temp, shift); |
| 3431 | } |
| 3432 | |
| 3433 | if (instruction->IsDiv()) { |
| 3434 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3435 | } else { |
| 3436 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3437 | // TODO: Strength reduction for msub. |
| 3438 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3439 | __ Mov(temp_imm, imm); |
| 3440 | __ Msub(out, temp, temp_imm, dividend); |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3445 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3446 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3447 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3448 | |
| 3449 | LocationSummary* locations = instruction->GetLocations(); |
| 3450 | Register out = OutputRegister(instruction); |
| 3451 | Location second = locations->InAt(1); |
| 3452 | |
| 3453 | if (second.IsConstant()) { |
| 3454 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3455 | |
| 3456 | if (imm == 0) { |
| 3457 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3458 | } else if (imm == 1 || imm == -1) { |
| 3459 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3460 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3461 | DivRemByPowerOfTwo(instruction); |
| 3462 | } else { |
| 3463 | DCHECK(imm <= -2 || imm >= 2); |
| 3464 | GenerateDivRemWithAnyConstant(instruction); |
| 3465 | } |
| 3466 | } else { |
| 3467 | Register dividend = InputRegisterAt(instruction, 0); |
| 3468 | Register divisor = InputRegisterAt(instruction, 1); |
| 3469 | if (instruction->IsDiv()) { |
| 3470 | __ Sdiv(out, dividend, divisor); |
| 3471 | } else { |
| 3472 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3473 | Register temp = temps.AcquireSameSizeAs(out); |
| 3474 | __ Sdiv(temp, dividend, divisor); |
| 3475 | __ Msub(out, temp, divisor, dividend); |
| 3476 | } |
| 3477 | } |
| 3478 | } |
| 3479 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3480 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3481 | LocationSummary* locations = |
| 3482 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3483 | switch (div->GetResultType()) { |
| 3484 | case Primitive::kPrimInt: |
| 3485 | case Primitive::kPrimLong: |
| 3486 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3487 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3488 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3489 | break; |
| 3490 | |
| 3491 | case Primitive::kPrimFloat: |
| 3492 | case Primitive::kPrimDouble: |
| 3493 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3494 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3495 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3496 | break; |
| 3497 | |
| 3498 | default: |
| 3499 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3500 | } |
| 3501 | } |
| 3502 | |
| 3503 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3504 | Primitive::Type type = div->GetResultType(); |
| 3505 | switch (type) { |
| 3506 | case Primitive::kPrimInt: |
| 3507 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3508 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3509 | break; |
| 3510 | |
| 3511 | case Primitive::kPrimFloat: |
| 3512 | case Primitive::kPrimDouble: |
| 3513 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3514 | break; |
| 3515 | |
| 3516 | default: |
| 3517 | LOG(FATAL) << "Unexpected div type " << type; |
| 3518 | } |
| 3519 | } |
| 3520 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3521 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3522 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3523 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3527 | SlowPathCodeARM64* slow_path = |
| 3528 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3529 | codegen_->AddSlowPath(slow_path); |
| 3530 | Location value = instruction->GetLocations()->InAt(0); |
| 3531 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3532 | Primitive::Type type = instruction->GetType(); |
| 3533 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3534 | if (!Primitive::IsIntegralType(type)) { |
| 3535 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3536 | return; |
| 3537 | } |
| 3538 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3539 | if (value.IsConstant()) { |
| 3540 | int64_t divisor = Int64ConstantFrom(value); |
| 3541 | if (divisor == 0) { |
| 3542 | __ B(slow_path->GetEntryLabel()); |
| 3543 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3544 | // A division by a non-null constant is valid. We don't need to perform |
| 3545 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3546 | } |
| 3547 | } else { |
| 3548 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3549 | } |
| 3550 | } |
| 3551 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3552 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3553 | LocationSummary* locations = |
| 3554 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3555 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3556 | } |
| 3557 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3558 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3559 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3560 | // Will be generated at use site. |
| 3561 | } |
| 3562 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3563 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3564 | exit->SetLocations(nullptr); |
| 3565 | } |
| 3566 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3567 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3568 | } |
| 3569 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3570 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3571 | LocationSummary* locations = |
| 3572 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3573 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3574 | } |
| 3575 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3576 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3577 | // Will be generated at use site. |
| 3578 | } |
| 3579 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3580 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3581 | DCHECK(!successor->IsExitBlock()); |
| 3582 | HBasicBlock* block = got->GetBlock(); |
| 3583 | HInstruction* previous = got->GetPrevious(); |
| 3584 | HLoopInformation* info = block->GetLoopInformation(); |
| 3585 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3586 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3587 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3588 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3589 | return; |
| 3590 | } |
| 3591 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3592 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3593 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3594 | } |
| 3595 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3596 | __ B(codegen_->GetLabelOf(successor)); |
| 3597 | } |
| 3598 | } |
| 3599 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3600 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3601 | got->SetLocations(nullptr); |
| 3602 | } |
| 3603 | |
| 3604 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3605 | HandleGoto(got, got->GetSuccessor()); |
| 3606 | } |
| 3607 | |
| 3608 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3609 | try_boundary->SetLocations(nullptr); |
| 3610 | } |
| 3611 | |
| 3612 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3613 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3614 | if (!successor->IsExitBlock()) { |
| 3615 | HandleGoto(try_boundary, successor); |
| 3616 | } |
| 3617 | } |
| 3618 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3619 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3620 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3621 | vixl::aarch64::Label* true_target, |
| 3622 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3623 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3624 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3625 | if (true_target == nullptr && false_target == nullptr) { |
| 3626 | // Nothing to do. The code always falls through. |
| 3627 | return; |
| 3628 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3629 | // Constant condition, statically compared against "true" (integer value 1). |
| 3630 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3631 | if (true_target != nullptr) { |
| 3632 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3633 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3634 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3635 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3636 | if (false_target != nullptr) { |
| 3637 | __ B(false_target); |
| 3638 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3639 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3640 | return; |
| 3641 | } |
| 3642 | |
| 3643 | // The following code generates these patterns: |
| 3644 | // (1) true_target == nullptr && false_target != nullptr |
| 3645 | // - opposite condition true => branch to false_target |
| 3646 | // (2) true_target != nullptr && false_target == nullptr |
| 3647 | // - condition true => branch to true_target |
| 3648 | // (3) true_target != nullptr && false_target != nullptr |
| 3649 | // - condition true => branch to true_target |
| 3650 | // - branch to false_target |
| 3651 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3652 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3653 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3654 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3655 | if (true_target == nullptr) { |
| 3656 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3657 | } else { |
| 3658 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3659 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3660 | } else { |
| 3661 | // The condition instruction has not been materialized, use its inputs as |
| 3662 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3663 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3664 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3665 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3666 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3667 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3668 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3669 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3670 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3671 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3672 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3673 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3674 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3675 | // Integer cases. |
| 3676 | Register lhs = InputRegisterAt(condition, 0); |
| 3677 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3678 | |
| 3679 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3680 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3681 | if (true_target == nullptr) { |
| 3682 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3683 | non_fallthrough_target = false_target; |
| 3684 | } else { |
| 3685 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3686 | non_fallthrough_target = true_target; |
| 3687 | } |
| 3688 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3689 | 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] | 3690 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3691 | switch (arm64_cond) { |
| 3692 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3693 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3696 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | case lt: |
| 3699 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3700 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3701 | break; |
| 3702 | case ge: |
| 3703 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3704 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3705 | break; |
| 3706 | default: |
| 3707 | // Without the `static_cast` the compiler throws an error for |
| 3708 | // `-Werror=sign-promo`. |
| 3709 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3710 | } |
| 3711 | } else { |
| 3712 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3713 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3714 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3715 | } |
| 3716 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3717 | |
| 3718 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3719 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3720 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3721 | __ B(false_target); |
| 3722 | } |
| 3723 | } |
| 3724 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3725 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3726 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3727 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3733 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3734 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3735 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3736 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3737 | true_target = nullptr; |
| 3738 | } |
| 3739 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3740 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3741 | false_target = nullptr; |
| 3742 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3743 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3747 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3748 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3749 | InvokeRuntimeCallingConvention calling_convention; |
| 3750 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3751 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3752 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3753 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3754 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3759 | SlowPathCodeARM64* slow_path = |
| 3760 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3761 | GenerateTestAndBranch(deoptimize, |
| 3762 | /* condition_input_index */ 0, |
| 3763 | slow_path->GetEntryLabel(), |
| 3764 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3767 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3768 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3769 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3770 | locations->SetOut(Location::RequiresRegister()); |
| 3771 | } |
| 3772 | |
| 3773 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3774 | __ Ldr(OutputRegister(flag), |
| 3775 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3776 | } |
| 3777 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3778 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3779 | return condition->IsCondition() && |
| 3780 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3781 | } |
| 3782 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3783 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3784 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3785 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3786 | : ARM64Condition(cond); |
| 3787 | } |
| 3788 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3789 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3790 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3791 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3792 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3793 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3794 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3795 | } else { |
| 3796 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3797 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3798 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3799 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3800 | // Ask VIXL whether we should synthesize constants in registers. |
| 3801 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3802 | Operand true_op = is_true_value_constant ? |
| 3803 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3804 | Operand false_op = is_false_value_constant ? |
| 3805 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3806 | bool true_value_in_register = false; |
| 3807 | bool false_value_in_register = false; |
| 3808 | MacroAssembler::GetCselSynthesisInformation( |
| 3809 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3810 | true_value_in_register |= !is_true_value_constant; |
| 3811 | false_value_in_register |= !is_false_value_constant; |
| 3812 | |
| 3813 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3814 | : Location::ConstantLocation(cst_true_value)); |
| 3815 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3816 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3817 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3818 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3819 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3820 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3821 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3822 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3826 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3827 | Condition csel_cond; |
| 3828 | |
| 3829 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3830 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3831 | // Use the condition flags set by the previous instruction. |
| 3832 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3833 | } else { |
| 3834 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3835 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3836 | } |
| 3837 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3838 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3839 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3840 | } else { |
| 3841 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3842 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3845 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3846 | __ Fcsel(OutputFPRegister(select), |
| 3847 | InputFPRegisterAt(select, 1), |
| 3848 | InputFPRegisterAt(select, 0), |
| 3849 | csel_cond); |
| 3850 | } else { |
| 3851 | __ Csel(OutputRegister(select), |
| 3852 | InputOperandAt(select, 1), |
| 3853 | InputOperandAt(select, 0), |
| 3854 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3855 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3858 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3859 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3860 | } |
| 3861 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3862 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3863 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | void CodeGeneratorARM64::GenerateNop() { |
| 3867 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3870 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3871 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3875 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3879 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3883 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3884 | } |
| 3885 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3886 | // Temp is used for read barrier. |
| 3887 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3888 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3889 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3890 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3891 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3892 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3893 | return 1; |
| 3894 | } |
| 3895 | return 0; |
| 3896 | } |
| 3897 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3898 | // 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] | 3899 | // interface pointer, one for loading the current interface. |
| 3900 | // The other checks have one temp for loading the object's class. |
| 3901 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3902 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3903 | return 3; |
| 3904 | } |
| 3905 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3906 | } |
| 3907 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3908 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3909 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3910 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3911 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3912 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3913 | case TypeCheckKind::kExactCheck: |
| 3914 | case TypeCheckKind::kAbstractClassCheck: |
| 3915 | case TypeCheckKind::kClassHierarchyCheck: |
| 3916 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3917 | call_kind = |
| 3918 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3919 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3920 | break; |
| 3921 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3922 | case TypeCheckKind::kUnresolvedCheck: |
| 3923 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3924 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3925 | break; |
| 3926 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3927 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3928 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3929 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3930 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3931 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3932 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3933 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3934 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3935 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3936 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3937 | // Add temps if necessary for read barriers. |
| 3938 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3942 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3943 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3944 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3945 | Register obj = InputRegisterAt(instruction, 0); |
| 3946 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3947 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3948 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3949 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3950 | DCHECK_LE(num_temps, 1u); |
| 3951 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3952 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3953 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3954 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3955 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3956 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3957 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3958 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3959 | |
| 3960 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3961 | // Avoid null check if we know `obj` is not null. |
| 3962 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3963 | __ Cbz(obj, &zero); |
| 3964 | } |
| 3965 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3966 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3967 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3968 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3969 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3970 | out_loc, |
| 3971 | obj_loc, |
| 3972 | class_offset, |
| 3973 | maybe_temp_loc, |
| 3974 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3975 | __ Cmp(out, cls); |
| 3976 | __ Cset(out, eq); |
| 3977 | if (zero.IsLinked()) { |
| 3978 | __ B(&done); |
| 3979 | } |
| 3980 | break; |
| 3981 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3982 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3983 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3984 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3985 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3986 | out_loc, |
| 3987 | obj_loc, |
| 3988 | class_offset, |
| 3989 | maybe_temp_loc, |
| 3990 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3991 | // If the class is abstract, we eagerly fetch the super class of the |
| 3992 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3993 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3994 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3995 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3996 | GenerateReferenceLoadOneRegister(instruction, |
| 3997 | out_loc, |
| 3998 | super_offset, |
| 3999 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4000 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4001 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4002 | __ Cbz(out, &done); |
| 4003 | __ Cmp(out, cls); |
| 4004 | __ B(ne, &loop); |
| 4005 | __ Mov(out, 1); |
| 4006 | if (zero.IsLinked()) { |
| 4007 | __ B(&done); |
| 4008 | } |
| 4009 | break; |
| 4010 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4011 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4012 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4013 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4014 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4015 | out_loc, |
| 4016 | obj_loc, |
| 4017 | class_offset, |
| 4018 | maybe_temp_loc, |
| 4019 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4020 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4021 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4022 | __ Bind(&loop); |
| 4023 | __ Cmp(out, cls); |
| 4024 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4025 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4026 | GenerateReferenceLoadOneRegister(instruction, |
| 4027 | out_loc, |
| 4028 | super_offset, |
| 4029 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4030 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | __ Cbnz(out, &loop); |
| 4032 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4033 | __ B(&done); |
| 4034 | __ Bind(&success); |
| 4035 | __ Mov(out, 1); |
| 4036 | if (zero.IsLinked()) { |
| 4037 | __ B(&done); |
| 4038 | } |
| 4039 | break; |
| 4040 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4041 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4042 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4043 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4044 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4045 | out_loc, |
| 4046 | obj_loc, |
| 4047 | class_offset, |
| 4048 | maybe_temp_loc, |
| 4049 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4050 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4051 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4052 | __ Cmp(out, cls); |
| 4053 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4054 | // 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] | 4055 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4056 | GenerateReferenceLoadOneRegister(instruction, |
| 4057 | out_loc, |
| 4058 | component_offset, |
| 4059 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4060 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4061 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4062 | __ Cbz(out, &done); |
| 4063 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4064 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4065 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4066 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4067 | __ Mov(out, 1); |
| 4068 | __ B(&done); |
| 4069 | break; |
| 4070 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4071 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4072 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4073 | // No read barrier since the slow path will retry upon failure. |
| 4074 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4075 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4076 | out_loc, |
| 4077 | obj_loc, |
| 4078 | class_offset, |
| 4079 | maybe_temp_loc, |
| 4080 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4081 | __ Cmp(out, cls); |
| 4082 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4083 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4084 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4085 | codegen_->AddSlowPath(slow_path); |
| 4086 | __ B(ne, slow_path->GetEntryLabel()); |
| 4087 | __ Mov(out, 1); |
| 4088 | if (zero.IsLinked()) { |
| 4089 | __ B(&done); |
| 4090 | } |
| 4091 | break; |
| 4092 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4093 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4094 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4095 | case TypeCheckKind::kInterfaceCheck: { |
| 4096 | // Note that we indeed only call on slow path, but we always go |
| 4097 | // into the slow path for the unresolved and interface check |
| 4098 | // cases. |
| 4099 | // |
| 4100 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4101 | // entry point without resorting to a type checking slow path |
| 4102 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4103 | // require to assign fixed registers for the inputs of this |
| 4104 | // HInstanceOf instruction (following the runtime calling |
| 4105 | // convention), which might be cluttered by the potential first |
| 4106 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4107 | // |
| 4108 | // TODO: Introduce a new runtime entry point taking the object |
| 4109 | // to test (instead of its class) as argument, and let it deal |
| 4110 | // with the read barrier issues. This will let us refactor this |
| 4111 | // case of the `switch` code as it was previously (with a direct |
| 4112 | // call to the runtime not using a type checking slow path). |
| 4113 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4114 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4115 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4116 | /* is_fatal */ false); |
| 4117 | codegen_->AddSlowPath(slow_path); |
| 4118 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4119 | if (zero.IsLinked()) { |
| 4120 | __ B(&done); |
| 4121 | } |
| 4122 | break; |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | if (zero.IsLinked()) { |
| 4127 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4128 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | if (done.IsLinked()) { |
| 4132 | __ Bind(&done); |
| 4133 | } |
| 4134 | |
| 4135 | if (slow_path != nullptr) { |
| 4136 | __ Bind(slow_path->GetExitLabel()); |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4141 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4142 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4143 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4144 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4145 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4146 | case TypeCheckKind::kExactCheck: |
| 4147 | case TypeCheckKind::kAbstractClassCheck: |
| 4148 | case TypeCheckKind::kClassHierarchyCheck: |
| 4149 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4150 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4151 | LocationSummary::kCallOnSlowPath : |
| 4152 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4153 | break; |
| 4154 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4155 | case TypeCheckKind::kUnresolvedCheck: |
| 4156 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4157 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4158 | break; |
| 4159 | } |
| 4160 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4161 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4162 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4163 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4164 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4165 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4169 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4170 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4171 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4172 | Register obj = InputRegisterAt(instruction, 0); |
| 4173 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4174 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4175 | DCHECK_GE(num_temps, 1u); |
| 4176 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4177 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4178 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4179 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4180 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4181 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4182 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4183 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4184 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4185 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4186 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4187 | const uint32_t object_array_data_offset = |
| 4188 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4189 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4190 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4191 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4192 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4193 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4194 | if (!kEmitCompilerReadBarrier) { |
| 4195 | is_type_check_slow_path_fatal = |
| 4196 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4197 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4198 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4199 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4200 | !instruction->CanThrowIntoCatchBlock(); |
| 4201 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4202 | SlowPathCodeARM64* type_check_slow_path = |
| 4203 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4204 | is_type_check_slow_path_fatal); |
| 4205 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4206 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4207 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4208 | // Avoid null check if we know obj is not null. |
| 4209 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4210 | __ Cbz(obj, &done); |
| 4211 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4212 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4213 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4214 | case TypeCheckKind::kExactCheck: |
| 4215 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4216 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4217 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4218 | temp_loc, |
| 4219 | obj_loc, |
| 4220 | class_offset, |
| 4221 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4222 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4223 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4224 | __ Cmp(temp, cls); |
| 4225 | // Jump to slow path for throwing the exception or doing a |
| 4226 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4227 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4228 | break; |
| 4229 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4230 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4231 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4232 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4233 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4234 | temp_loc, |
| 4235 | obj_loc, |
| 4236 | class_offset, |
| 4237 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4238 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4239 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4240 | // If the class is abstract, we eagerly fetch the super class of the |
| 4241 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4242 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4243 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4244 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4245 | GenerateReferenceLoadOneRegister(instruction, |
| 4246 | temp_loc, |
| 4247 | super_offset, |
| 4248 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4249 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4250 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4251 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4252 | // exception. |
| 4253 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4254 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4255 | __ Cmp(temp, cls); |
| 4256 | __ B(ne, &loop); |
| 4257 | break; |
| 4258 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4259 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4260 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4261 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4262 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4263 | temp_loc, |
| 4264 | obj_loc, |
| 4265 | class_offset, |
| 4266 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4267 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4268 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4269 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4270 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4271 | __ Bind(&loop); |
| 4272 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4273 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4274 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4275 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4276 | GenerateReferenceLoadOneRegister(instruction, |
| 4277 | temp_loc, |
| 4278 | super_offset, |
| 4279 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4280 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4281 | |
| 4282 | // If the class reference currently in `temp` is not null, jump |
| 4283 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4284 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4285 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4286 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4287 | break; |
| 4288 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4289 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4290 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4291 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4292 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4293 | temp_loc, |
| 4294 | obj_loc, |
| 4295 | class_offset, |
| 4296 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4297 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4298 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4299 | // Do an exact check. |
| 4300 | __ Cmp(temp, cls); |
| 4301 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4302 | |
| 4303 | // 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] | 4304 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4305 | GenerateReferenceLoadOneRegister(instruction, |
| 4306 | temp_loc, |
| 4307 | component_offset, |
| 4308 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4309 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4310 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4311 | // If the component type is null, jump to the slow path to throw the exception. |
| 4312 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4313 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4314 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4315 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4316 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4317 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4318 | break; |
| 4319 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4320 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4321 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4322 | // 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] | 4323 | // |
| 4324 | // We cannot directly call the CheckCast runtime entry point |
| 4325 | // without resorting to a type checking slow path here (i.e. by |
| 4326 | // calling InvokeRuntime directly), as it would require to |
| 4327 | // assign fixed registers for the inputs of this HInstanceOf |
| 4328 | // instruction (following the runtime calling convention), which |
| 4329 | // might be cluttered by the potential first read barrier |
| 4330 | // emission at the beginning of this method. |
| 4331 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4332 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4333 | case TypeCheckKind::kInterfaceCheck: { |
| 4334 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4335 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4336 | temp_loc, |
| 4337 | obj_loc, |
| 4338 | class_offset, |
| 4339 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4340 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4341 | |
| 4342 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4343 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4344 | temp_loc, |
| 4345 | temp_loc, |
| 4346 | iftable_offset, |
| 4347 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4348 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4349 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4350 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4351 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4352 | vixl::aarch64::Label start_loop; |
| 4353 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4354 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4355 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4356 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4357 | // Go to next interface. |
| 4358 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4359 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4360 | // Compare the classes and continue the loop if they do not match. |
| 4361 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4362 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4363 | break; |
| 4364 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4365 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4366 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4367 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4368 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4371 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4372 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4373 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4374 | } |
| 4375 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4376 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4377 | // Will be generated at use site. |
| 4378 | } |
| 4379 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4380 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4381 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4382 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4383 | } |
| 4384 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4385 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4386 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4387 | } |
| 4388 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4389 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4390 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4391 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4392 | // the method_idx. |
| 4393 | HandleInvoke(invoke); |
| 4394 | } |
| 4395 | |
| 4396 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4397 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4398 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4399 | } |
| 4400 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4401 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4402 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4403 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4406 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4407 | HandleInvoke(invoke); |
| 4408 | } |
| 4409 | |
| 4410 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4411 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4412 | LocationSummary* locations = invoke->GetLocations(); |
| 4413 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4414 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4415 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4416 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4417 | |
| 4418 | // The register ip1 is required to be used for the hidden argument in |
| 4419 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4420 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4421 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4422 | scratch_scope.Exclude(ip1); |
| 4423 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4424 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4425 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4426 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4427 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4428 | { |
| 4429 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4430 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4431 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4432 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4433 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4434 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4435 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4436 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4437 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4438 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4439 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4440 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4441 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4442 | // emit a read barrier for the previous class reference load. |
| 4443 | // However this is not required in practice, as this is an |
| 4444 | // intermediate/temporary reference and because the current |
| 4445 | // concurrent copying collector keeps the from-space memory |
| 4446 | // intact/accessible until the end of the marking phase (the |
| 4447 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4448 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4449 | __ Ldr(temp, |
| 4450 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4451 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4452 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4453 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4454 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4455 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4456 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4457 | |
| 4458 | { |
| 4459 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4460 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4461 | |
| 4462 | // lr(); |
| 4463 | __ blr(lr); |
| 4464 | DCHECK(!codegen_->IsLeafMethod()); |
| 4465 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4466 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4467 | |
| 4468 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4472 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4473 | if (intrinsic.TryDispatch(invoke)) { |
| 4474 | return; |
| 4475 | } |
| 4476 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4477 | HandleInvoke(invoke); |
| 4478 | } |
| 4479 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4480 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4481 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4482 | // art::PrepareForRegisterAllocation. |
| 4483 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4484 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4485 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4486 | if (intrinsic.TryDispatch(invoke)) { |
| 4487 | return; |
| 4488 | } |
| 4489 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4490 | HandleInvoke(invoke); |
| 4491 | } |
| 4492 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4493 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4494 | if (invoke->GetLocations()->Intrinsified()) { |
| 4495 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4496 | intrinsic.Dispatch(invoke); |
| 4497 | return true; |
| 4498 | } |
| 4499 | return false; |
| 4500 | } |
| 4501 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4502 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4503 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4504 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4505 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4506 | return desired_dispatch_info; |
| 4507 | } |
| 4508 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4509 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4510 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4511 | // 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] | 4512 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4513 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4514 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4515 | uint32_t offset = |
| 4516 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4517 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4518 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4520 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4521 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4522 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4523 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4524 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4525 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4526 | // Add ADRP with its PC-relative method patch. |
| 4527 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4528 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4529 | // Add ADD with its PC-relative method patch. |
| 4530 | vixl::aarch64::Label* add_label = |
| 4531 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4532 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4533 | break; |
| 4534 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4535 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4536 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4537 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4538 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4539 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4540 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4541 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4542 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4543 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4544 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4545 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4546 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4547 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4548 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4549 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4550 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4551 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4552 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | switch (invoke->GetCodePtrLocation()) { |
| 4557 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4558 | { |
| 4559 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4560 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4561 | kInstructionSize, |
| 4562 | CodeBufferCheckScope::kExactSize); |
| 4563 | __ bl(&frame_entry_label_); |
| 4564 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4565 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4566 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4567 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4568 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4569 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4570 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4571 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4572 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4573 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4574 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4575 | kInstructionSize, |
| 4576 | CodeBufferCheckScope::kExactSize); |
| 4577 | // lr() |
| 4578 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4579 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4580 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4581 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4582 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4583 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4584 | DCHECK(!IsLeafMethod()); |
| 4585 | } |
| 4586 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4587 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4588 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4589 | // Use the calling convention instead of the location of the receiver, as |
| 4590 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4591 | // slow path, the arguments have been moved to the right place, so here we are |
| 4592 | // guaranteed that the receiver is the first register of the calling convention. |
| 4593 | InvokeDexCallingConvention calling_convention; |
| 4594 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4595 | Register temp = XRegisterFrom(temp_in); |
| 4596 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4597 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4598 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4599 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4600 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4601 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4602 | |
| 4603 | { |
| 4604 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4605 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4606 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4607 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4608 | MaybeRecordImplicitNullCheck(invoke); |
| 4609 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4610 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4611 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4612 | // intermediate/temporary reference and because the current |
| 4613 | // concurrent copying collector keeps the from-space memory |
| 4614 | // intact/accessible until the end of the marking phase (the |
| 4615 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4616 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4617 | // temp = temp->GetMethodAt(method_offset); |
| 4618 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4619 | // lr = temp->GetEntryPoint(); |
| 4620 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4621 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4622 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4623 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4624 | // lr(); |
| 4625 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4626 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4627 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4630 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4631 | HandleInvoke(invoke); |
| 4632 | } |
| 4633 | |
| 4634 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4635 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4636 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4639 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4640 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4641 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4642 | return NewPcRelativePatch(*target_method.dex_file, |
| 4643 | target_method.dex_method_index, |
| 4644 | adrp_label, |
| 4645 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4648 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4649 | MethodReference target_method, |
| 4650 | vixl::aarch64::Label* adrp_label) { |
| 4651 | return NewPcRelativePatch(*target_method.dex_file, |
| 4652 | target_method.dex_method_index, |
| 4653 | adrp_label, |
| 4654 | &method_bss_entry_patches_); |
| 4655 | } |
| 4656 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4657 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4658 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4659 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4660 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4661 | 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] | 4662 | } |
| 4663 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4664 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4665 | const DexFile& dex_file, |
| 4666 | dex::TypeIndex type_index, |
| 4667 | vixl::aarch64::Label* adrp_label) { |
| 4668 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4669 | } |
| 4670 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4671 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4672 | const DexFile& dex_file, |
| 4673 | dex::StringIndex string_index, |
| 4674 | vixl::aarch64::Label* adrp_label) { |
| 4675 | return |
| 4676 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4677 | } |
| 4678 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4679 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4680 | const DexFile& dex_file, |
| 4681 | dex::StringIndex string_index, |
| 4682 | vixl::aarch64::Label* adrp_label) { |
| 4683 | return NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
| 4684 | } |
| 4685 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4686 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4687 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4688 | return &baker_read_barrier_patches_.back().label; |
| 4689 | } |
| 4690 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4691 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4692 | const DexFile& dex_file, |
| 4693 | uint32_t offset_or_index, |
| 4694 | vixl::aarch64::Label* adrp_label, |
| 4695 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4696 | // Add a patch entry and return the label. |
| 4697 | patches->emplace_back(dex_file, offset_or_index); |
| 4698 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4699 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4700 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4701 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4702 | return label; |
| 4703 | } |
| 4704 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4705 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4706 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4707 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4710 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4711 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4712 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4713 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4714 | return jit_string_patches_.GetOrCreate( |
| 4715 | StringReference(&dex_file, string_index), |
| 4716 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4717 | } |
| 4718 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4719 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4720 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4721 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4722 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4723 | return jit_class_patches_.GetOrCreate( |
| 4724 | TypeReference(&dex_file, type_index), |
| 4725 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4726 | } |
| 4727 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4728 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4729 | vixl::aarch64::Register reg) { |
| 4730 | DCHECK(reg.IsX()); |
| 4731 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4732 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4733 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4734 | } |
| 4735 | |
| 4736 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4737 | vixl::aarch64::Register out, |
| 4738 | vixl::aarch64::Register base) { |
| 4739 | DCHECK(out.IsX()); |
| 4740 | DCHECK(base.IsX()); |
| 4741 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4742 | __ Bind(fixup_label); |
| 4743 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4744 | } |
| 4745 | |
| 4746 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4747 | vixl::aarch64::Register out, |
| 4748 | vixl::aarch64::Register base) { |
| 4749 | DCHECK(base.IsX()); |
| 4750 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4751 | __ Bind(fixup_label); |
| 4752 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4753 | } |
| 4754 | |
| 4755 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4756 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4757 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4758 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4759 | for (const PcRelativePatchInfo& info : infos) { |
| 4760 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4761 | &info.target_dex_file, |
| 4762 | info.pc_insn_label->GetLocation(), |
| 4763 | info.offset_or_index)); |
| 4764 | } |
| 4765 | } |
| 4766 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4767 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4768 | DCHECK(linker_patches->empty()); |
| 4769 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4770 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4771 | method_bss_entry_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4772 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4773 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4774 | pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4775 | string_bss_entry_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4776 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4777 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4778 | if (GetCompilerOptions().IsBootImage()) { |
| 4779 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4780 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4781 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4782 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4783 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4784 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4785 | } else { |
| 4786 | DCHECK(pc_relative_method_patches_.empty()); |
| 4787 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4788 | EmitPcRelativeLinkerPatches<LinkerPatch::StringInternTablePatch>(pc_relative_string_patches_, |
| 4789 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4790 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4791 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 4792 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4793 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4794 | linker_patches); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4795 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_bss_entry_patches_, |
| 4796 | linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4797 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 4798 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 4799 | info.custom_data)); |
| 4800 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4801 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4804 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4805 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4806 | value, |
| 4807 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4808 | } |
| 4809 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4810 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4811 | return uint64_literals_.GetOrCreate( |
| 4812 | value, |
| 4813 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4814 | } |
| 4815 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4816 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4817 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4818 | // art::PrepareForRegisterAllocation. |
| 4819 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4820 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4821 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4822 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4823 | return; |
| 4824 | } |
| 4825 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4826 | { |
| 4827 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4828 | // are no pools emitted. |
| 4829 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4830 | LocationSummary* locations = invoke->GetLocations(); |
| 4831 | codegen_->GenerateStaticOrDirectCall( |
| 4832 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4833 | } |
| 4834 | |
| 4835 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4836 | } |
| 4837 | |
| 4838 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4839 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4840 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4841 | return; |
| 4842 | } |
| 4843 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4844 | { |
| 4845 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4846 | // are no pools emitted. |
| 4847 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4848 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4849 | DCHECK(!codegen_->IsLeafMethod()); |
| 4850 | } |
| 4851 | |
| 4852 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4853 | } |
| 4854 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4855 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4856 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4857 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4858 | case HLoadClass::LoadKind::kInvalid: |
| 4859 | LOG(FATAL) << "UNREACHABLE"; |
| 4860 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4861 | case HLoadClass::LoadKind::kReferrersClass: |
| 4862 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4863 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4864 | case HLoadClass::LoadKind::kBssEntry: |
| 4865 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4866 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4867 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4868 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4869 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4870 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4871 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4872 | break; |
| 4873 | } |
| 4874 | return desired_class_load_kind; |
| 4875 | } |
| 4876 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4877 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4878 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4879 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4880 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4881 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4882 | cls, |
| 4883 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4884 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4885 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4886 | return; |
| 4887 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4888 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4889 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4890 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4891 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4892 | ? LocationSummary::kCallOnSlowPath |
| 4893 | : LocationSummary::kNoCall; |
| 4894 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4895 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4896 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4897 | } |
| 4898 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4899 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4900 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4901 | } |
| 4902 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4903 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4904 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4905 | // 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] | 4906 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4907 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4908 | InvokeRuntimeCallingConvention calling_convention; |
| 4909 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4910 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4911 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4912 | Primitive::kPrimNot).GetCode()); |
| 4913 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4914 | } else { |
| 4915 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4916 | } |
| 4917 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4918 | } |
| 4919 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4920 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4921 | // move. |
| 4922 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4923 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4924 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4925 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4926 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4927 | return; |
| 4928 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4929 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4930 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4931 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4932 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4933 | Register bss_entry_temp; |
| 4934 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4935 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4936 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4937 | ? kWithoutReadBarrier |
| 4938 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4939 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4940 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4941 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4942 | DCHECK(!cls->CanCallRuntime()); |
| 4943 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4944 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4945 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4946 | GenerateGcRootFieldLoad(cls, |
| 4947 | out_loc, |
| 4948 | current_method, |
| 4949 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4950 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4951 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4952 | break; |
| 4953 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4954 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4955 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4956 | // Add ADRP with its PC-relative type patch. |
| 4957 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4958 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4959 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4960 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4961 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4962 | vixl::aarch64::Label* add_label = |
| 4963 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4964 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4965 | break; |
| 4966 | } |
| 4967 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4968 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4969 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4970 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4971 | DCHECK_NE(address, 0u); |
| 4972 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4973 | break; |
| 4974 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4975 | case HLoadClass::LoadKind::kBssEntry: { |
| 4976 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4977 | const DexFile& dex_file = cls->GetDexFile(); |
| 4978 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4979 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4980 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4981 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4982 | // Add LDR with its PC-relative Class patch. |
| 4983 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4984 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4985 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4986 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4987 | out_loc, |
| 4988 | bss_entry_temp, |
| 4989 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4990 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4991 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4992 | generate_null_check = true; |
| 4993 | break; |
| 4994 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4995 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4996 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4997 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4998 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4999 | GenerateGcRootFieldLoad(cls, |
| 5000 | out_loc, |
| 5001 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5002 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5003 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5004 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5005 | break; |
| 5006 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5007 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5008 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5009 | LOG(FATAL) << "UNREACHABLE"; |
| 5010 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5011 | } |
| 5012 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5013 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5014 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5015 | DCHECK(cls->CanCallRuntime()); |
| 5016 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5017 | 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] | 5018 | codegen_->AddSlowPath(slow_path); |
| 5019 | if (generate_null_check) { |
| 5020 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5021 | } |
| 5022 | if (cls->MustGenerateClinitCheck()) { |
| 5023 | GenerateClassInitializationCheck(slow_path, out); |
| 5024 | } else { |
| 5025 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5026 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5027 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5028 | } |
| 5029 | } |
| 5030 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5031 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5032 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5033 | } |
| 5034 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5035 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5036 | LocationSummary* locations = |
| 5037 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5038 | locations->SetOut(Location::RequiresRegister()); |
| 5039 | } |
| 5040 | |
| 5041 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5042 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5043 | } |
| 5044 | |
| 5045 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5046 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5047 | } |
| 5048 | |
| 5049 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5050 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5053 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5054 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5055 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5056 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5057 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5058 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5059 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5060 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5061 | case HLoadString::LoadKind::kJitTableAddress: |
| 5062 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5063 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5064 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5065 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5066 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5067 | } |
| 5068 | return desired_string_load_kind; |
| 5069 | } |
| 5070 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5071 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5072 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5073 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5074 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5075 | InvokeRuntimeCallingConvention calling_convention; |
| 5076 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5077 | } else { |
| 5078 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5079 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5080 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5081 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5082 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5083 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5084 | InvokeRuntimeCallingConvention calling_convention; |
| 5085 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5086 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5087 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5088 | Primitive::kPrimNot).GetCode()); |
| 5089 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5090 | } else { |
| 5091 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5092 | } |
| 5093 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5094 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5095 | } |
| 5096 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5097 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5098 | // move. |
| 5099 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5100 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5101 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5102 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5103 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5104 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5105 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5106 | // Add ADRP with its PC-relative String patch. |
| 5107 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5108 | const dex::StringIndex string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5109 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5110 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5111 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5112 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5113 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5114 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5115 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5116 | } |
| 5117 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5118 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5119 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5120 | DCHECK_NE(address, 0u); |
| 5121 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5122 | return; |
| 5123 | } |
| 5124 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5125 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5126 | // Add ADRP with its PC-relative String patch. |
| 5127 | const DexFile& dex_file = load->GetDexFile(); |
| 5128 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 5129 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 5130 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 5131 | // Add LDR with its PC-relative String patch. |
| 5132 | vixl::aarch64::Label* ldr_label = |
| 5133 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 5134 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5135 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5136 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5137 | case HLoadString::LoadKind::kBssEntry: { |
| 5138 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5139 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5140 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5141 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5142 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5143 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5144 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5145 | // Add LDR with its .bss entry String patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5146 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 5147 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5148 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5149 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5150 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5151 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5152 | /* offset placeholder */ 0u, |
| 5153 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5154 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5155 | SlowPathCodeARM64* slow_path = |
| 5156 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5157 | codegen_->AddSlowPath(slow_path); |
| 5158 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5159 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5160 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5161 | return; |
| 5162 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5163 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5164 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5165 | load->GetStringIndex(), |
| 5166 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5167 | GenerateGcRootFieldLoad(load, |
| 5168 | out_loc, |
| 5169 | out.X(), |
| 5170 | /* offset */ 0, |
| 5171 | /* fixup_label */ nullptr, |
| 5172 | kCompilerReadBarrierOption); |
| 5173 | return; |
| 5174 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5175 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5176 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5177 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5178 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5179 | // 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] | 5180 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5181 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5182 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5183 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5184 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5185 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5186 | } |
| 5187 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5188 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5189 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5190 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5191 | } |
| 5192 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5193 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5194 | // Will be generated at use site. |
| 5195 | } |
| 5196 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5197 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5198 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5199 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5200 | InvokeRuntimeCallingConvention calling_convention; |
| 5201 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5202 | } |
| 5203 | |
| 5204 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5205 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5206 | instruction, |
| 5207 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5208 | if (instruction->IsEnter()) { |
| 5209 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5210 | } else { |
| 5211 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5212 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5213 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5216 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5217 | LocationSummary* locations = |
| 5218 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5219 | switch (mul->GetResultType()) { |
| 5220 | case Primitive::kPrimInt: |
| 5221 | case Primitive::kPrimLong: |
| 5222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5223 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5224 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5225 | break; |
| 5226 | |
| 5227 | case Primitive::kPrimFloat: |
| 5228 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5229 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5230 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5231 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5232 | break; |
| 5233 | |
| 5234 | default: |
| 5235 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5240 | switch (mul->GetResultType()) { |
| 5241 | case Primitive::kPrimInt: |
| 5242 | case Primitive::kPrimLong: |
| 5243 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5244 | break; |
| 5245 | |
| 5246 | case Primitive::kPrimFloat: |
| 5247 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5248 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5249 | break; |
| 5250 | |
| 5251 | default: |
| 5252 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5253 | } |
| 5254 | } |
| 5255 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5256 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5257 | LocationSummary* locations = |
| 5258 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5259 | switch (neg->GetResultType()) { |
| 5260 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5261 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5262 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5264 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5265 | |
| 5266 | case Primitive::kPrimFloat: |
| 5267 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5269 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5270 | break; |
| 5271 | |
| 5272 | default: |
| 5273 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5278 | switch (neg->GetResultType()) { |
| 5279 | case Primitive::kPrimInt: |
| 5280 | case Primitive::kPrimLong: |
| 5281 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5282 | break; |
| 5283 | |
| 5284 | case Primitive::kPrimFloat: |
| 5285 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5286 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5287 | break; |
| 5288 | |
| 5289 | default: |
| 5290 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5291 | } |
| 5292 | } |
| 5293 | |
| 5294 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5295 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5296 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5297 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5298 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5299 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5300 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5304 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5305 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5306 | QuickEntrypointEnum entrypoint = |
| 5307 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5308 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5309 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5310 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5313 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5314 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5315 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5316 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5317 | if (instruction->IsStringAlloc()) { |
| 5318 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5319 | } else { |
| 5320 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5321 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5322 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5323 | } |
| 5324 | |
| 5325 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* 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. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5328 | if (instruction->IsStringAlloc()) { |
| 5329 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5330 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5331 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5332 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5333 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5334 | |
| 5335 | { |
| 5336 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5337 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5338 | kInstructionSize, |
| 5339 | CodeBufferCheckScope::kExactSize); |
| 5340 | __ blr(lr); |
| 5341 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5342 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5343 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5344 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5345 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5346 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5347 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5351 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5352 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5357 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5358 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5359 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5360 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5361 | break; |
| 5362 | |
| 5363 | default: |
| 5364 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5365 | } |
| 5366 | } |
| 5367 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5368 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5369 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5370 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5371 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5372 | } |
| 5373 | |
| 5374 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5375 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5378 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5379 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5380 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5381 | } |
| 5382 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5383 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5384 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5385 | return; |
| 5386 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5387 | { |
| 5388 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5389 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5390 | Location obj = instruction->GetLocations()->InAt(0); |
| 5391 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5392 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5393 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5394 | } |
| 5395 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5396 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5397 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5398 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5399 | |
| 5400 | LocationSummary* locations = instruction->GetLocations(); |
| 5401 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5402 | |
| 5403 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5404 | } |
| 5405 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5406 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5407 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5410 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5411 | HandleBinaryOp(instruction); |
| 5412 | } |
| 5413 | |
| 5414 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5415 | HandleBinaryOp(instruction); |
| 5416 | } |
| 5417 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5418 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5419 | LOG(FATAL) << "Unreachable"; |
| 5420 | } |
| 5421 | |
| 5422 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5423 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5424 | } |
| 5425 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5426 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5427 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5428 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5429 | if (location.IsStackSlot()) { |
| 5430 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5431 | } else if (location.IsDoubleStackSlot()) { |
| 5432 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5433 | } |
| 5434 | locations->SetOut(location); |
| 5435 | } |
| 5436 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5437 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5438 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5439 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5443 | LocationSummary* locations = |
| 5444 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5445 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5449 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5450 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5454 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5455 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5456 | locations->SetInAt(i, Location::Any()); |
| 5457 | } |
| 5458 | locations->SetOut(Location::Any()); |
| 5459 | } |
| 5460 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5461 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5462 | LOG(FATAL) << "Unreachable"; |
| 5463 | } |
| 5464 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5465 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5466 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5467 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5468 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5469 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5470 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5471 | |
| 5472 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5473 | case Primitive::kPrimInt: |
| 5474 | case Primitive::kPrimLong: |
| 5475 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5476 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5477 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5478 | break; |
| 5479 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5480 | case Primitive::kPrimFloat: |
| 5481 | case Primitive::kPrimDouble: { |
| 5482 | InvokeRuntimeCallingConvention calling_convention; |
| 5483 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5484 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5485 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5486 | |
| 5487 | break; |
| 5488 | } |
| 5489 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5490 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5491 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5492 | } |
| 5493 | } |
| 5494 | |
| 5495 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5496 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5497 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5498 | switch (type) { |
| 5499 | case Primitive::kPrimInt: |
| 5500 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5501 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5502 | break; |
| 5503 | } |
| 5504 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5505 | case Primitive::kPrimFloat: |
| 5506 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5507 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5508 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5509 | if (type == Primitive::kPrimFloat) { |
| 5510 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5511 | } else { |
| 5512 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5513 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5514 | break; |
| 5515 | } |
| 5516 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5517 | default: |
| 5518 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5519 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5520 | } |
| 5521 | } |
| 5522 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5523 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5524 | constructor_fence->SetLocations(nullptr); |
| 5525 | } |
| 5526 | |
| 5527 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5528 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5529 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5530 | } |
| 5531 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5532 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5533 | memory_barrier->SetLocations(nullptr); |
| 5534 | } |
| 5535 | |
| 5536 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5537 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5538 | } |
| 5539 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5540 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5541 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5542 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5543 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5544 | } |
| 5545 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5546 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5547 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5551 | instruction->SetLocations(nullptr); |
| 5552 | } |
| 5553 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5554 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5555 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5556 | } |
| 5557 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5558 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5559 | HandleBinaryOp(ror); |
| 5560 | } |
| 5561 | |
| 5562 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5563 | HandleBinaryOp(ror); |
| 5564 | } |
| 5565 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5566 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5567 | HandleShift(shl); |
| 5568 | } |
| 5569 | |
| 5570 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5571 | HandleShift(shl); |
| 5572 | } |
| 5573 | |
| 5574 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5575 | HandleShift(shr); |
| 5576 | } |
| 5577 | |
| 5578 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5579 | HandleShift(shr); |
| 5580 | } |
| 5581 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5582 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5583 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5587 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5588 | } |
| 5589 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5590 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5591 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5595 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5599 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5600 | } |
| 5601 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5602 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5603 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5604 | } |
| 5605 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5606 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5607 | HUnresolvedInstanceFieldGet* instruction) { |
| 5608 | FieldAccessCallingConventionARM64 calling_convention; |
| 5609 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5610 | instruction, instruction->GetFieldType(), calling_convention); |
| 5611 | } |
| 5612 | |
| 5613 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5614 | HUnresolvedInstanceFieldGet* instruction) { |
| 5615 | FieldAccessCallingConventionARM64 calling_convention; |
| 5616 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5617 | instruction->GetFieldType(), |
| 5618 | instruction->GetFieldIndex(), |
| 5619 | instruction->GetDexPc(), |
| 5620 | calling_convention); |
| 5621 | } |
| 5622 | |
| 5623 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5624 | HUnresolvedInstanceFieldSet* instruction) { |
| 5625 | FieldAccessCallingConventionARM64 calling_convention; |
| 5626 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5627 | instruction, instruction->GetFieldType(), calling_convention); |
| 5628 | } |
| 5629 | |
| 5630 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5631 | HUnresolvedInstanceFieldSet* instruction) { |
| 5632 | FieldAccessCallingConventionARM64 calling_convention; |
| 5633 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5634 | instruction->GetFieldType(), |
| 5635 | instruction->GetFieldIndex(), |
| 5636 | instruction->GetDexPc(), |
| 5637 | calling_convention); |
| 5638 | } |
| 5639 | |
| 5640 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5641 | HUnresolvedStaticFieldGet* instruction) { |
| 5642 | FieldAccessCallingConventionARM64 calling_convention; |
| 5643 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5644 | instruction, instruction->GetFieldType(), calling_convention); |
| 5645 | } |
| 5646 | |
| 5647 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5648 | HUnresolvedStaticFieldGet* instruction) { |
| 5649 | FieldAccessCallingConventionARM64 calling_convention; |
| 5650 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5651 | instruction->GetFieldType(), |
| 5652 | instruction->GetFieldIndex(), |
| 5653 | instruction->GetDexPc(), |
| 5654 | calling_convention); |
| 5655 | } |
| 5656 | |
| 5657 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5658 | HUnresolvedStaticFieldSet* instruction) { |
| 5659 | FieldAccessCallingConventionARM64 calling_convention; |
| 5660 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5661 | instruction, instruction->GetFieldType(), calling_convention); |
| 5662 | } |
| 5663 | |
| 5664 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5665 | HUnresolvedStaticFieldSet* instruction) { |
| 5666 | FieldAccessCallingConventionARM64 calling_convention; |
| 5667 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5668 | instruction->GetFieldType(), |
| 5669 | instruction->GetFieldIndex(), |
| 5670 | instruction->GetDexPc(), |
| 5671 | calling_convention); |
| 5672 | } |
| 5673 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5674 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5675 | LocationSummary* locations = |
| 5676 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5677 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5678 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5679 | // registers in full width (since the runtime only saves/restores lower part). |
| 5680 | locations->SetCustomSlowPathCallerSaves( |
| 5681 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5685 | HBasicBlock* block = instruction->GetBlock(); |
| 5686 | if (block->GetLoopInformation() != nullptr) { |
| 5687 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5688 | // The back edge will generate the suspend check. |
| 5689 | return; |
| 5690 | } |
| 5691 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5692 | // The goto will generate the suspend check. |
| 5693 | return; |
| 5694 | } |
| 5695 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5696 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5697 | } |
| 5698 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5699 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5700 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5701 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5702 | InvokeRuntimeCallingConvention calling_convention; |
| 5703 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5704 | } |
| 5705 | |
| 5706 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5707 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5708 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5712 | LocationSummary* locations = |
| 5713 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5714 | Primitive::Type input_type = conversion->GetInputType(); |
| 5715 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5716 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5717 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5718 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5719 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5720 | } |
| 5721 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5722 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5723 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5724 | } else { |
| 5725 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5726 | } |
| 5727 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5728 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5729 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5730 | } else { |
| 5731 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5736 | Primitive::Type result_type = conversion->GetResultType(); |
| 5737 | Primitive::Type input_type = conversion->GetInputType(); |
| 5738 | |
| 5739 | DCHECK_NE(input_type, result_type); |
| 5740 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5741 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5742 | int result_size = Primitive::ComponentSize(result_type); |
| 5743 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5744 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5745 | Register output = OutputRegister(conversion); |
| 5746 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5747 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5748 | // 'int' values are used directly as W registers, discarding the top |
| 5749 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5750 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5751 | // top 32 bits of the target register. We theoretically could leave those |
| 5752 | // bits unchanged, but we would have to make sure that no code uses a |
| 5753 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5754 | // zero. |
| 5755 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5756 | } else if (result_type == Primitive::kPrimChar || |
| 5757 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5758 | __ Ubfx(output, |
| 5759 | output.IsX() ? source.X() : source.W(), |
| 5760 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5761 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5762 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5763 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5764 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5765 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5766 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5767 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5768 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5769 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5770 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5771 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5772 | } else { |
| 5773 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5774 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5775 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5776 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5777 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5778 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5779 | HandleShift(ushr); |
| 5780 | } |
| 5781 | |
| 5782 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5783 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5787 | HandleBinaryOp(instruction); |
| 5788 | } |
| 5789 | |
| 5790 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5791 | HandleBinaryOp(instruction); |
| 5792 | } |
| 5793 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5794 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5795 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5796 | LOG(FATAL) << "Unreachable"; |
| 5797 | } |
| 5798 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5799 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5800 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5801 | LOG(FATAL) << "Unreachable"; |
| 5802 | } |
| 5803 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5804 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5805 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5806 | LocationSummary* locations = |
| 5807 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5808 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5809 | } |
| 5810 | |
| 5811 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5812 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5813 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5814 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5815 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5816 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5817 | // 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] | 5818 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5819 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5820 | // make sure we don't emit it if the target may run out of range. |
| 5821 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5822 | // ranges and emit the tables only as required. |
| 5823 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5824 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5825 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5826 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5827 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5828 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5829 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5830 | Register temp = temps.AcquireW(); |
| 5831 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5832 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5833 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5834 | // Jump to successors[0] if value == lower_bound. |
| 5835 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5836 | int32_t last_index = 0; |
| 5837 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5838 | __ Subs(temp, temp, Operand(2)); |
| 5839 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5840 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5841 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5842 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5843 | } |
| 5844 | if (num_entries - last_index == 2) { |
| 5845 | // The last missing case_value. |
| 5846 | __ Cmp(temp, Operand(1)); |
| 5847 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | // And the default for any other value. |
| 5851 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5852 | __ B(codegen_->GetLabelOf(default_block)); |
| 5853 | } |
| 5854 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5855 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5856 | |
| 5857 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5858 | |
| 5859 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5860 | // registers, we are free to block one. |
| 5861 | Register temp_w = temps.AcquireW(); |
| 5862 | Register index; |
| 5863 | // Remove the bias. |
| 5864 | if (lower_bound != 0) { |
| 5865 | index = temp_w; |
| 5866 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5867 | } else { |
| 5868 | index = value_reg; |
| 5869 | } |
| 5870 | |
| 5871 | // Jump to default block if index is out of the range. |
| 5872 | __ Cmp(index, Operand(num_entries)); |
| 5873 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5874 | |
| 5875 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5876 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5877 | // register pressure. |
| 5878 | Register table_base = temps.AcquireX(); |
| 5879 | // Load jump offset from the table. |
| 5880 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5881 | Register jump_offset = temp_w; |
| 5882 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5883 | |
| 5884 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5885 | Register target_address = table_base; |
| 5886 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5887 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5888 | } |
| 5889 | } |
| 5890 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5891 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5892 | HInstruction* instruction, |
| 5893 | Location out, |
| 5894 | uint32_t offset, |
| 5895 | Location maybe_temp, |
| 5896 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5897 | Primitive::Type type = Primitive::kPrimNot; |
| 5898 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5899 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5900 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5901 | if (kUseBakerReadBarrier) { |
| 5902 | // Load with fast path based Baker's read barrier. |
| 5903 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5904 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5905 | out, |
| 5906 | out_reg, |
| 5907 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5908 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5909 | /* needs_null_check */ false, |
| 5910 | /* use_load_acquire */ false); |
| 5911 | } else { |
| 5912 | // Load with slow path based read barrier. |
| 5913 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5914 | // in the following move operation, as we will need it for the |
| 5915 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5916 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5917 | __ Mov(temp_reg, out_reg); |
| 5918 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5919 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5920 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5921 | } |
| 5922 | } else { |
| 5923 | // Plain load with no read barrier. |
| 5924 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5925 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5926 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5927 | } |
| 5928 | } |
| 5929 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5930 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5931 | HInstruction* instruction, |
| 5932 | Location out, |
| 5933 | Location obj, |
| 5934 | uint32_t offset, |
| 5935 | Location maybe_temp, |
| 5936 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5937 | Primitive::Type type = Primitive::kPrimNot; |
| 5938 | Register out_reg = RegisterFrom(out, type); |
| 5939 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5940 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5941 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5942 | if (kUseBakerReadBarrier) { |
| 5943 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5944 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5945 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5946 | out, |
| 5947 | obj_reg, |
| 5948 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5949 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5950 | /* needs_null_check */ false, |
| 5951 | /* use_load_acquire */ false); |
| 5952 | } else { |
| 5953 | // Load with slow path based read barrier. |
| 5954 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5955 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5956 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5957 | } |
| 5958 | } else { |
| 5959 | // Plain load with no read barrier. |
| 5960 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5961 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5962 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5963 | } |
| 5964 | } |
| 5965 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5966 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5967 | HInstruction* instruction, |
| 5968 | Location root, |
| 5969 | Register obj, |
| 5970 | uint32_t offset, |
| 5971 | vixl::aarch64::Label* fixup_label, |
| 5972 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5973 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5974 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5975 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5976 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5977 | if (kUseBakerReadBarrier) { |
| 5978 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5979 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5980 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 5981 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5982 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 5983 | // the Marking Register) to decide whether we need to enter |
| 5984 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5985 | // |
| 5986 | // We use link-time generated thunks for the slow path. That thunk |
| 5987 | // checks the reference and jumps to the entrypoint if needed. |
| 5988 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5989 | // lr = &return_address; |
| 5990 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5991 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 5992 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5993 | // } |
| 5994 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5995 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5996 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5997 | DCHECK(temps.IsAvailable(ip0)); |
| 5998 | DCHECK(temps.IsAvailable(ip1)); |
| 5999 | temps.Exclude(ip0, ip1); |
| 6000 | uint32_t custom_data = |
| 6001 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 6002 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6003 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6004 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6005 | vixl::aarch64::Label return_address; |
| 6006 | __ adr(lr, &return_address); |
| 6007 | if (fixup_label != nullptr) { |
| 6008 | __ Bind(fixup_label); |
| 6009 | } |
| 6010 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6011 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6012 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6013 | __ Bind(cbnz_label); |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6014 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6015 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6016 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6017 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6018 | // the Marking Register) to decide whether we need to enter |
| 6019 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6020 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6021 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6022 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6023 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6024 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6025 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6026 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6027 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6028 | // Slow path marking the GC root `root`. The entrypoint will |
| 6029 | // be loaded by the slow path code. |
| 6030 | SlowPathCodeARM64* slow_path = |
| 6031 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6032 | codegen_->AddSlowPath(slow_path); |
| 6033 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6034 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6035 | if (fixup_label == nullptr) { |
| 6036 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6037 | } else { |
| 6038 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6039 | } |
| 6040 | static_assert( |
| 6041 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6042 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6043 | "have different sizes."); |
| 6044 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6045 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6046 | "have different sizes."); |
| 6047 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6048 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6049 | __ Bind(slow_path->GetExitLabel()); |
| 6050 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6051 | } else { |
| 6052 | // GC root loaded through a slow path for read barriers other |
| 6053 | // than Baker's. |
| 6054 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6055 | if (fixup_label == nullptr) { |
| 6056 | __ Add(root_reg.X(), obj.X(), offset); |
| 6057 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6058 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6059 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6060 | // /* mirror::Object* */ root = root->Read() |
| 6061 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6062 | } |
| 6063 | } else { |
| 6064 | // Plain GC root load with no read barrier. |
| 6065 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6066 | if (fixup_label == nullptr) { |
| 6067 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6068 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6069 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6070 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6071 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6072 | // do not have to unpoison `root_reg` here. |
| 6073 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6074 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6078 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6079 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6080 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6081 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6082 | bool needs_null_check, |
| 6083 | bool use_load_acquire) { |
| 6084 | DCHECK(kEmitCompilerReadBarrier); |
| 6085 | DCHECK(kUseBakerReadBarrier); |
| 6086 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6087 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6088 | !use_load_acquire && |
| 6089 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6090 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6091 | // Marking Register) to decide whether we need to enter the slow |
| 6092 | // path to mark the reference. Then, in the slow path, check the |
| 6093 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6094 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6095 | // |
| 6096 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6097 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6098 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6099 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6100 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6101 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6102 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6103 | // } |
| 6104 | // not_gray_return_address: |
| 6105 | // // Original reference load. If the offset is too large to fit |
| 6106 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6107 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6108 | // gray_return_address: |
| 6109 | |
| 6110 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6111 | Register base = obj; |
| 6112 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6113 | DCHECK(maybe_temp.IsRegister()); |
| 6114 | base = WRegisterFrom(maybe_temp); |
| 6115 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6116 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6117 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6118 | } |
| 6119 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6120 | DCHECK(temps.IsAvailable(ip0)); |
| 6121 | DCHECK(temps.IsAvailable(ip1)); |
| 6122 | temps.Exclude(ip0, ip1); |
| 6123 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6124 | base.GetCode(), |
| 6125 | obj.GetCode()); |
| 6126 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6127 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6128 | { |
| 6129 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6130 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6131 | vixl::aarch64::Label return_address; |
| 6132 | __ adr(lr, &return_address); |
| 6133 | __ Bind(cbnz_label); |
| 6134 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6135 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6136 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6137 | " 2 instructions (8B) for heap poisoning."); |
| 6138 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6139 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6140 | if (needs_null_check) { |
| 6141 | MaybeRecordImplicitNullCheck(instruction); |
| 6142 | } |
| 6143 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6144 | __ Bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6145 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6146 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6147 | return; |
| 6148 | } |
| 6149 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6150 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6151 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6152 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6153 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6154 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6155 | ref, |
| 6156 | obj, |
| 6157 | offset, |
| 6158 | no_index, |
| 6159 | no_scale_factor, |
| 6160 | temp, |
| 6161 | needs_null_check, |
| 6162 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6166 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6167 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6168 | uint32_t data_offset, |
| 6169 | Location index, |
| 6170 | Register temp, |
| 6171 | bool needs_null_check) { |
| 6172 | DCHECK(kEmitCompilerReadBarrier); |
| 6173 | DCHECK(kUseBakerReadBarrier); |
| 6174 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6175 | static_assert( |
| 6176 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6177 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6178 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6179 | |
| 6180 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6181 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6182 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6183 | // Marking Register) to decide whether we need to enter the slow |
| 6184 | // path to mark the reference. Then, in the slow path, check the |
| 6185 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6186 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6187 | // |
| 6188 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6189 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6190 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6191 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6192 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6193 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6194 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6195 | // } |
| 6196 | // not_gray_return_address: |
| 6197 | // // Original reference load. If the offset is too large to fit |
| 6198 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6199 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6200 | // gray_return_address: |
| 6201 | |
| 6202 | DCHECK(index.IsValid()); |
| 6203 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 6204 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6205 | |
| 6206 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6207 | DCHECK(temps.IsAvailable(ip0)); |
| 6208 | DCHECK(temps.IsAvailable(ip1)); |
| 6209 | temps.Exclude(ip0, ip1); |
| 6210 | uint32_t custom_data = |
| 6211 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6212 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6213 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6214 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6215 | { |
| 6216 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6217 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6218 | vixl::aarch64::Label return_address; |
| 6219 | __ adr(lr, &return_address); |
| 6220 | __ Bind(cbnz_label); |
| 6221 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6222 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6223 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6224 | " 2 instructions (8B) for heap poisoning."); |
| 6225 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6226 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6227 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6228 | __ Bind(&return_address); |
| 6229 | } |
| 6230 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6231 | return; |
| 6232 | } |
| 6233 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6234 | // Array cells are never volatile variables, therefore array loads |
| 6235 | // never use Load-Acquire instructions on ARM64. |
| 6236 | const bool use_load_acquire = false; |
| 6237 | |
| 6238 | // /* HeapReference<Object> */ ref = |
| 6239 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6240 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6241 | ref, |
| 6242 | obj, |
| 6243 | data_offset, |
| 6244 | index, |
| 6245 | scale_factor, |
| 6246 | temp, |
| 6247 | needs_null_check, |
| 6248 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6252 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6253 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6254 | uint32_t offset, |
| 6255 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6256 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6257 | Register temp, |
| 6258 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6259 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6260 | DCHECK(kEmitCompilerReadBarrier); |
| 6261 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6262 | // If we are emitting an array load, we should not be using a |
| 6263 | // Load Acquire instruction. In other words: |
| 6264 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6265 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6266 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6267 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6268 | // Marking Register) to decide whether we need to enter the slow |
| 6269 | // path to mark the reference. Then, in the slow path, check the |
| 6270 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6271 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6272 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6273 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6274 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6275 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6276 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6277 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6278 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6279 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6280 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6281 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6282 | // } |
| 6283 | // } else { |
| 6284 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6285 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6286 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6287 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6288 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6289 | SlowPathCodeARM64* slow_path = |
| 6290 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6291 | instruction, |
| 6292 | ref, |
| 6293 | obj, |
| 6294 | offset, |
| 6295 | index, |
| 6296 | scale_factor, |
| 6297 | needs_null_check, |
| 6298 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6299 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6300 | AddSlowPath(slow_path); |
| 6301 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6302 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6303 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6304 | GenerateRawReferenceLoad( |
| 6305 | 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] | 6306 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6307 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6308 | } |
| 6309 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6310 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6311 | Location ref, |
| 6312 | Register obj, |
| 6313 | Location field_offset, |
| 6314 | Register temp, |
| 6315 | bool needs_null_check, |
| 6316 | bool use_load_acquire) { |
| 6317 | DCHECK(kEmitCompilerReadBarrier); |
| 6318 | DCHECK(kUseBakerReadBarrier); |
| 6319 | // If we are emitting an array load, we should not be using a |
| 6320 | // Load Acquire instruction. In other words: |
| 6321 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6322 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6323 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6324 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6325 | // Marking Register) to decide whether we need to enter the slow |
| 6326 | // path to update the reference field within `obj`. Then, in the |
| 6327 | // slow path, check the gray bit in the lock word of the reference's |
| 6328 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6329 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6330 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6331 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6332 | // // Slow path. |
| 6333 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6334 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6335 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6336 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6337 | // if (is_gray) { |
| 6338 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6339 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6340 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6341 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6342 | // } |
| 6343 | // } |
| 6344 | |
| 6345 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6346 | // 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] | 6347 | SlowPathCodeARM64* slow_path = |
| 6348 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6349 | instruction, |
| 6350 | ref, |
| 6351 | obj, |
| 6352 | /* offset */ 0u, |
| 6353 | /* index */ field_offset, |
| 6354 | /* scale_factor */ 0u /* "times 1" */, |
| 6355 | needs_null_check, |
| 6356 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6357 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6358 | AddSlowPath(slow_path); |
| 6359 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6360 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6361 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6362 | // up-to-date, and we don't need to load the reference). |
| 6363 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6364 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6367 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6368 | Location ref, |
| 6369 | Register obj, |
| 6370 | uint32_t offset, |
| 6371 | Location index, |
| 6372 | size_t scale_factor, |
| 6373 | bool needs_null_check, |
| 6374 | bool use_load_acquire) { |
| 6375 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6376 | Primitive::Type type = Primitive::kPrimNot; |
| 6377 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6378 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6379 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6380 | // that no pools are emitted between the load (macro) instruction |
| 6381 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6382 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6383 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6384 | // Load types involving an "index": ArrayGet, |
| 6385 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6386 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6387 | if (use_load_acquire) { |
| 6388 | // UnsafeGetObjectVolatile intrinsic case. |
| 6389 | // Register `index` is not an index in an object array, but an |
| 6390 | // offset to an object reference field within object `obj`. |
| 6391 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6392 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6393 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6394 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6395 | DCHECK_EQ(offset, 0u); |
| 6396 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6397 | DCHECK_EQ(needs_null_check, false); |
| 6398 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6399 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6400 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6401 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6402 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6403 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6404 | if (index.IsConstant()) { |
| 6405 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6406 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6407 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6408 | if (needs_null_check) { |
| 6409 | MaybeRecordImplicitNullCheck(instruction); |
| 6410 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6411 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6412 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6413 | Register temp = temps.AcquireW(); |
| 6414 | __ Add(temp, obj, offset); |
| 6415 | { |
| 6416 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6417 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6418 | if (needs_null_check) { |
| 6419 | MaybeRecordImplicitNullCheck(instruction); |
| 6420 | } |
| 6421 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6422 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6423 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6424 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6425 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6426 | MemOperand field = HeapOperand(obj, offset); |
| 6427 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6428 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6429 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6430 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6431 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6432 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6433 | if (needs_null_check) { |
| 6434 | MaybeRecordImplicitNullCheck(instruction); |
| 6435 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6440 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6441 | } |
| 6442 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6443 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6444 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6445 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6446 | // The following condition is a run-time one; it is executed after the |
| 6447 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6448 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6449 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6450 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6451 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6452 | } |
| 6453 | } |
| 6454 | } |
| 6455 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6456 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6457 | Location out, |
| 6458 | Location ref, |
| 6459 | Location obj, |
| 6460 | uint32_t offset, |
| 6461 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6462 | DCHECK(kEmitCompilerReadBarrier); |
| 6463 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6464 | // Insert a slow path based read barrier *after* the reference load. |
| 6465 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6466 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6467 | // reference will be carried out by the runtime within the slow |
| 6468 | // path. |
| 6469 | // |
| 6470 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6471 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6472 | // not used by the artReadBarrierSlow entry point. |
| 6473 | // |
| 6474 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6475 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6476 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6477 | AddSlowPath(slow_path); |
| 6478 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6479 | __ B(slow_path->GetEntryLabel()); |
| 6480 | __ Bind(slow_path->GetExitLabel()); |
| 6481 | } |
| 6482 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6483 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6484 | Location out, |
| 6485 | Location ref, |
| 6486 | Location obj, |
| 6487 | uint32_t offset, |
| 6488 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6489 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6490 | // Baker's read barriers shall be handled by the fast path |
| 6491 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6492 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6493 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6494 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6495 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6496 | } else if (kPoisonHeapReferences) { |
| 6497 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6498 | } |
| 6499 | } |
| 6500 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6501 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6502 | Location out, |
| 6503 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6504 | DCHECK(kEmitCompilerReadBarrier); |
| 6505 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6506 | // Insert a slow path based read barrier *after* the GC root load. |
| 6507 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6508 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6509 | // not need to do anything special for this here. |
| 6510 | SlowPathCodeARM64* slow_path = |
| 6511 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6512 | AddSlowPath(slow_path); |
| 6513 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6514 | __ B(slow_path->GetEntryLabel()); |
| 6515 | __ Bind(slow_path->GetExitLabel()); |
| 6516 | } |
| 6517 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6518 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6519 | LocationSummary* locations = |
| 6520 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6522 | locations->SetOut(Location::RequiresRegister()); |
| 6523 | } |
| 6524 | |
| 6525 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6526 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6527 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6528 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6529 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6530 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6531 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6532 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6533 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6534 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6535 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6536 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6537 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6538 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6539 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6540 | } |
| 6541 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6542 | static void PatchJitRootUse(uint8_t* code, |
| 6543 | const uint8_t* roots_data, |
| 6544 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6545 | uint64_t index_in_table) { |
| 6546 | uint32_t literal_offset = literal->GetOffset(); |
| 6547 | uintptr_t address = |
| 6548 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6549 | uint8_t* data = code + literal_offset; |
| 6550 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6551 | } |
| 6552 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6553 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6554 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6555 | const StringReference& string_reference = entry.first; |
| 6556 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6557 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6558 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6559 | uint64_t index_in_table = it->second; |
| 6560 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6561 | } |
| 6562 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6563 | const TypeReference& type_reference = entry.first; |
| 6564 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6565 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6566 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6567 | uint64_t index_in_table = it->second; |
| 6568 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6569 | } |
| 6570 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6571 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6572 | #undef __ |
| 6573 | #undef QUICK_ENTRY_POINT |
| 6574 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6575 | } // namespace arm64 |
| 6576 | } // namespace art |