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 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 19 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 30 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 31 | #include "thread.h" |
| 32 | #include "utils/arm64/assembler_arm64.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/stack_checks.h" |
| 35 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 36 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 37 | using vixl::ExactAssemblyScope; |
| 38 | using vixl::CodeBufferCheckScope; |
| 39 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 40 | |
| 41 | #ifdef __ |
| 42 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 43 | #endif |
| 44 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 45 | namespace art { |
| 46 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 47 | template<class MirrorType> |
| 48 | class GcRoot; |
| 49 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 50 | namespace arm64 { |
| 51 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 52 | using helpers::ARM64EncodableConstantOrRegister; |
| 53 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 54 | using helpers::CPURegisterFrom; |
| 55 | using helpers::DRegisterFrom; |
| 56 | using helpers::FPRegisterFrom; |
| 57 | using helpers::HeapOperand; |
| 58 | using helpers::HeapOperandFrom; |
| 59 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 61 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 62 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 63 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 64 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 65 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 66 | using helpers::LocationFrom; |
| 67 | using helpers::OperandFromMemOperand; |
| 68 | using helpers::OutputCPURegister; |
| 69 | using helpers::OutputFPRegister; |
| 70 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 71 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | using helpers::RegisterFrom; |
| 73 | using helpers::StackOperandFrom; |
| 74 | using helpers::VIXLRegCodeFromART; |
| 75 | using helpers::WRegisterFrom; |
| 76 | using helpers::XRegisterFrom; |
| 77 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 78 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 79 | // 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] | 80 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 81 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 82 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 83 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 84 | inline Condition ARM64Condition(IfCondition cond) { |
| 85 | switch (cond) { |
| 86 | case kCondEQ: return eq; |
| 87 | case kCondNE: return ne; |
| 88 | case kCondLT: return lt; |
| 89 | case kCondLE: return le; |
| 90 | case kCondGT: return gt; |
| 91 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 92 | case kCondB: return lo; |
| 93 | case kCondBE: return ls; |
| 94 | case kCondA: return hi; |
| 95 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 96 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 97 | LOG(FATAL) << "Unreachable"; |
| 98 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 101 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 102 | // The ARM64 condition codes can express all the necessary branches, see the |
| 103 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 104 | // There is no dex instruction or HIR that would need the missing conditions |
| 105 | // "equal or unordered" or "not equal". |
| 106 | switch (cond) { |
| 107 | case kCondEQ: return eq; |
| 108 | case kCondNE: return ne /* unordered */; |
| 109 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 110 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 111 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 112 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 113 | default: |
| 114 | LOG(FATAL) << "UNREACHABLE"; |
| 115 | UNREACHABLE(); |
| 116 | } |
| 117 | } |
| 118 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 119 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 120 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 121 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 122 | // but we use the exact registers for clarity. |
| 123 | if (return_type == Primitive::kPrimFloat) { |
| 124 | return LocationFrom(s0); |
| 125 | } else if (return_type == Primitive::kPrimDouble) { |
| 126 | return LocationFrom(d0); |
| 127 | } else if (return_type == Primitive::kPrimLong) { |
| 128 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 129 | } else if (return_type == Primitive::kPrimVoid) { |
| 130 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 131 | } else { |
| 132 | return LocationFrom(w0); |
| 133 | } |
| 134 | } |
| 135 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 136 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 137 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 140 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 141 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 142 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 143 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 144 | // Calculate memory accessing operand for save/restore live registers. |
| 145 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 146 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 147 | int64_t spill_offset, |
| 148 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 149 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 150 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 151 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 152 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 153 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 154 | codegen->GetNumberOfFloatingPointRegisters())); |
| 155 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 156 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 157 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 158 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 159 | |
| 160 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 161 | UseScratchRegisterScope temps(masm); |
| 162 | |
| 163 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 164 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 165 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 166 | int64_t reg_size = kXRegSizeInBytes; |
| 167 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 168 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 169 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 170 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 171 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 172 | // to compute the base address(float point registers spill base address). |
| 173 | Register new_base = temps.AcquireSameSizeAs(base); |
| 174 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 175 | base = new_base; |
| 176 | spill_offset = -core_spill_size; |
| 177 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 178 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 179 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 180 | } |
| 181 | |
| 182 | if (is_save) { |
| 183 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 184 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 185 | } else { |
| 186 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 187 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 192 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 193 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 194 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 195 | // If the register holds an object, update the stack mask. |
| 196 | if (locations->RegisterContainsObject(i)) { |
| 197 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 199 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 200 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 201 | saved_core_stack_offsets_[i] = stack_offset; |
| 202 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 203 | } |
| 204 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 205 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 206 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 207 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 208 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 209 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 210 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 211 | } |
| 212 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 213 | SaveRestoreLiveRegistersHelper(codegen, |
| 214 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 215 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 216 | } |
| 217 | |
| 218 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 219 | SaveRestoreLiveRegistersHelper(codegen, |
| 220 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 221 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 222 | } |
| 223 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 224 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 225 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 226 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 227 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 228 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 229 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 230 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 231 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 232 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 233 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 234 | // Live registers will be restored in the catch block if caught. |
| 235 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 236 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 237 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 238 | // move resolver. |
| 239 | InvokeRuntimeCallingConvention calling_convention; |
| 240 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 241 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 242 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 243 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 244 | ? kQuickThrowStringBounds |
| 245 | : kQuickThrowArrayBounds; |
| 246 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 247 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 248 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 251 | bool IsFatal() const OVERRIDE { return true; } |
| 252 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 253 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 254 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 255 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 256 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 257 | }; |
| 258 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 259 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 260 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 261 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 262 | |
| 263 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 264 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 265 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 266 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 267 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 270 | bool IsFatal() const OVERRIDE { return true; } |
| 271 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 272 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 273 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 274 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 276 | }; |
| 277 | |
| 278 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 279 | public: |
| 280 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 281 | HInstruction* at, |
| 282 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 283 | bool do_clinit, |
| 284 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 285 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 286 | : SlowPathCodeARM64(at), |
| 287 | cls_(cls), |
| 288 | dex_pc_(dex_pc), |
| 289 | do_clinit_(do_clinit), |
| 290 | bss_entry_temp_(bss_entry_temp), |
| 291 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 293 | } |
| 294 | |
| 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 296 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 297 | Location out = locations->Out(); |
| 298 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 300 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 301 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the page address of |
| 302 | // the entry which is in a scratch register. Make sure it's not used for saving/restoring |
| 303 | // registers. Exclude the scratch register also for non-Baker read barrier for simplicity. |
| 304 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 305 | bool is_load_class_bss_entry = |
| 306 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 307 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 308 | if (is_load_class_bss_entry) { |
| 309 | // This temp is a scratch register. |
| 310 | DCHECK(bss_entry_temp_.IsValid()); |
| 311 | temps.Exclude(bss_entry_temp_); |
| 312 | } |
| 313 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 314 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 315 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 316 | |
| 317 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 318 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 319 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 320 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 321 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 322 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 323 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 324 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 325 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 326 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 327 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 328 | |
| 329 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 330 | if (out.IsValid()) { |
| 331 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 332 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 333 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 334 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 335 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 336 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 337 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 338 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 339 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 340 | if (call_saves_everything_except_r0_ip0) { |
| 341 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 342 | } else { |
| 343 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 344 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 345 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 346 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 347 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 348 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 349 | { |
| 350 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 351 | __ Bind(strp_label); |
| 352 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 353 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | __ B(GetExitLabel()); |
| 357 | } |
| 358 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 359 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 360 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 361 | private: |
| 362 | // The class this slow path will load. |
| 363 | HLoadClass* const cls_; |
| 364 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 365 | // The dex PC of `at_`. |
| 366 | const uint32_t dex_pc_; |
| 367 | |
| 368 | // Whether to initialize the class. |
| 369 | const bool do_clinit_; |
| 370 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 371 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 372 | vixl::aarch64::Register bss_entry_temp_; |
| 373 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 374 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 375 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 376 | }; |
| 377 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 378 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 379 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 380 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 381 | : SlowPathCodeARM64(instruction), |
| 382 | temp_(temp), |
| 383 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 384 | |
| 385 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 386 | LocationSummary* locations = instruction_->GetLocations(); |
| 387 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 388 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 389 | |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 390 | // temp_ is a scratch register. Make sure it's not used for saving/restoring registers. |
| 391 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 392 | temps.Exclude(temp_); |
| 393 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 394 | __ Bind(GetEntryLabel()); |
| 395 | SaveLiveRegisters(codegen, locations); |
| 396 | |
| 397 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 398 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 399 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 400 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 401 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 402 | Primitive::Type type = instruction_->GetType(); |
| 403 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 404 | |
| 405 | RestoreLiveRegisters(codegen, locations); |
| 406 | |
| 407 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 408 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 409 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 410 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 411 | } else { |
| 412 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 413 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 414 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 415 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 416 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 417 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 418 | { |
| 419 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 420 | __ Bind(strp_label); |
| 421 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 422 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | __ B(GetExitLabel()); |
| 426 | } |
| 427 | |
| 428 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 429 | |
| 430 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 431 | const Register temp_; |
| 432 | vixl::aarch64::Label* adrp_label_; |
| 433 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 434 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 435 | }; |
| 436 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 437 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 438 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 439 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 440 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 441 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 442 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 443 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 444 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 445 | // Live registers will be restored in the catch block if caught. |
| 446 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 447 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 448 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 449 | instruction_, |
| 450 | instruction_->GetDexPc(), |
| 451 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 452 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 455 | bool IsFatal() const OVERRIDE { return true; } |
| 456 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 457 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 458 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 459 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 460 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 461 | }; |
| 462 | |
| 463 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 464 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 465 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 466 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 467 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 468 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 469 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 470 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 471 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 472 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 473 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 474 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 475 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 476 | if (successor_ == nullptr) { |
| 477 | __ B(GetReturnLabel()); |
| 478 | } else { |
| 479 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 480 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 483 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 484 | DCHECK(successor_ == nullptr); |
| 485 | return &return_label_; |
| 486 | } |
| 487 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 488 | HBasicBlock* GetSuccessor() const { |
| 489 | return successor_; |
| 490 | } |
| 491 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 492 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 493 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 494 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 495 | // If not null, the block to branch to after the suspend check. |
| 496 | HBasicBlock* const successor_; |
| 497 | |
| 498 | // 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] | 499 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 500 | |
| 501 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 502 | }; |
| 503 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 504 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 505 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 506 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 507 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 508 | |
| 509 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 510 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 511 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 512 | DCHECK(instruction_->IsCheckCast() |
| 513 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 514 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 515 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 516 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 517 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 518 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 519 | if (!is_fatal_) { |
| 520 | SaveLiveRegisters(codegen, locations); |
| 521 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 522 | |
| 523 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 524 | // move resolver. |
| 525 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 526 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 527 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 528 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 529 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 530 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 531 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 532 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 533 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 534 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 535 | Primitive::Type ret_type = instruction_->GetType(); |
| 536 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 537 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 538 | } else { |
| 539 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 540 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 541 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 544 | if (!is_fatal_) { |
| 545 | RestoreLiveRegisters(codegen, locations); |
| 546 | __ B(GetExitLabel()); |
| 547 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 550 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 551 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 552 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 553 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 554 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 555 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 556 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 557 | }; |
| 558 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 559 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 560 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 561 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 562 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 563 | |
| 564 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 565 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 566 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 567 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 568 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 571 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 572 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 573 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 574 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 575 | }; |
| 576 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 577 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 578 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 579 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 580 | |
| 581 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 582 | LocationSummary* locations = instruction_->GetLocations(); |
| 583 | __ Bind(GetEntryLabel()); |
| 584 | SaveLiveRegisters(codegen, locations); |
| 585 | |
| 586 | InvokeRuntimeCallingConvention calling_convention; |
| 587 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 588 | parallel_move.AddMove( |
| 589 | locations->InAt(0), |
| 590 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 591 | Primitive::kPrimNot, |
| 592 | nullptr); |
| 593 | parallel_move.AddMove( |
| 594 | locations->InAt(1), |
| 595 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 596 | Primitive::kPrimInt, |
| 597 | nullptr); |
| 598 | parallel_move.AddMove( |
| 599 | locations->InAt(2), |
| 600 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 601 | Primitive::kPrimNot, |
| 602 | nullptr); |
| 603 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 604 | |
| 605 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 606 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 607 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 608 | RestoreLiveRegisters(codegen, locations); |
| 609 | __ B(GetExitLabel()); |
| 610 | } |
| 611 | |
| 612 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 613 | |
| 614 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 615 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 616 | }; |
| 617 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 618 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 619 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 620 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 621 | |
| 622 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 623 | // 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] | 624 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 625 | num_entries * sizeof(int32_t), |
| 626 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 627 | |
| 628 | __ Bind(&table_start_); |
| 629 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 630 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 631 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 632 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 633 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 634 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 635 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 636 | Literal<int32_t> literal(jump_offset); |
| 637 | __ place(&literal); |
| 638 | } |
| 639 | } |
| 640 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 641 | // Abstract base class for read barrier slow paths marking a reference |
| 642 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 643 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 644 | // Argument `entrypoint` must be a register location holding the read |
| 645 | // barrier marking runtime entry point to be invoked. |
| 646 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 647 | protected: |
| 648 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 649 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 650 | DCHECK(kEmitCompilerReadBarrier); |
| 651 | } |
| 652 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 653 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 654 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 655 | // Generate assembly code calling the read barrier marking runtime |
| 656 | // entry point (ReadBarrierMarkRegX). |
| 657 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 658 | // No need to save live registers; it's taken care of by the |
| 659 | // entrypoint. Also, there is no need to update the stack mask, |
| 660 | // as this runtime call will not trigger a garbage collection. |
| 661 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 662 | DCHECK_NE(ref_.reg(), LR); |
| 663 | DCHECK_NE(ref_.reg(), WSP); |
| 664 | DCHECK_NE(ref_.reg(), WZR); |
| 665 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 666 | // as a temporary, it cannot be the entry point's input/output. |
| 667 | DCHECK_NE(ref_.reg(), IP0); |
| 668 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 669 | // "Compact" slow path, saving two moves. |
| 670 | // |
| 671 | // Instead of using the standard runtime calling convention (input |
| 672 | // and output in W0): |
| 673 | // |
| 674 | // W0 <- ref |
| 675 | // W0 <- ReadBarrierMark(W0) |
| 676 | // ref <- W0 |
| 677 | // |
| 678 | // we just use rX (the register containing `ref`) as input and output |
| 679 | // of a dedicated entrypoint: |
| 680 | // |
| 681 | // rX <- ReadBarrierMarkRegX(rX) |
| 682 | // |
| 683 | if (entrypoint_.IsValid()) { |
| 684 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 685 | __ Blr(XRegisterFrom(entrypoint_)); |
| 686 | } else { |
| 687 | // Entrypoint is not already loaded, load from the thread. |
| 688 | int32_t entry_point_offset = |
| 689 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 690 | // This runtime call does not require a stack map. |
| 691 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | // The location (register) of the marked object reference. |
| 696 | const Location ref_; |
| 697 | |
| 698 | // The location of the entrypoint if it is already loaded. |
| 699 | const Location entrypoint_; |
| 700 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 701 | private: |
| 702 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 703 | }; |
| 704 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 705 | // Slow path marking an object reference `ref` during a read |
| 706 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 707 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 708 | // |
| 709 | // This means that after the execution of this slow path, `ref` will |
| 710 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 711 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 712 | // probably still be a from-space reference (unless it gets updated by |
| 713 | // another thread, or if another thread installed another object |
| 714 | // reference (different from `ref`) in `obj.field`). |
| 715 | // |
| 716 | // If `entrypoint` is a valid location it is assumed to already be |
| 717 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 718 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 719 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 720 | public: |
| 721 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 722 | Location ref, |
| 723 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 724 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 725 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 729 | |
| 730 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 731 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 732 | DCHECK(locations->CanCall()); |
| 733 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 734 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 735 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 736 | << "Unexpected instruction in read barrier marking slow path: " |
| 737 | << instruction_->DebugName(); |
| 738 | |
| 739 | __ Bind(GetEntryLabel()); |
| 740 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 741 | __ B(GetExitLabel()); |
| 742 | } |
| 743 | |
| 744 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 745 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 746 | }; |
| 747 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 748 | // Slow path loading `obj`'s lock word, loading a reference from |
| 749 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 750 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 751 | // read barrier). The field `obj.field` in the object `obj` holding |
| 752 | // this reference does not get updated by this slow path after marking |
| 753 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 754 | // below for that). |
| 755 | // |
| 756 | // This means that after the execution of this slow path, `ref` will |
| 757 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 758 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 759 | // probably still be a from-space reference (unless it gets updated by |
| 760 | // another thread, or if another thread installed another object |
| 761 | // reference (different from `ref`) in `obj.field`). |
| 762 | // |
| 763 | // Argument `entrypoint` must be a register location holding the read |
| 764 | // barrier marking runtime entry point to be invoked. |
| 765 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 766 | public: |
| 767 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 768 | Location ref, |
| 769 | Register obj, |
| 770 | uint32_t offset, |
| 771 | Location index, |
| 772 | size_t scale_factor, |
| 773 | bool needs_null_check, |
| 774 | bool use_load_acquire, |
| 775 | Register temp, |
| 776 | Location entrypoint) |
| 777 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 778 | obj_(obj), |
| 779 | offset_(offset), |
| 780 | index_(index), |
| 781 | scale_factor_(scale_factor), |
| 782 | needs_null_check_(needs_null_check), |
| 783 | use_load_acquire_(use_load_acquire), |
| 784 | temp_(temp) { |
| 785 | DCHECK(kEmitCompilerReadBarrier); |
| 786 | DCHECK(kUseBakerReadBarrier); |
| 787 | } |
| 788 | |
| 789 | const char* GetDescription() const OVERRIDE { |
| 790 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 791 | } |
| 792 | |
| 793 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 794 | LocationSummary* locations = instruction_->GetLocations(); |
| 795 | DCHECK(locations->CanCall()); |
| 796 | DCHECK(ref_.IsRegister()) << ref_; |
| 797 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 798 | DCHECK(obj_.IsW()); |
| 799 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 800 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 801 | instruction_->IsStaticFieldGet() || |
| 802 | instruction_->IsArrayGet() || |
| 803 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 804 | instruction_->IsInstanceOf() || |
| 805 | instruction_->IsCheckCast() || |
| 806 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 807 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 808 | << "Unexpected instruction in read barrier marking slow path: " |
| 809 | << instruction_->DebugName(); |
| 810 | // The read barrier instrumentation of object ArrayGet |
| 811 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 812 | // instruction. |
| 813 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 814 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 815 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 816 | // Temporary register `temp_`, used to store the lock word, must |
| 817 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 818 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 819 | // need the lock word to still be in `temp_` after the reference |
| 820 | // load. |
| 821 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 822 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 823 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 824 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 825 | |
| 826 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 827 | // inserted after the original load. However, in fast path based |
| 828 | // Baker's read barriers, we need to perform the load of |
| 829 | // mirror::Object::monitor_ *before* the original reference load. |
| 830 | // This load-load ordering is required by the read barrier. |
| 831 | // The fast path/slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 832 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 833 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 834 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 835 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 836 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 837 | // if (is_gray) { |
| 838 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 839 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 840 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 841 | // Note: the original implementation in ReadBarrier::Barrier is |
| 842 | // slightly more complex as it performs additional checks that we do |
| 843 | // not do here for performance reasons. |
| 844 | |
| 845 | // /* int32_t */ monitor = obj->monitor_ |
| 846 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 847 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 848 | if (needs_null_check_) { |
| 849 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 850 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 851 | // /* LockWord */ lock_word = LockWord(monitor) |
| 852 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 853 | "art::LockWord and int32_t have different sizes."); |
| 854 | |
| 855 | // Introduce a dependency on the lock_word including rb_state, |
| 856 | // to prevent load-load reordering, and without using |
| 857 | // a memory barrier (which would be more expensive). |
| 858 | // `obj` is unchanged by this operation, but its value now depends |
| 859 | // on `temp`. |
| 860 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 861 | |
| 862 | // The actual reference load. |
| 863 | // A possible implicit null check has already been handled above. |
| 864 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 865 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 866 | ref_, |
| 867 | obj_, |
| 868 | offset_, |
| 869 | index_, |
| 870 | scale_factor_, |
| 871 | /* needs_null_check */ false, |
| 872 | use_load_acquire_); |
| 873 | |
| 874 | // Mark the object `ref` when `obj` is gray. |
| 875 | // |
| 876 | // if (rb_state == ReadBarrier::GrayState()) |
| 877 | // ref = ReadBarrier::Mark(ref); |
| 878 | // |
| 879 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 880 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 881 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 882 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 883 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 884 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 885 | __ B(GetExitLabel()); |
| 886 | } |
| 887 | |
| 888 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 889 | // The register containing the object holding the marked object reference field. |
| 890 | Register obj_; |
| 891 | // The offset, index and scale factor to access the reference in `obj_`. |
| 892 | uint32_t offset_; |
| 893 | Location index_; |
| 894 | size_t scale_factor_; |
| 895 | // Is a null check required? |
| 896 | bool needs_null_check_; |
| 897 | // Should this reference load use Load-Acquire semantics? |
| 898 | bool use_load_acquire_; |
| 899 | // A temporary register used to hold the lock word of `obj_`. |
| 900 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 901 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 902 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 903 | }; |
| 904 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 905 | // Slow path loading `obj`'s lock word, loading a reference from |
| 906 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 907 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 908 | // read barrier). If needed, this slow path also atomically updates |
| 909 | // the field `obj.field` in the object `obj` holding this reference |
| 910 | // after marking (contrary to |
| 911 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 912 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 913 | // |
| 914 | // This means that after the execution of this slow path, both `ref` |
| 915 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 916 | // hold the same to-space reference (unless another thread installed |
| 917 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 918 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | // Argument `entrypoint` must be a register location holding the read |
| 920 | // barrier marking runtime entry point to be invoked. |
| 921 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 922 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 923 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 924 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 925 | Location ref, |
| 926 | Register obj, |
| 927 | uint32_t offset, |
| 928 | Location index, |
| 929 | size_t scale_factor, |
| 930 | bool needs_null_check, |
| 931 | bool use_load_acquire, |
| 932 | Register temp, |
| 933 | Location entrypoint) |
| 934 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 935 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 936 | offset_(offset), |
| 937 | index_(index), |
| 938 | scale_factor_(scale_factor), |
| 939 | needs_null_check_(needs_null_check), |
| 940 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 941 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 942 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 943 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 947 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 951 | LocationSummary* locations = instruction_->GetLocations(); |
| 952 | Register ref_reg = WRegisterFrom(ref_); |
| 953 | DCHECK(locations->CanCall()); |
| 954 | DCHECK(ref_.IsRegister()) << ref_; |
| 955 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 956 | DCHECK(obj_.IsW()); |
| 957 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 958 | |
| 959 | // 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] | 960 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 961 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 962 | << instruction_->DebugName(); |
| 963 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 964 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 965 | DCHECK_EQ(offset_, 0u); |
| 966 | DCHECK_EQ(scale_factor_, 0u); |
| 967 | DCHECK_EQ(use_load_acquire_, false); |
| 968 | // The location of the offset of the marked reference field within `obj_`. |
| 969 | Location field_offset = index_; |
| 970 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 971 | |
| 972 | // Temporary register `temp_`, used to store the lock word, must |
| 973 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 974 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 975 | // need the lock word to still be in `temp_` after the reference |
| 976 | // load. |
| 977 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 978 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 979 | |
| 980 | __ Bind(GetEntryLabel()); |
| 981 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 982 | // /* int32_t */ monitor = obj->monitor_ |
| 983 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 984 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 985 | if (needs_null_check_) { |
| 986 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 987 | } |
| 988 | // /* LockWord */ lock_word = LockWord(monitor) |
| 989 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 990 | "art::LockWord and int32_t have different sizes."); |
| 991 | |
| 992 | // Introduce a dependency on the lock_word including rb_state, |
| 993 | // to prevent load-load reordering, and without using |
| 994 | // a memory barrier (which would be more expensive). |
| 995 | // `obj` is unchanged by this operation, but its value now depends |
| 996 | // on `temp`. |
| 997 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 998 | |
| 999 | // The actual reference load. |
| 1000 | // A possible implicit null check has already been handled above. |
| 1001 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1002 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1003 | ref_, |
| 1004 | obj_, |
| 1005 | offset_, |
| 1006 | index_, |
| 1007 | scale_factor_, |
| 1008 | /* needs_null_check */ false, |
| 1009 | use_load_acquire_); |
| 1010 | |
| 1011 | // Mark the object `ref` when `obj` is gray. |
| 1012 | // |
| 1013 | // if (rb_state == ReadBarrier::GrayState()) |
| 1014 | // ref = ReadBarrier::Mark(ref); |
| 1015 | // |
| 1016 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1017 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1018 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1019 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1020 | |
| 1021 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1022 | // Note that we cannot use IP to save the old reference, as IP is |
| 1023 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1024 | // need the old reference after the call to that entry point. |
| 1025 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1026 | __ Mov(temp_.W(), ref_reg); |
| 1027 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1028 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1029 | |
| 1030 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1031 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1032 | // |
| 1033 | // Note that this field could also hold a different object, if |
| 1034 | // another thread had concurrently changed it. In that case, the |
| 1035 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1036 | // (CAS) operation below would abort the CAS, leaving the field |
| 1037 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1038 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1039 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1040 | |
| 1041 | // Update the the holder's field atomically. This may fail if |
| 1042 | // mutator updates before us, but it's OK. This is achieved |
| 1043 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1044 | // memory synchronization ordering, where the expected value is |
| 1045 | // the old reference and the desired value is the new reference. |
| 1046 | |
| 1047 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1048 | UseScratchRegisterScope temps(masm); |
| 1049 | |
| 1050 | // Convenience aliases. |
| 1051 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1052 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1053 | Register expected = temp_.W(); |
| 1054 | Register value = ref_reg; |
| 1055 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1056 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1057 | |
| 1058 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1059 | |
| 1060 | if (kPoisonHeapReferences) { |
| 1061 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1062 | if (value.Is(expected)) { |
| 1063 | // Do not poison `value`, as it is the same register as |
| 1064 | // `expected`, which has just been poisoned. |
| 1065 | } else { |
| 1066 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | // do { |
| 1071 | // tmp_value = [tmp_ptr] - expected; |
| 1072 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1073 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1074 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1075 | __ Bind(&loop_head); |
| 1076 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1077 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1078 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1079 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1080 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1081 | __ B(&exit_loop); |
| 1082 | __ Bind(&comparison_failed); |
| 1083 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1084 | __ Bind(&exit_loop); |
| 1085 | |
| 1086 | if (kPoisonHeapReferences) { |
| 1087 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1088 | if (value.Is(expected)) { |
| 1089 | // Do not unpoison `value`, as it is the same register as |
| 1090 | // `expected`, which has just been unpoisoned. |
| 1091 | } else { |
| 1092 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1093 | } |
| 1094 | } |
| 1095 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1096 | __ B(GetExitLabel()); |
| 1097 | } |
| 1098 | |
| 1099 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1100 | // The register containing the object holding the marked object reference field. |
| 1101 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1102 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1103 | uint32_t offset_; |
| 1104 | Location index_; |
| 1105 | size_t scale_factor_; |
| 1106 | // Is a null check required? |
| 1107 | bool needs_null_check_; |
| 1108 | // Should this reference load use Load-Acquire semantics? |
| 1109 | bool use_load_acquire_; |
| 1110 | // A temporary register used to hold the lock word of `obj_`; and |
| 1111 | // also to hold the original reference value, when the reference is |
| 1112 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1113 | const Register temp_; |
| 1114 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1115 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1116 | }; |
| 1117 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1118 | // Slow path generating a read barrier for a heap reference. |
| 1119 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1120 | public: |
| 1121 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1122 | Location out, |
| 1123 | Location ref, |
| 1124 | Location obj, |
| 1125 | uint32_t offset, |
| 1126 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1127 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1128 | out_(out), |
| 1129 | ref_(ref), |
| 1130 | obj_(obj), |
| 1131 | offset_(offset), |
| 1132 | index_(index) { |
| 1133 | DCHECK(kEmitCompilerReadBarrier); |
| 1134 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1135 | // has been overwritten by (or after) the heap object reference load |
| 1136 | // to be instrumented, e.g.: |
| 1137 | // |
| 1138 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1139 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1140 | // |
| 1141 | // In that case, we have lost the information about the original |
| 1142 | // object, and the emitted read barrier cannot work properly. |
| 1143 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1144 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1145 | } |
| 1146 | |
| 1147 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1148 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1149 | LocationSummary* locations = instruction_->GetLocations(); |
| 1150 | Primitive::Type type = Primitive::kPrimNot; |
| 1151 | DCHECK(locations->CanCall()); |
| 1152 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1153 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1154 | instruction_->IsStaticFieldGet() || |
| 1155 | instruction_->IsArrayGet() || |
| 1156 | instruction_->IsInstanceOf() || |
| 1157 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1158 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1159 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1160 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1161 | // The read barrier instrumentation of object ArrayGet |
| 1162 | // instructions does not support the HIntermediateAddress |
| 1163 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1164 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1165 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1166 | |
| 1167 | __ Bind(GetEntryLabel()); |
| 1168 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1169 | SaveLiveRegisters(codegen, locations); |
| 1170 | |
| 1171 | // We may have to change the index's value, but as `index_` is a |
| 1172 | // constant member (like other "inputs" of this slow path), |
| 1173 | // introduce a copy of it, `index`. |
| 1174 | Location index = index_; |
| 1175 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1176 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1177 | if (instruction_->IsArrayGet()) { |
| 1178 | // Compute the actual memory offset and store it in `index`. |
| 1179 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1180 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1181 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1182 | // We are about to change the value of `index_reg` (see the |
| 1183 | // calls to vixl::MacroAssembler::Lsl and |
| 1184 | // vixl::MacroAssembler::Mov below), but it has |
| 1185 | // not been saved by the previous call to |
| 1186 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1187 | // callee-save register -- |
| 1188 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1189 | // callee-save registers, as it has been designed with the |
| 1190 | // assumption that callee-save registers are supposed to be |
| 1191 | // handled by the called function. So, as a callee-save |
| 1192 | // register, `index_reg` _would_ eventually be saved onto |
| 1193 | // the stack, but it would be too late: we would have |
| 1194 | // changed its value earlier. Therefore, we manually save |
| 1195 | // it here into another freely available register, |
| 1196 | // `free_reg`, chosen of course among the caller-save |
| 1197 | // registers (as a callee-save `free_reg` register would |
| 1198 | // exhibit the same problem). |
| 1199 | // |
| 1200 | // Note we could have requested a temporary register from |
| 1201 | // the register allocator instead; but we prefer not to, as |
| 1202 | // this is a slow path, and we know we can find a |
| 1203 | // caller-save register that is available. |
| 1204 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1205 | __ Mov(free_reg.W(), index_reg); |
| 1206 | index_reg = free_reg; |
| 1207 | index = LocationFrom(index_reg); |
| 1208 | } else { |
| 1209 | // The initial register stored in `index_` has already been |
| 1210 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1211 | // (as it is not a callee-save register), so we can freely |
| 1212 | // use it. |
| 1213 | } |
| 1214 | // Shifting the index value contained in `index_reg` by the scale |
| 1215 | // factor (2) cannot overflow in practice, as the runtime is |
| 1216 | // unable to allocate object arrays with a size larger than |
| 1217 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1218 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1219 | static_assert( |
| 1220 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1221 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1222 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1223 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1224 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1225 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1226 | // (as in the case of ArrayGet), as it is actually an offset |
| 1227 | // to an object field within an object. |
| 1228 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1229 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1230 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1231 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1232 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1233 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1234 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | // We're moving two or three locations to locations that could |
| 1239 | // overlap, so we need a parallel move resolver. |
| 1240 | InvokeRuntimeCallingConvention calling_convention; |
| 1241 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1242 | parallel_move.AddMove(ref_, |
| 1243 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1244 | type, |
| 1245 | nullptr); |
| 1246 | parallel_move.AddMove(obj_, |
| 1247 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1248 | type, |
| 1249 | nullptr); |
| 1250 | if (index.IsValid()) { |
| 1251 | parallel_move.AddMove(index, |
| 1252 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1253 | Primitive::kPrimInt, |
| 1254 | nullptr); |
| 1255 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1256 | } else { |
| 1257 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1258 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1259 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1260 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1261 | instruction_, |
| 1262 | instruction_->GetDexPc(), |
| 1263 | this); |
| 1264 | CheckEntrypointTypes< |
| 1265 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1266 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1267 | |
| 1268 | RestoreLiveRegisters(codegen, locations); |
| 1269 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1270 | __ B(GetExitLabel()); |
| 1271 | } |
| 1272 | |
| 1273 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1274 | |
| 1275 | private: |
| 1276 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1277 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1278 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1279 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1280 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1281 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1282 | } |
| 1283 | } |
| 1284 | // We shall never fail to find a free caller-save register, as |
| 1285 | // there are more than two core caller-save registers on ARM64 |
| 1286 | // (meaning it is possible to find one which is different from |
| 1287 | // `ref` and `obj`). |
| 1288 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1289 | LOG(FATAL) << "Could not find a free register"; |
| 1290 | UNREACHABLE(); |
| 1291 | } |
| 1292 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1293 | const Location out_; |
| 1294 | const Location ref_; |
| 1295 | const Location obj_; |
| 1296 | const uint32_t offset_; |
| 1297 | // An additional location containing an index to an array. |
| 1298 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1299 | // UnsafeGetObjectVolatile intrinsics. |
| 1300 | const Location index_; |
| 1301 | |
| 1302 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1303 | }; |
| 1304 | |
| 1305 | // Slow path generating a read barrier for a GC root. |
| 1306 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1307 | public: |
| 1308 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1309 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1310 | DCHECK(kEmitCompilerReadBarrier); |
| 1311 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1312 | |
| 1313 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1314 | LocationSummary* locations = instruction_->GetLocations(); |
| 1315 | Primitive::Type type = Primitive::kPrimNot; |
| 1316 | DCHECK(locations->CanCall()); |
| 1317 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1318 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1319 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1320 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1321 | |
| 1322 | __ Bind(GetEntryLabel()); |
| 1323 | SaveLiveRegisters(codegen, locations); |
| 1324 | |
| 1325 | InvokeRuntimeCallingConvention calling_convention; |
| 1326 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1327 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1328 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1329 | // thus we need a 64-bit move here, and we cannot use |
| 1330 | // |
| 1331 | // arm64_codegen->MoveLocation( |
| 1332 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1333 | // root_, |
| 1334 | // type); |
| 1335 | // |
| 1336 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1337 | // reference type (`Primitive::kPrimNot`). |
| 1338 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1339 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1340 | instruction_, |
| 1341 | instruction_->GetDexPc(), |
| 1342 | this); |
| 1343 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1344 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1345 | |
| 1346 | RestoreLiveRegisters(codegen, locations); |
| 1347 | __ B(GetExitLabel()); |
| 1348 | } |
| 1349 | |
| 1350 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1351 | |
| 1352 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1353 | const Location out_; |
| 1354 | const Location root_; |
| 1355 | |
| 1356 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1357 | }; |
| 1358 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1359 | #undef __ |
| 1360 | |
| 1361 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1362 | Location next_location; |
| 1363 | if (type == Primitive::kPrimVoid) { |
| 1364 | LOG(FATAL) << "Unreachable type " << type; |
| 1365 | } |
| 1366 | |
| 1367 | if (Primitive::IsFloatingPointType(type) && |
| 1368 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1369 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1370 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1371 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1372 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1373 | } else { |
| 1374 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1375 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1376 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1379 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1380 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1381 | return next_location; |
| 1382 | } |
| 1383 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1384 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1385 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1386 | } |
| 1387 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1388 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1389 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1390 | const CompilerOptions& compiler_options, |
| 1391 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1392 | : CodeGenerator(graph, |
| 1393 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1394 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1395 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1396 | callee_saved_core_registers.GetList(), |
| 1397 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1398 | compiler_options, |
| 1399 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1400 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1401 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1402 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1403 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1404 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1405 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1406 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1407 | uint32_literals_(std::less<uint32_t>(), |
| 1408 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1409 | uint64_literals_(std::less<uint64_t>(), |
| 1410 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1411 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1412 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1413 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1414 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1415 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1416 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1417 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1418 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1419 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1420 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1421 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1422 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1423 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1424 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1425 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1426 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1427 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1428 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1429 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1430 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1431 | jump_table->EmitTable(this); |
| 1432 | } |
| 1433 | } |
| 1434 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1435 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1436 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1437 | // Ensure we emit the literal pool. |
| 1438 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1439 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1440 | CodeGenerator::Finalize(allocator); |
| 1441 | } |
| 1442 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1443 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1444 | // Note: There are 6 kinds of moves: |
| 1445 | // 1. constant -> GPR/FPR (non-cycle) |
| 1446 | // 2. constant -> stack (non-cycle) |
| 1447 | // 3. GPR/FPR -> GPR/FPR |
| 1448 | // 4. GPR/FPR -> stack |
| 1449 | // 5. stack -> GPR/FPR |
| 1450 | // 6. stack -> stack (non-cycle) |
| 1451 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1452 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1453 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1454 | // dependency. |
| 1455 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1456 | } |
| 1457 | |
| 1458 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1459 | vixl_temps_.Close(); |
| 1460 | } |
| 1461 | |
| 1462 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1463 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1464 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1465 | || kind == Location::kSIMDStackSlot); |
| 1466 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1467 | ? Location::kFpuRegister |
| 1468 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1469 | Location scratch = GetScratchLocation(kind); |
| 1470 | if (!scratch.Equals(Location::NoLocation())) { |
| 1471 | return scratch; |
| 1472 | } |
| 1473 | // Allocate from VIXL temp registers. |
| 1474 | if (kind == Location::kRegister) { |
| 1475 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1476 | } else { |
| 1477 | DCHECK(kind == Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1478 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1479 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1480 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1481 | } |
| 1482 | AddScratchLocation(scratch); |
| 1483 | return scratch; |
| 1484 | } |
| 1485 | |
| 1486 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1487 | if (loc.IsRegister()) { |
| 1488 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1489 | } else { |
| 1490 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1491 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1492 | } |
| 1493 | RemoveScratchLocation(loc); |
| 1494 | } |
| 1495 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1496 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1497 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1498 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1501 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1502 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1503 | __ Bind(&frame_entry_label_); |
| 1504 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1505 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1506 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1507 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1508 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1509 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1510 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1511 | { |
| 1512 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1513 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1514 | kInstructionSize, |
| 1515 | CodeBufferCheckScope::kExactSize); |
| 1516 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1517 | RecordPcInfo(nullptr, 0); |
| 1518 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1519 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1520 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1521 | if (!HasEmptyFrame()) { |
| 1522 | int frame_size = GetFrameSize(); |
| 1523 | // Stack layout: |
| 1524 | // sp[frame_size - 8] : lr. |
| 1525 | // ... : other preserved core registers. |
| 1526 | // ... : other preserved fp registers. |
| 1527 | // ... : reserved frame space. |
| 1528 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1529 | |
| 1530 | // Save the current method if we need it. Note that we do not |
| 1531 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1532 | // in the SSA graph. |
| 1533 | if (RequiresCurrentMethod()) { |
| 1534 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1535 | } else { |
| 1536 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1537 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1538 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1539 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1540 | frame_size - GetCoreSpillSize()); |
| 1541 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1542 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1543 | |
| 1544 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1545 | // Initialize should_deoptimize flag to 0. |
| 1546 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1547 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1548 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1549 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1553 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1554 | if (!HasEmptyFrame()) { |
| 1555 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1556 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1557 | frame_size - FrameEntrySpillSize()); |
| 1558 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1559 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1560 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1561 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1562 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1563 | __ Ret(); |
| 1564 | GetAssembler()->cfi().RestoreState(); |
| 1565 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1568 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1569 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1570 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1571 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1572 | } |
| 1573 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1574 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1575 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1576 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1577 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1578 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1579 | } |
| 1580 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1581 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1582 | __ Bind(GetLabelOf(block)); |
| 1583 | } |
| 1584 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1585 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1586 | DCHECK(location.IsRegister()); |
| 1587 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1588 | } |
| 1589 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1590 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1591 | if (location.IsRegister()) { |
| 1592 | locations->AddTemp(location); |
| 1593 | } else { |
| 1594 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1595 | } |
| 1596 | } |
| 1597 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1598 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1599 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1600 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1601 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1602 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1603 | if (value_can_be_null) { |
| 1604 | __ Cbz(value, &done); |
| 1605 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1606 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1607 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1608 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1609 | if (value_can_be_null) { |
| 1610 | __ Bind(&done); |
| 1611 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1614 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1615 | // Blocked core registers: |
| 1616 | // lr : Runtime reserved. |
| 1617 | // tr : Runtime reserved. |
| 1618 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1619 | // ip1 : VIXL core temp. |
| 1620 | // ip0 : VIXL core temp. |
| 1621 | // |
| 1622 | // Blocked fp registers: |
| 1623 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1624 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1625 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1626 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1627 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1628 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1629 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1630 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1631 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1632 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1633 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1634 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1635 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1636 | // Stubs do not save callee-save floating point registers. If the graph |
| 1637 | // is debuggable, we need to deal with these registers differently. For |
| 1638 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1639 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1640 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1641 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1642 | } |
| 1643 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1646 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1647 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1648 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1649 | return kArm64WordSize; |
| 1650 | } |
| 1651 | |
| 1652 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1653 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1654 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1655 | return kArm64WordSize; |
| 1656 | } |
| 1657 | |
| 1658 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1659 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1660 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1661 | return kArm64WordSize; |
| 1662 | } |
| 1663 | |
| 1664 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1665 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1666 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1667 | return kArm64WordSize; |
| 1668 | } |
| 1669 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1670 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1671 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1675 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1676 | } |
| 1677 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1678 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1679 | if (constant->IsIntConstant()) { |
| 1680 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1681 | } else if (constant->IsLongConstant()) { |
| 1682 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1683 | } else if (constant->IsNullConstant()) { |
| 1684 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1685 | } else if (constant->IsFloatConstant()) { |
| 1686 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1687 | } else { |
| 1688 | DCHECK(constant->IsDoubleConstant()); |
| 1689 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1690 | } |
| 1691 | } |
| 1692 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1693 | |
| 1694 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1695 | DCHECK(constant.IsConstant()); |
| 1696 | HConstant* cst = constant.GetConstant(); |
| 1697 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1698 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1699 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1700 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1701 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1702 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1703 | } |
| 1704 | |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1705 | // Allocate a scratch register from the VIXL pool, querying first into |
| 1706 | // the floating-point register pool, and then the the core register |
| 1707 | // pool. This is essentially a reimplementation of |
| 1708 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1709 | // using a different allocation strategy. |
| 1710 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1711 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1712 | int size_in_bits) { |
| 1713 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1714 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1715 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1716 | } |
| 1717 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1718 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1719 | Location source, |
| 1720 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1721 | if (source.Equals(destination)) { |
| 1722 | return; |
| 1723 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1724 | |
| 1725 | // A valid move can always be inferred from the destination and source |
| 1726 | // locations. When moving from and to a register, the argument type can be |
| 1727 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1728 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1729 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1730 | |
| 1731 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1732 | if (unspecified_type) { |
| 1733 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1734 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1735 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1736 | || src_cst->IsFloatConstant() |
| 1737 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1738 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1739 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1740 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1741 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1742 | // type is appropriate. Else the source is a register, and since the |
| 1743 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1744 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1745 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1746 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1747 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1748 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1749 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1750 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1751 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1752 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1753 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1754 | } else if (source.IsSIMDStackSlot()) { |
| 1755 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1756 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1757 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1758 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1759 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1760 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1761 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1762 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1763 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1764 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1765 | ? Primitive::kPrimLong |
| 1766 | : Primitive::kPrimInt; |
| 1767 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1768 | } |
| 1769 | } else { |
| 1770 | DCHECK(source.IsFpuRegister()); |
| 1771 | if (destination.IsRegister()) { |
| 1772 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1773 | ? Primitive::kPrimDouble |
| 1774 | : Primitive::kPrimFloat; |
| 1775 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1776 | } else { |
| 1777 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1778 | if (GetGraph()->HasSIMD()) { |
| 1779 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1780 | } else { |
| 1781 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | } else if (destination.IsSIMDStackSlot()) { |
| 1786 | if (source.IsFpuRegister()) { |
| 1787 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1788 | } else { |
| 1789 | DCHECK(source.IsSIMDStackSlot()); |
| 1790 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1791 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1792 | Register temp = temps.AcquireX(); |
| 1793 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1794 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1795 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1796 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1797 | } else { |
| 1798 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1799 | __ Ldr(temp, StackOperandFrom(source)); |
| 1800 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1801 | } |
| 1802 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1803 | } else { // The destination is not a register. It must be a stack slot. |
| 1804 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1805 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1806 | if (unspecified_type) { |
| 1807 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1808 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1809 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1810 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1811 | } |
| 1812 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1813 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1814 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1815 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1816 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1817 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1818 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1819 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1820 | HConstant* src_cst = source.GetConstant(); |
| 1821 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1822 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1823 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1824 | ? Register(xzr) |
| 1825 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1826 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1827 | if (src_cst->IsIntConstant()) { |
| 1828 | temp = temps.AcquireW(); |
| 1829 | } else if (src_cst->IsLongConstant()) { |
| 1830 | temp = temps.AcquireX(); |
| 1831 | } else if (src_cst->IsFloatConstant()) { |
| 1832 | temp = temps.AcquireS(); |
| 1833 | } else { |
| 1834 | DCHECK(src_cst->IsDoubleConstant()); |
| 1835 | temp = temps.AcquireD(); |
| 1836 | } |
| 1837 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1838 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1839 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1840 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1841 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1842 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1843 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1844 | // Use any scratch register (a core or a floating-point one) |
| 1845 | // from VIXL scratch register pools as a temporary. |
| 1846 | // |
| 1847 | // We used to only use the FP scratch register pool, but in some |
| 1848 | // rare cases the only register from this pool (D31) would |
| 1849 | // already be used (e.g. within a ParallelMove instruction, when |
| 1850 | // a move is blocked by a another move requiring a scratch FP |
| 1851 | // register, which would reserve D31). To prevent this issue, we |
| 1852 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1853 | // |
| 1854 | // Also, we start by asking for a FP scratch register first, as the |
| 1855 | // demand of scratch core registers is higher. This is why we |
| 1856 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1857 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1858 | // allocates core scratch registers first. |
| 1859 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1860 | GetVIXLAssembler(), |
| 1861 | &temps, |
| 1862 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1863 | __ Ldr(temp, StackOperandFrom(source)); |
| 1864 | __ Str(temp, StackOperandFrom(destination)); |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1870 | CPURegister dst, |
| 1871 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1872 | switch (type) { |
| 1873 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1874 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1875 | break; |
| 1876 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1877 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1878 | break; |
| 1879 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1880 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1881 | break; |
| 1882 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1883 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1884 | break; |
| 1885 | case Primitive::kPrimInt: |
| 1886 | case Primitive::kPrimNot: |
| 1887 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1888 | case Primitive::kPrimFloat: |
| 1889 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1890 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1891 | __ Ldr(dst, src); |
| 1892 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1893 | case Primitive::kPrimVoid: |
| 1894 | LOG(FATAL) << "Unreachable type " << type; |
| 1895 | } |
| 1896 | } |
| 1897 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1898 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1899 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1900 | const MemOperand& src, |
| 1901 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1902 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1903 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1904 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1905 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1906 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1907 | DCHECK(!src.IsPreIndex()); |
| 1908 | DCHECK(!src.IsPostIndex()); |
| 1909 | |
| 1910 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1911 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1912 | { |
| 1913 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1914 | MemOperand base = MemOperand(temp_base); |
| 1915 | switch (type) { |
| 1916 | case Primitive::kPrimBoolean: |
| 1917 | { |
| 1918 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1919 | __ ldarb(Register(dst), base); |
| 1920 | if (needs_null_check) { |
| 1921 | MaybeRecordImplicitNullCheck(instruction); |
| 1922 | } |
| 1923 | } |
| 1924 | break; |
| 1925 | case Primitive::kPrimByte: |
| 1926 | { |
| 1927 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1928 | __ ldarb(Register(dst), base); |
| 1929 | if (needs_null_check) { |
| 1930 | MaybeRecordImplicitNullCheck(instruction); |
| 1931 | } |
| 1932 | } |
| 1933 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1934 | break; |
| 1935 | case Primitive::kPrimChar: |
| 1936 | { |
| 1937 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1938 | __ ldarh(Register(dst), base); |
| 1939 | if (needs_null_check) { |
| 1940 | MaybeRecordImplicitNullCheck(instruction); |
| 1941 | } |
| 1942 | } |
| 1943 | break; |
| 1944 | case Primitive::kPrimShort: |
| 1945 | { |
| 1946 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1947 | __ ldarh(Register(dst), base); |
| 1948 | if (needs_null_check) { |
| 1949 | MaybeRecordImplicitNullCheck(instruction); |
| 1950 | } |
| 1951 | } |
| 1952 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1953 | break; |
| 1954 | case Primitive::kPrimInt: |
| 1955 | case Primitive::kPrimNot: |
| 1956 | case Primitive::kPrimLong: |
| 1957 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 1958 | { |
| 1959 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1960 | __ ldar(Register(dst), base); |
| 1961 | if (needs_null_check) { |
| 1962 | MaybeRecordImplicitNullCheck(instruction); |
| 1963 | } |
| 1964 | } |
| 1965 | break; |
| 1966 | case Primitive::kPrimFloat: |
| 1967 | case Primitive::kPrimDouble: { |
| 1968 | DCHECK(dst.IsFPRegister()); |
| 1969 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1970 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1971 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1972 | { |
| 1973 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1974 | __ ldar(temp, base); |
| 1975 | if (needs_null_check) { |
| 1976 | MaybeRecordImplicitNullCheck(instruction); |
| 1977 | } |
| 1978 | } |
| 1979 | __ Fmov(FPRegister(dst), temp); |
| 1980 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1981 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1982 | case Primitive::kPrimVoid: |
| 1983 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1984 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1985 | } |
| 1986 | } |
| 1987 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1988 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1989 | CPURegister src, |
| 1990 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1991 | switch (type) { |
| 1992 | case Primitive::kPrimBoolean: |
| 1993 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1994 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1995 | break; |
| 1996 | case Primitive::kPrimChar: |
| 1997 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1998 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1999 | break; |
| 2000 | case Primitive::kPrimInt: |
| 2001 | case Primitive::kPrimNot: |
| 2002 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2003 | case Primitive::kPrimFloat: |
| 2004 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2005 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2006 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2007 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2008 | case Primitive::kPrimVoid: |
| 2009 | LOG(FATAL) << "Unreachable type " << type; |
| 2010 | } |
| 2011 | } |
| 2012 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2013 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2014 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2015 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2016 | const MemOperand& dst, |
| 2017 | bool needs_null_check) { |
| 2018 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2019 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2020 | Register temp_base = temps.AcquireX(); |
| 2021 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2022 | DCHECK(!dst.IsPreIndex()); |
| 2023 | DCHECK(!dst.IsPostIndex()); |
| 2024 | |
| 2025 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2026 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2027 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2028 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2029 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2030 | switch (type) { |
| 2031 | case Primitive::kPrimBoolean: |
| 2032 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2033 | { |
| 2034 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2035 | __ stlrb(Register(src), base); |
| 2036 | if (needs_null_check) { |
| 2037 | MaybeRecordImplicitNullCheck(instruction); |
| 2038 | } |
| 2039 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | case Primitive::kPrimChar: |
| 2042 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2043 | { |
| 2044 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2045 | __ stlrh(Register(src), base); |
| 2046 | if (needs_null_check) { |
| 2047 | MaybeRecordImplicitNullCheck(instruction); |
| 2048 | } |
| 2049 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | case Primitive::kPrimInt: |
| 2052 | case Primitive::kPrimNot: |
| 2053 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2054 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2055 | { |
| 2056 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2057 | __ stlr(Register(src), base); |
| 2058 | if (needs_null_check) { |
| 2059 | MaybeRecordImplicitNullCheck(instruction); |
| 2060 | } |
| 2061 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2062 | break; |
| 2063 | case Primitive::kPrimFloat: |
| 2064 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2065 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2066 | Register temp_src; |
| 2067 | if (src.IsZero()) { |
| 2068 | // The zero register is used to avoid synthesizing zero constants. |
| 2069 | temp_src = Register(src); |
| 2070 | } else { |
| 2071 | DCHECK(src.IsFPRegister()); |
| 2072 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2073 | __ Fmov(temp_src, FPRegister(src)); |
| 2074 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2075 | { |
| 2076 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2077 | __ stlr(temp_src, base); |
| 2078 | if (needs_null_check) { |
| 2079 | MaybeRecordImplicitNullCheck(instruction); |
| 2080 | } |
| 2081 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | } |
| 2084 | case Primitive::kPrimVoid: |
| 2085 | LOG(FATAL) << "Unreachable type " << type; |
| 2086 | } |
| 2087 | } |
| 2088 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2089 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2090 | HInstruction* instruction, |
| 2091 | uint32_t dex_pc, |
| 2092 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2093 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2094 | |
| 2095 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2096 | { |
| 2097 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2098 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2099 | __ blr(lr); |
| 2100 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2101 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2102 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2103 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2106 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2107 | HInstruction* instruction, |
| 2108 | SlowPathCode* slow_path) { |
| 2109 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2110 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2111 | __ Blr(lr); |
| 2112 | } |
| 2113 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2114 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2115 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2116 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2117 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2118 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2119 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2120 | // 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] | 2121 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2122 | __ Add(temp, class_reg, status_offset); |
| 2123 | __ Ldar(temp, HeapOperand(temp)); |
| 2124 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2125 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2126 | __ Bind(slow_path->GetExitLabel()); |
| 2127 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2128 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2129 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2130 | BarrierType type = BarrierAll; |
| 2131 | |
| 2132 | switch (kind) { |
| 2133 | case MemBarrierKind::kAnyAny: |
| 2134 | case MemBarrierKind::kAnyStore: { |
| 2135 | type = BarrierAll; |
| 2136 | break; |
| 2137 | } |
| 2138 | case MemBarrierKind::kLoadAny: { |
| 2139 | type = BarrierReads; |
| 2140 | break; |
| 2141 | } |
| 2142 | case MemBarrierKind::kStoreStore: { |
| 2143 | type = BarrierWrites; |
| 2144 | break; |
| 2145 | } |
| 2146 | default: |
| 2147 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2148 | } |
| 2149 | __ Dmb(InnerShareable, type); |
| 2150 | } |
| 2151 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2152 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2153 | HBasicBlock* successor) { |
| 2154 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2155 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2156 | if (slow_path == nullptr) { |
| 2157 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2158 | instruction->SetSlowPath(slow_path); |
| 2159 | codegen_->AddSlowPath(slow_path); |
| 2160 | if (successor != nullptr) { |
| 2161 | DCHECK(successor->IsLoopHeader()); |
| 2162 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2163 | } |
| 2164 | } else { |
| 2165 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2166 | } |
| 2167 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2168 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2169 | Register temp = temps.AcquireW(); |
| 2170 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2171 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2172 | if (successor == nullptr) { |
| 2173 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2174 | __ Bind(slow_path->GetReturnLabel()); |
| 2175 | } else { |
| 2176 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2177 | __ B(slow_path->GetEntryLabel()); |
| 2178 | // slow_path will return to GetLabelOf(successor). |
| 2179 | } |
| 2180 | } |
| 2181 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2182 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2183 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2184 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2185 | assembler_(codegen->GetAssembler()), |
| 2186 | codegen_(codegen) {} |
| 2187 | |
| 2188 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2189 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2190 | |
| 2191 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2192 | |
| 2193 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2194 | // Using a base helps identify when we hit such breakpoints. |
| 2195 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2196 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2197 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2198 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2199 | }; |
| 2200 | |
| 2201 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2202 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2203 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2204 | } \ |
| 2205 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2206 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2207 | locations->SetOut(Location::Any()); \ |
| 2208 | } |
| 2209 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2210 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2211 | |
| 2212 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2213 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2214 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2215 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2216 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2217 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2218 | Primitive::Type type = instr->GetResultType(); |
| 2219 | switch (type) { |
| 2220 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2221 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2222 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2223 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2224 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2225 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2226 | |
| 2227 | case Primitive::kPrimFloat: |
| 2228 | case Primitive::kPrimDouble: |
| 2229 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2230 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2231 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2232 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2233 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2234 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2235 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2239 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2240 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2241 | |
| 2242 | bool object_field_get_with_read_barrier = |
| 2243 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2244 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2245 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2246 | object_field_get_with_read_barrier ? |
| 2247 | LocationSummary::kCallOnSlowPath : |
| 2248 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2249 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2250 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2251 | // We need a temporary register for the read barrier marking slow |
| 2252 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
| 2253 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2254 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2256 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2257 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2258 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2259 | // The output overlaps for an object field get when read barriers |
| 2260 | // are enabled: we do not want the load to overwrite the object's |
| 2261 | // location, as we need it to emit the read barrier. |
| 2262 | locations->SetOut( |
| 2263 | Location::RequiresRegister(), |
| 2264 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2269 | const FieldInfo& field_info) { |
| 2270 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2271 | LocationSummary* locations = instruction->GetLocations(); |
| 2272 | Location base_loc = locations->InAt(0); |
| 2273 | Location out = locations->Out(); |
| 2274 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2275 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2276 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2277 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2278 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2279 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2280 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2281 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2282 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2283 | // Note that potential implicit null checks are handled in this |
| 2284 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2285 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2286 | instruction, |
| 2287 | out, |
| 2288 | base, |
| 2289 | offset, |
| 2290 | temp, |
| 2291 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2292 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2293 | } else { |
| 2294 | // General case. |
| 2295 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2296 | // Note that a potential implicit null check is handled in this |
| 2297 | // CodeGeneratorARM64::LoadAcquire call. |
| 2298 | // NB: LoadAcquire will record the pc info if needed. |
| 2299 | codegen_->LoadAcquire( |
| 2300 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2301 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2302 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2303 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2304 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2306 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2307 | if (field_type == Primitive::kPrimNot) { |
| 2308 | // If read barriers are enabled, emit read barriers other than |
| 2309 | // Baker's using a slow path (and also unpoison the loaded |
| 2310 | // reference, if heap poisoning is enabled). |
| 2311 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2312 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2313 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2317 | LocationSummary* locations = |
| 2318 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2319 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2320 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2321 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2322 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2323 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2324 | } else { |
| 2325 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2330 | const FieldInfo& field_info, |
| 2331 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2332 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2333 | |
| 2334 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2335 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2336 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2337 | Offset offset = field_info.GetFieldOffset(); |
| 2338 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2339 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2340 | { |
| 2341 | // We use a block to end the scratch scope before the write barrier, thus |
| 2342 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2343 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2344 | |
| 2345 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2346 | DCHECK(value.IsW()); |
| 2347 | Register temp = temps.AcquireW(); |
| 2348 | __ Mov(temp, value.W()); |
| 2349 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2350 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2351 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2352 | |
| 2353 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2354 | codegen_->StoreRelease( |
| 2355 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2356 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2357 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2358 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2359 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2360 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2361 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2365 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2366 | } |
| 2367 | } |
| 2368 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2369 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2370 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2371 | |
| 2372 | switch (type) { |
| 2373 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimLong: { |
| 2375 | Register dst = OutputRegister(instr); |
| 2376 | Register lhs = InputRegisterAt(instr, 0); |
| 2377 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2378 | if (instr->IsAdd()) { |
| 2379 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2380 | } else if (instr->IsAnd()) { |
| 2381 | __ And(dst, lhs, rhs); |
| 2382 | } else if (instr->IsOr()) { |
| 2383 | __ Orr(dst, lhs, rhs); |
| 2384 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2385 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2386 | } else if (instr->IsRor()) { |
| 2387 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2388 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2389 | __ Ror(dst, lhs, shift); |
| 2390 | } else { |
| 2391 | // Ensure shift distance is in the same size register as the result. If |
| 2392 | // we are rotating a long and the shift comes in a w register originally, |
| 2393 | // we don't need to sxtw for use as an x since the shift distances are |
| 2394 | // all & reg_bits - 1. |
| 2395 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2396 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2397 | } else { |
| 2398 | DCHECK(instr->IsXor()); |
| 2399 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2400 | } |
| 2401 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2402 | } |
| 2403 | case Primitive::kPrimFloat: |
| 2404 | case Primitive::kPrimDouble: { |
| 2405 | FPRegister dst = OutputFPRegister(instr); |
| 2406 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2407 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2408 | if (instr->IsAdd()) { |
| 2409 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2410 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2411 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2412 | } else { |
| 2413 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2414 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2415 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2416 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2417 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2418 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2422 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2423 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2424 | |
| 2425 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2426 | Primitive::Type type = instr->GetResultType(); |
| 2427 | switch (type) { |
| 2428 | case Primitive::kPrimInt: |
| 2429 | case Primitive::kPrimLong: { |
| 2430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2431 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2432 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2433 | break; |
| 2434 | } |
| 2435 | default: |
| 2436 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2441 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2442 | |
| 2443 | Primitive::Type type = instr->GetType(); |
| 2444 | switch (type) { |
| 2445 | case Primitive::kPrimInt: |
| 2446 | case Primitive::kPrimLong: { |
| 2447 | Register dst = OutputRegister(instr); |
| 2448 | Register lhs = InputRegisterAt(instr, 0); |
| 2449 | Operand rhs = InputOperandAt(instr, 1); |
| 2450 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2451 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2452 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2453 | if (instr->IsShl()) { |
| 2454 | __ Lsl(dst, lhs, shift_value); |
| 2455 | } else if (instr->IsShr()) { |
| 2456 | __ Asr(dst, lhs, shift_value); |
| 2457 | } else { |
| 2458 | __ Lsr(dst, lhs, shift_value); |
| 2459 | } |
| 2460 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2461 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2462 | |
| 2463 | if (instr->IsShl()) { |
| 2464 | __ Lsl(dst, lhs, rhs_reg); |
| 2465 | } else if (instr->IsShr()) { |
| 2466 | __ Asr(dst, lhs, rhs_reg); |
| 2467 | } else { |
| 2468 | __ Lsr(dst, lhs, rhs_reg); |
| 2469 | } |
| 2470 | } |
| 2471 | break; |
| 2472 | } |
| 2473 | default: |
| 2474 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2475 | } |
| 2476 | } |
| 2477 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2478 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2479 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2483 | HandleBinaryOp(instruction); |
| 2484 | } |
| 2485 | |
| 2486 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2487 | HandleBinaryOp(instruction); |
| 2488 | } |
| 2489 | |
| 2490 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2491 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2492 | } |
| 2493 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2494 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2495 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2496 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2497 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2498 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2499 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2500 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2501 | } |
| 2502 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2503 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2504 | Register dst = OutputRegister(instr); |
| 2505 | Register lhs = InputRegisterAt(instr, 0); |
| 2506 | Register rhs = InputRegisterAt(instr, 1); |
| 2507 | |
| 2508 | switch (instr->GetOpKind()) { |
| 2509 | case HInstruction::kAnd: |
| 2510 | __ Bic(dst, lhs, rhs); |
| 2511 | break; |
| 2512 | case HInstruction::kOr: |
| 2513 | __ Orn(dst, lhs, rhs); |
| 2514 | break; |
| 2515 | case HInstruction::kXor: |
| 2516 | __ Eon(dst, lhs, rhs); |
| 2517 | break; |
| 2518 | default: |
| 2519 | LOG(FATAL) << "Unreachable"; |
| 2520 | } |
| 2521 | } |
| 2522 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2523 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2524 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2525 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2526 | instruction->GetType() == Primitive::kPrimLong); |
| 2527 | LocationSummary* locations = |
| 2528 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2529 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2530 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2531 | } else { |
| 2532 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2533 | } |
| 2534 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2535 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2536 | } |
| 2537 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2538 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2539 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2540 | Primitive::Type type = instruction->GetType(); |
| 2541 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2542 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2543 | Register out = OutputRegister(instruction); |
| 2544 | Register left; |
| 2545 | if (kind != HInstruction::kNeg) { |
| 2546 | left = InputRegisterAt(instruction, 0); |
| 2547 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2548 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2549 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2550 | // conversion) can have a different type from the current instruction's type, |
| 2551 | // so we manually indicate the type. |
| 2552 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2553 | Operand right_operand(0); |
| 2554 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2555 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2556 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2557 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2558 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2559 | right_operand = Operand(right_reg, |
| 2560 | helpers::ShiftFromOpKind(op_kind), |
| 2561 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | // Logical binary operations do not support extension operations in the |
| 2565 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2566 | // the extension as a separate instruction. |
| 2567 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2568 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2569 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2570 | kind != HInstruction::kNeg)); |
| 2571 | switch (kind) { |
| 2572 | case HInstruction::kAdd: |
| 2573 | __ Add(out, left, right_operand); |
| 2574 | break; |
| 2575 | case HInstruction::kAnd: |
| 2576 | __ And(out, left, right_operand); |
| 2577 | break; |
| 2578 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2579 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2580 | __ Neg(out, right_operand); |
| 2581 | break; |
| 2582 | case HInstruction::kOr: |
| 2583 | __ Orr(out, left, right_operand); |
| 2584 | break; |
| 2585 | case HInstruction::kSub: |
| 2586 | __ Sub(out, left, right_operand); |
| 2587 | break; |
| 2588 | case HInstruction::kXor: |
| 2589 | __ Eor(out, left, right_operand); |
| 2590 | break; |
| 2591 | default: |
| 2592 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2593 | UNREACHABLE(); |
| 2594 | } |
| 2595 | } |
| 2596 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2597 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2598 | LocationSummary* locations = |
| 2599 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2600 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2601 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2602 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2603 | } |
| 2604 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2605 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2606 | __ Add(OutputRegister(instruction), |
| 2607 | InputRegisterAt(instruction, 0), |
| 2608 | Operand(InputOperandAt(instruction, 1))); |
| 2609 | } |
| 2610 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2611 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2612 | LocationSummary* locations = |
| 2613 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2614 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2615 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2616 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2617 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2618 | // Don't allocate register for Mneg instruction. |
| 2619 | } else { |
| 2620 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2621 | Location::RequiresRegister()); |
| 2622 | } |
| 2623 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2624 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2625 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2626 | } |
| 2627 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2628 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2629 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2630 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2631 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2632 | |
| 2633 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2634 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2635 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2636 | if (instr->GetType() == Primitive::kPrimLong && |
| 2637 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2638 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2639 | vixl::aarch64::Instruction* prev = |
| 2640 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2641 | if (prev->IsLoadOrStore()) { |
| 2642 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2643 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2644 | __ nop(); |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2649 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2650 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2651 | } else { |
| 2652 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2653 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2654 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2655 | __ Mneg(res, mul_left, mul_right); |
| 2656 | } else { |
| 2657 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2658 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2659 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2660 | } |
| 2661 | } |
| 2662 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2663 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2664 | bool object_array_get_with_read_barrier = |
| 2665 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2666 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2667 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2668 | object_array_get_with_read_barrier ? |
| 2669 | LocationSummary::kCallOnSlowPath : |
| 2670 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2671 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2672 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2673 | // We need a temporary register for the read barrier marking slow |
| 2674 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
| 2675 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2676 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2677 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2678 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2679 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2680 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2681 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2682 | // The output overlaps in the case of an object array get with |
| 2683 | // read barriers enabled: we do not want the move to overwrite the |
| 2684 | // array's location, as we need it to emit the read barrier. |
| 2685 | locations->SetOut( |
| 2686 | Location::RequiresRegister(), |
| 2687 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2688 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2692 | Primitive::Type type = instruction->GetType(); |
| 2693 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2694 | LocationSummary* locations = instruction->GetLocations(); |
| 2695 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2696 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2697 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2698 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2699 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2700 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2701 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2702 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2703 | // The read barrier instrumentation of object ArrayGet instructions |
| 2704 | // does not support the HIntermediateAddress instruction. |
| 2705 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2706 | instruction->GetArray()->IsIntermediateAddress() && |
| 2707 | kEmitCompilerReadBarrier)); |
| 2708 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2709 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2710 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2711 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2712 | // Note that a potential implicit null check is handled in the |
| 2713 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2714 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2715 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2716 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2717 | // General case. |
| 2718 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2719 | Register length; |
| 2720 | if (maybe_compressed_char_at) { |
| 2721 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2722 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2723 | { |
| 2724 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2725 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2726 | |
| 2727 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2728 | DCHECK_LT(count_offset, offset); |
| 2729 | int64_t adjusted_offset = |
| 2730 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2731 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2732 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2733 | } else { |
| 2734 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2735 | } |
| 2736 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2737 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2738 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2739 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2740 | if (maybe_compressed_char_at) { |
| 2741 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2742 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2743 | "Expecting 0=compressed, 1=uncompressed"); |
| 2744 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2745 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2746 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2747 | __ B(&done); |
| 2748 | __ Bind(&uncompressed_load); |
| 2749 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2750 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2751 | __ Bind(&done); |
| 2752 | } else { |
| 2753 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2754 | source = HeapOperand(obj, offset); |
| 2755 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2756 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2757 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2758 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2759 | // We do not need to compute the intermediate address from the array: the |
| 2760 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2761 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2762 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2763 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2764 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2765 | } |
| 2766 | temp = obj; |
| 2767 | } else { |
| 2768 | __ Add(temp, obj, offset); |
| 2769 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2770 | if (maybe_compressed_char_at) { |
| 2771 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2772 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2773 | "Expecting 0=compressed, 1=uncompressed"); |
| 2774 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2775 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2776 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2777 | __ B(&done); |
| 2778 | __ Bind(&uncompressed_load); |
| 2779 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2780 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2781 | __ Bind(&done); |
| 2782 | } else { |
| 2783 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2784 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2785 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2786 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2787 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2788 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2789 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2790 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2791 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2792 | |
| 2793 | if (type == Primitive::kPrimNot) { |
| 2794 | static_assert( |
| 2795 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2796 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2797 | Location obj_loc = locations->InAt(0); |
| 2798 | if (index.IsConstant()) { |
| 2799 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2800 | } else { |
| 2801 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2802 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2803 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2804 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2807 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2808 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2809 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2810 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2814 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2815 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2816 | { |
| 2817 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2818 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2819 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2820 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2821 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2822 | // Mask out compression flag from String's array length. |
| 2823 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2824 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2825 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2826 | } |
| 2827 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2828 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2829 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2830 | |
| 2831 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2832 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2833 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2834 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2835 | LocationSummary::kCallOnSlowPath : |
| 2836 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2838 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2839 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2840 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2841 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2842 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2843 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2844 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2849 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2850 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2851 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2852 | bool needs_write_barrier = |
| 2853 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2854 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2855 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2856 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2857 | CPURegister source = value; |
| 2858 | Location index = locations->InAt(1); |
| 2859 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2860 | MemOperand destination = HeapOperand(array); |
| 2861 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2862 | |
| 2863 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2864 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2865 | if (index.IsConstant()) { |
| 2866 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2867 | destination = HeapOperand(array, offset); |
| 2868 | } else { |
| 2869 | UseScratchRegisterScope temps(masm); |
| 2870 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2871 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2872 | // We do not need to compute the intermediate address from the array: the |
| 2873 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2874 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2875 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2876 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2877 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2878 | } |
| 2879 | temp = array; |
| 2880 | } else { |
| 2881 | __ Add(temp, array, offset); |
| 2882 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2883 | destination = HeapOperand(temp, |
| 2884 | XRegisterFrom(index), |
| 2885 | LSL, |
| 2886 | Primitive::ComponentSizeShift(value_type)); |
| 2887 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2888 | { |
| 2889 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2890 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2891 | codegen_->Store(value_type, value, destination); |
| 2892 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2893 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2894 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2895 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2896 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2897 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2898 | { |
| 2899 | // We use a block to end the scratch scope before the write barrier, thus |
| 2900 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2901 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2902 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2903 | if (index.IsConstant()) { |
| 2904 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2905 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2906 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2907 | destination = HeapOperand(temp, |
| 2908 | XRegisterFrom(index), |
| 2909 | LSL, |
| 2910 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2911 | } |
| 2912 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2913 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2914 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2915 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2916 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2917 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2918 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2919 | codegen_->AddSlowPath(slow_path); |
| 2920 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2921 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2922 | __ Cbnz(Register(value), &non_zero); |
| 2923 | if (!index.IsConstant()) { |
| 2924 | __ Add(temp, array, offset); |
| 2925 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2926 | { |
| 2927 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 2928 | // emitted. |
| 2929 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2930 | __ Str(wzr, destination); |
| 2931 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2932 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2933 | __ B(&done); |
| 2934 | __ Bind(&non_zero); |
| 2935 | } |
| 2936 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2937 | // Note that when Baker read barriers are enabled, the type |
| 2938 | // checks are performed without read barriers. This is fine, |
| 2939 | // even in the case where a class object is in the from-space |
| 2940 | // after the flip, as a comparison involving such a type would |
| 2941 | // not produce a false positive; it may of course produce a |
| 2942 | // false negative, in which case we would take the ArraySet |
| 2943 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2944 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2945 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2946 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2947 | { |
| 2948 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2949 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2950 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2951 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2952 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2953 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2954 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2955 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2956 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2957 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2958 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2959 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2960 | // nor `temp2`, as we are comparing two poisoned references. |
| 2961 | __ Cmp(temp, temp2); |
| 2962 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2963 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2964 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2965 | vixl::aarch64::Label do_put; |
| 2966 | __ B(eq, &do_put); |
| 2967 | // If heap poisoning is enabled, the `temp` reference has |
| 2968 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2969 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2970 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2971 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2972 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2973 | // If heap poisoning is enabled, no need to unpoison |
| 2974 | // `temp`, as we are comparing against null below. |
| 2975 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2976 | __ Bind(&do_put); |
| 2977 | } else { |
| 2978 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2983 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2984 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2985 | __ Mov(temp2, value.W()); |
| 2986 | GetAssembler()->PoisonHeapReference(temp2); |
| 2987 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | if (!index.IsConstant()) { |
| 2991 | __ Add(temp, array, offset); |
| 2992 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2993 | { |
| 2994 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2995 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2996 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2997 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2998 | if (!may_need_runtime_call_for_type_check) { |
| 2999 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3000 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3001 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3002 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3003 | |
| 3004 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3005 | |
| 3006 | if (done.IsLinked()) { |
| 3007 | __ Bind(&done); |
| 3008 | } |
| 3009 | |
| 3010 | if (slow_path != nullptr) { |
| 3011 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3012 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3016 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3017 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3018 | InvokeRuntimeCallingConvention calling_convention; |
| 3019 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3020 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3021 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3022 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3023 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3027 | BoundsCheckSlowPathARM64* slow_path = |
| 3028 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3029 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3030 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3031 | __ B(slow_path->GetEntryLabel(), hs); |
| 3032 | } |
| 3033 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3034 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3035 | LocationSummary* locations = |
| 3036 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3037 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3038 | if (check->HasUses()) { |
| 3039 | locations->SetOut(Location::SameAsFirstInput()); |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3044 | // We assume the class is not null. |
| 3045 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3046 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3047 | codegen_->AddSlowPath(slow_path); |
| 3048 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3049 | } |
| 3050 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3051 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3052 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3053 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3054 | } |
| 3055 | |
| 3056 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3057 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3058 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3059 | if (rhs_loc.IsConstant()) { |
| 3060 | // 0.0 is the only immediate that can be encoded directly in |
| 3061 | // an FCMP instruction. |
| 3062 | // |
| 3063 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3064 | // specify that in a floating-point comparison, positive zero |
| 3065 | // and negative zero are considered equal, so we can use the |
| 3066 | // literal 0.0 for both cases here. |
| 3067 | // |
| 3068 | // Note however that some methods (Float.equal, Float.compare, |
| 3069 | // Float.compareTo, Double.equal, Double.compare, |
| 3070 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3071 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3072 | // -0.0. So if we ever translate calls to these methods into a |
| 3073 | // HCompare instruction, we must handle the -0.0 case with |
| 3074 | // care here. |
| 3075 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3076 | __ Fcmp(lhs_reg, 0.0); |
| 3077 | } else { |
| 3078 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3079 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3082 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3083 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3084 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3085 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3086 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3087 | case Primitive::kPrimBoolean: |
| 3088 | case Primitive::kPrimByte: |
| 3089 | case Primitive::kPrimShort: |
| 3090 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3091 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3092 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3093 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3094 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3095 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3096 | break; |
| 3097 | } |
| 3098 | case Primitive::kPrimFloat: |
| 3099 | case Primitive::kPrimDouble: { |
| 3100 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3101 | locations->SetInAt(1, |
| 3102 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3103 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3104 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3105 | locations->SetOut(Location::RequiresRegister()); |
| 3106 | break; |
| 3107 | } |
| 3108 | default: |
| 3109 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3110 | } |
| 3111 | } |
| 3112 | |
| 3113 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3114 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3115 | |
| 3116 | // 0 if: left == right |
| 3117 | // 1 if: left > right |
| 3118 | // -1 if: left < right |
| 3119 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3120 | case Primitive::kPrimBoolean: |
| 3121 | case Primitive::kPrimByte: |
| 3122 | case Primitive::kPrimShort: |
| 3123 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3124 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3125 | case Primitive::kPrimLong: { |
| 3126 | Register result = OutputRegister(compare); |
| 3127 | Register left = InputRegisterAt(compare, 0); |
| 3128 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3129 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3130 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3131 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3132 | break; |
| 3133 | } |
| 3134 | case Primitive::kPrimFloat: |
| 3135 | case Primitive::kPrimDouble: { |
| 3136 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3137 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3138 | __ Cset(result, ne); |
| 3139 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3140 | break; |
| 3141 | } |
| 3142 | default: |
| 3143 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3144 | } |
| 3145 | } |
| 3146 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3147 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3148 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3149 | |
| 3150 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3151 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3152 | locations->SetInAt(1, |
| 3153 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3154 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3155 | : Location::RequiresFpuRegister()); |
| 3156 | } else { |
| 3157 | // Integer cases. |
| 3158 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3159 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3160 | } |
| 3161 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3162 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3167 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3168 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3169 | return; |
| 3170 | } |
| 3171 | |
| 3172 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3173 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3174 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3175 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3176 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3177 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3178 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3179 | } else { |
| 3180 | // Integer cases. |
| 3181 | Register lhs = InputRegisterAt(instruction, 0); |
| 3182 | Operand rhs = InputOperandAt(instruction, 1); |
| 3183 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3184 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3185 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3189 | M(Equal) \ |
| 3190 | M(NotEqual) \ |
| 3191 | M(LessThan) \ |
| 3192 | M(LessThanOrEqual) \ |
| 3193 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3194 | M(GreaterThanOrEqual) \ |
| 3195 | M(Below) \ |
| 3196 | M(BelowOrEqual) \ |
| 3197 | M(Above) \ |
| 3198 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3199 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3200 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3201 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3202 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3203 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3204 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3205 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3206 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3207 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3208 | |
| 3209 | LocationSummary* locations = instruction->GetLocations(); |
| 3210 | Location second = locations->InAt(1); |
| 3211 | DCHECK(second.IsConstant()); |
| 3212 | |
| 3213 | Register out = OutputRegister(instruction); |
| 3214 | Register dividend = InputRegisterAt(instruction, 0); |
| 3215 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3216 | DCHECK(imm == 1 || imm == -1); |
| 3217 | |
| 3218 | if (instruction->IsRem()) { |
| 3219 | __ Mov(out, 0); |
| 3220 | } else { |
| 3221 | if (imm == 1) { |
| 3222 | __ Mov(out, dividend); |
| 3223 | } else { |
| 3224 | __ Neg(out, dividend); |
| 3225 | } |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3230 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3231 | |
| 3232 | LocationSummary* locations = instruction->GetLocations(); |
| 3233 | Location second = locations->InAt(1); |
| 3234 | DCHECK(second.IsConstant()); |
| 3235 | |
| 3236 | Register out = OutputRegister(instruction); |
| 3237 | Register dividend = InputRegisterAt(instruction, 0); |
| 3238 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3239 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3240 | int ctz_imm = CTZ(abs_imm); |
| 3241 | |
| 3242 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3243 | Register temp = temps.AcquireSameSizeAs(out); |
| 3244 | |
| 3245 | if (instruction->IsDiv()) { |
| 3246 | __ Add(temp, dividend, abs_imm - 1); |
| 3247 | __ Cmp(dividend, 0); |
| 3248 | __ Csel(out, temp, dividend, lt); |
| 3249 | if (imm > 0) { |
| 3250 | __ Asr(out, out, ctz_imm); |
| 3251 | } else { |
| 3252 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3253 | } |
| 3254 | } else { |
| 3255 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3256 | __ Asr(temp, dividend, bits - 1); |
| 3257 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3258 | __ Add(out, dividend, temp); |
| 3259 | __ And(out, out, abs_imm - 1); |
| 3260 | __ Sub(out, out, temp); |
| 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3265 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3266 | |
| 3267 | LocationSummary* locations = instruction->GetLocations(); |
| 3268 | Location second = locations->InAt(1); |
| 3269 | DCHECK(second.IsConstant()); |
| 3270 | |
| 3271 | Register out = OutputRegister(instruction); |
| 3272 | Register dividend = InputRegisterAt(instruction, 0); |
| 3273 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3274 | |
| 3275 | Primitive::Type type = instruction->GetResultType(); |
| 3276 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3277 | |
| 3278 | int64_t magic; |
| 3279 | int shift; |
| 3280 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3281 | |
| 3282 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3283 | Register temp = temps.AcquireSameSizeAs(out); |
| 3284 | |
| 3285 | // temp = get_high(dividend * magic) |
| 3286 | __ Mov(temp, magic); |
| 3287 | if (type == Primitive::kPrimLong) { |
| 3288 | __ Smulh(temp, dividend, temp); |
| 3289 | } else { |
| 3290 | __ Smull(temp.X(), dividend, temp); |
| 3291 | __ Lsr(temp.X(), temp.X(), 32); |
| 3292 | } |
| 3293 | |
| 3294 | if (imm > 0 && magic < 0) { |
| 3295 | __ Add(temp, temp, dividend); |
| 3296 | } else if (imm < 0 && magic > 0) { |
| 3297 | __ Sub(temp, temp, dividend); |
| 3298 | } |
| 3299 | |
| 3300 | if (shift != 0) { |
| 3301 | __ Asr(temp, temp, shift); |
| 3302 | } |
| 3303 | |
| 3304 | if (instruction->IsDiv()) { |
| 3305 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3306 | } else { |
| 3307 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3308 | // TODO: Strength reduction for msub. |
| 3309 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3310 | __ Mov(temp_imm, imm); |
| 3311 | __ Msub(out, temp, temp_imm, dividend); |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3316 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3317 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3318 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3319 | |
| 3320 | LocationSummary* locations = instruction->GetLocations(); |
| 3321 | Register out = OutputRegister(instruction); |
| 3322 | Location second = locations->InAt(1); |
| 3323 | |
| 3324 | if (second.IsConstant()) { |
| 3325 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3326 | |
| 3327 | if (imm == 0) { |
| 3328 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3329 | } else if (imm == 1 || imm == -1) { |
| 3330 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3331 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3332 | DivRemByPowerOfTwo(instruction); |
| 3333 | } else { |
| 3334 | DCHECK(imm <= -2 || imm >= 2); |
| 3335 | GenerateDivRemWithAnyConstant(instruction); |
| 3336 | } |
| 3337 | } else { |
| 3338 | Register dividend = InputRegisterAt(instruction, 0); |
| 3339 | Register divisor = InputRegisterAt(instruction, 1); |
| 3340 | if (instruction->IsDiv()) { |
| 3341 | __ Sdiv(out, dividend, divisor); |
| 3342 | } else { |
| 3343 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3344 | Register temp = temps.AcquireSameSizeAs(out); |
| 3345 | __ Sdiv(temp, dividend, divisor); |
| 3346 | __ Msub(out, temp, divisor, dividend); |
| 3347 | } |
| 3348 | } |
| 3349 | } |
| 3350 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3351 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3352 | LocationSummary* locations = |
| 3353 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3354 | switch (div->GetResultType()) { |
| 3355 | case Primitive::kPrimInt: |
| 3356 | case Primitive::kPrimLong: |
| 3357 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3358 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3359 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3360 | break; |
| 3361 | |
| 3362 | case Primitive::kPrimFloat: |
| 3363 | case Primitive::kPrimDouble: |
| 3364 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3365 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3366 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3367 | break; |
| 3368 | |
| 3369 | default: |
| 3370 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3375 | Primitive::Type type = div->GetResultType(); |
| 3376 | switch (type) { |
| 3377 | case Primitive::kPrimInt: |
| 3378 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3379 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3380 | break; |
| 3381 | |
| 3382 | case Primitive::kPrimFloat: |
| 3383 | case Primitive::kPrimDouble: |
| 3384 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3385 | break; |
| 3386 | |
| 3387 | default: |
| 3388 | LOG(FATAL) << "Unexpected div type " << type; |
| 3389 | } |
| 3390 | } |
| 3391 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3392 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3393 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3394 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3398 | SlowPathCodeARM64* slow_path = |
| 3399 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3400 | codegen_->AddSlowPath(slow_path); |
| 3401 | Location value = instruction->GetLocations()->InAt(0); |
| 3402 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3403 | Primitive::Type type = instruction->GetType(); |
| 3404 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3405 | if (!Primitive::IsIntegralType(type)) { |
| 3406 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3407 | return; |
| 3408 | } |
| 3409 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3410 | if (value.IsConstant()) { |
| 3411 | int64_t divisor = Int64ConstantFrom(value); |
| 3412 | if (divisor == 0) { |
| 3413 | __ B(slow_path->GetEntryLabel()); |
| 3414 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3415 | // A division by a non-null constant is valid. We don't need to perform |
| 3416 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3417 | } |
| 3418 | } else { |
| 3419 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3420 | } |
| 3421 | } |
| 3422 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3423 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3424 | LocationSummary* locations = |
| 3425 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3426 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3427 | } |
| 3428 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3429 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3430 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3431 | // Will be generated at use site. |
| 3432 | } |
| 3433 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3434 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3435 | exit->SetLocations(nullptr); |
| 3436 | } |
| 3437 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3438 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3439 | } |
| 3440 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3441 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3442 | LocationSummary* locations = |
| 3443 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3444 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3445 | } |
| 3446 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3447 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3448 | // Will be generated at use site. |
| 3449 | } |
| 3450 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3451 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3452 | DCHECK(!successor->IsExitBlock()); |
| 3453 | HBasicBlock* block = got->GetBlock(); |
| 3454 | HInstruction* previous = got->GetPrevious(); |
| 3455 | HLoopInformation* info = block->GetLoopInformation(); |
| 3456 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3457 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3458 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3459 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3460 | return; |
| 3461 | } |
| 3462 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3463 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3464 | } |
| 3465 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3466 | __ B(codegen_->GetLabelOf(successor)); |
| 3467 | } |
| 3468 | } |
| 3469 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3470 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3471 | got->SetLocations(nullptr); |
| 3472 | } |
| 3473 | |
| 3474 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3475 | HandleGoto(got, got->GetSuccessor()); |
| 3476 | } |
| 3477 | |
| 3478 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3479 | try_boundary->SetLocations(nullptr); |
| 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3483 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3484 | if (!successor->IsExitBlock()) { |
| 3485 | HandleGoto(try_boundary, successor); |
| 3486 | } |
| 3487 | } |
| 3488 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3489 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3490 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3491 | vixl::aarch64::Label* true_target, |
| 3492 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3493 | // FP branching requires both targets to be explicit. If either of the targets |
| 3494 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3495 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3496 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3497 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3498 | if (true_target == nullptr && false_target == nullptr) { |
| 3499 | // Nothing to do. The code always falls through. |
| 3500 | return; |
| 3501 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3502 | // Constant condition, statically compared against "true" (integer value 1). |
| 3503 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3504 | if (true_target != nullptr) { |
| 3505 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3506 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3507 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3508 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3509 | if (false_target != nullptr) { |
| 3510 | __ B(false_target); |
| 3511 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3512 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3513 | return; |
| 3514 | } |
| 3515 | |
| 3516 | // The following code generates these patterns: |
| 3517 | // (1) true_target == nullptr && false_target != nullptr |
| 3518 | // - opposite condition true => branch to false_target |
| 3519 | // (2) true_target != nullptr && false_target == nullptr |
| 3520 | // - condition true => branch to true_target |
| 3521 | // (3) true_target != nullptr && false_target != nullptr |
| 3522 | // - condition true => branch to true_target |
| 3523 | // - branch to false_target |
| 3524 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3525 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3526 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3527 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3528 | if (true_target == nullptr) { |
| 3529 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3530 | } else { |
| 3531 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3532 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3533 | } else { |
| 3534 | // The condition instruction has not been materialized, use its inputs as |
| 3535 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3536 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3537 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3538 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3539 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3540 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3541 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3542 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3543 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3544 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3545 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3546 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3547 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3548 | // Integer cases. |
| 3549 | Register lhs = InputRegisterAt(condition, 0); |
| 3550 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3551 | |
| 3552 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3553 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3554 | if (true_target == nullptr) { |
| 3555 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3556 | non_fallthrough_target = false_target; |
| 3557 | } else { |
| 3558 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3559 | non_fallthrough_target = true_target; |
| 3560 | } |
| 3561 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3562 | 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] | 3563 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3564 | switch (arm64_cond) { |
| 3565 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3566 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3567 | break; |
| 3568 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3569 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3570 | break; |
| 3571 | case lt: |
| 3572 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3573 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | case ge: |
| 3576 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3577 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3578 | break; |
| 3579 | default: |
| 3580 | // Without the `static_cast` the compiler throws an error for |
| 3581 | // `-Werror=sign-promo`. |
| 3582 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3583 | } |
| 3584 | } else { |
| 3585 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3586 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3587 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3588 | } |
| 3589 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3590 | |
| 3591 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3592 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3593 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3594 | __ B(false_target); |
| 3595 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3596 | |
| 3597 | if (fallthrough_target.IsLinked()) { |
| 3598 | __ Bind(&fallthrough_target); |
| 3599 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3600 | } |
| 3601 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3602 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3603 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3604 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3610 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3611 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3612 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3613 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3614 | true_target = nullptr; |
| 3615 | } |
| 3616 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3617 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3618 | false_target = nullptr; |
| 3619 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3620 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3624 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3625 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3626 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3627 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3633 | SlowPathCodeARM64* slow_path = |
| 3634 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3635 | GenerateTestAndBranch(deoptimize, |
| 3636 | /* condition_input_index */ 0, |
| 3637 | slow_path->GetEntryLabel(), |
| 3638 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3641 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3642 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3643 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3644 | locations->SetOut(Location::RequiresRegister()); |
| 3645 | } |
| 3646 | |
| 3647 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3648 | __ Ldr(OutputRegister(flag), |
| 3649 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3650 | } |
| 3651 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3652 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3653 | return condition->IsCondition() && |
| 3654 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3655 | } |
| 3656 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3657 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3658 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3659 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3660 | : ARM64Condition(cond); |
| 3661 | } |
| 3662 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3663 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3664 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3665 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3667 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3668 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3669 | } else { |
| 3670 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3671 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3672 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3673 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3674 | // Ask VIXL whether we should synthesize constants in registers. |
| 3675 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3676 | Operand true_op = is_true_value_constant ? |
| 3677 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3678 | Operand false_op = is_false_value_constant ? |
| 3679 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3680 | bool true_value_in_register = false; |
| 3681 | bool false_value_in_register = false; |
| 3682 | MacroAssembler::GetCselSynthesisInformation( |
| 3683 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3684 | true_value_in_register |= !is_true_value_constant; |
| 3685 | false_value_in_register |= !is_false_value_constant; |
| 3686 | |
| 3687 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3688 | : Location::ConstantLocation(cst_true_value)); |
| 3689 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3690 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3691 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3692 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3693 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3694 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3695 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3696 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3700 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3701 | Condition csel_cond; |
| 3702 | |
| 3703 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3704 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3705 | // Use the condition flags set by the previous instruction. |
| 3706 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3707 | } else { |
| 3708 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3709 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3710 | } |
| 3711 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3712 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3713 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3714 | } else { |
| 3715 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3716 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3717 | } |
| 3718 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3719 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3720 | __ Fcsel(OutputFPRegister(select), |
| 3721 | InputFPRegisterAt(select, 1), |
| 3722 | InputFPRegisterAt(select, 0), |
| 3723 | csel_cond); |
| 3724 | } else { |
| 3725 | __ Csel(OutputRegister(select), |
| 3726 | InputOperandAt(select, 1), |
| 3727 | InputOperandAt(select, 0), |
| 3728 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3729 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3732 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3733 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3734 | } |
| 3735 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3736 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3737 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | void CodeGeneratorARM64::GenerateNop() { |
| 3741 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3742 | } |
| 3743 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3744 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3745 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3749 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3753 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3757 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3758 | } |
| 3759 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3760 | // Temp is used for read barrier. |
| 3761 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3762 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3763 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3764 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3765 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3766 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3767 | return 1; |
| 3768 | } |
| 3769 | return 0; |
| 3770 | } |
| 3771 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3772 | // 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] | 3773 | // interface pointer, one for loading the current interface. |
| 3774 | // The other checks have one temp for loading the object's class. |
| 3775 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3776 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3777 | return 3; |
| 3778 | } |
| 3779 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3780 | } |
| 3781 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3782 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3783 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3784 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3785 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3786 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3787 | case TypeCheckKind::kExactCheck: |
| 3788 | case TypeCheckKind::kAbstractClassCheck: |
| 3789 | case TypeCheckKind::kClassHierarchyCheck: |
| 3790 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3791 | call_kind = |
| 3792 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3793 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3794 | break; |
| 3795 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3796 | case TypeCheckKind::kUnresolvedCheck: |
| 3797 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3798 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3799 | break; |
| 3800 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3801 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3802 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3803 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3804 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3805 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3807 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3808 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3809 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3810 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3811 | // Add temps if necessary for read barriers. |
| 3812 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3816 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3817 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3818 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3819 | Register obj = InputRegisterAt(instruction, 0); |
| 3820 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3821 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3822 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3823 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3824 | DCHECK_LE(num_temps, 1u); |
| 3825 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3826 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3827 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3828 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3829 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3830 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3831 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3832 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3833 | |
| 3834 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3835 | // Avoid null check if we know `obj` is not null. |
| 3836 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3837 | __ Cbz(obj, &zero); |
| 3838 | } |
| 3839 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3840 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3841 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3842 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3843 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3844 | out_loc, |
| 3845 | obj_loc, |
| 3846 | class_offset, |
| 3847 | maybe_temp_loc, |
| 3848 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3849 | __ Cmp(out, cls); |
| 3850 | __ Cset(out, eq); |
| 3851 | if (zero.IsLinked()) { |
| 3852 | __ B(&done); |
| 3853 | } |
| 3854 | break; |
| 3855 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3856 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3857 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3858 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3859 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3860 | out_loc, |
| 3861 | obj_loc, |
| 3862 | class_offset, |
| 3863 | maybe_temp_loc, |
| 3864 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3865 | // If the class is abstract, we eagerly fetch the super class of the |
| 3866 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3867 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3868 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3869 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3870 | GenerateReferenceLoadOneRegister(instruction, |
| 3871 | out_loc, |
| 3872 | super_offset, |
| 3873 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3874 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3875 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3876 | __ Cbz(out, &done); |
| 3877 | __ Cmp(out, cls); |
| 3878 | __ B(ne, &loop); |
| 3879 | __ Mov(out, 1); |
| 3880 | if (zero.IsLinked()) { |
| 3881 | __ B(&done); |
| 3882 | } |
| 3883 | break; |
| 3884 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3885 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3886 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3887 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3888 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3889 | out_loc, |
| 3890 | obj_loc, |
| 3891 | class_offset, |
| 3892 | maybe_temp_loc, |
| 3893 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3894 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3895 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3896 | __ Bind(&loop); |
| 3897 | __ Cmp(out, cls); |
| 3898 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3899 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3900 | GenerateReferenceLoadOneRegister(instruction, |
| 3901 | out_loc, |
| 3902 | super_offset, |
| 3903 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3904 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3905 | __ Cbnz(out, &loop); |
| 3906 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3907 | __ B(&done); |
| 3908 | __ Bind(&success); |
| 3909 | __ Mov(out, 1); |
| 3910 | if (zero.IsLinked()) { |
| 3911 | __ B(&done); |
| 3912 | } |
| 3913 | break; |
| 3914 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3915 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3916 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3917 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3918 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3919 | out_loc, |
| 3920 | obj_loc, |
| 3921 | class_offset, |
| 3922 | maybe_temp_loc, |
| 3923 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3924 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3925 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3926 | __ Cmp(out, cls); |
| 3927 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3928 | // 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] | 3929 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3930 | GenerateReferenceLoadOneRegister(instruction, |
| 3931 | out_loc, |
| 3932 | component_offset, |
| 3933 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3934 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3935 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3936 | __ Cbz(out, &done); |
| 3937 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3938 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3939 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3940 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3941 | __ Mov(out, 1); |
| 3942 | __ B(&done); |
| 3943 | break; |
| 3944 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3945 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3947 | // No read barrier since the slow path will retry upon failure. |
| 3948 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3949 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3950 | out_loc, |
| 3951 | obj_loc, |
| 3952 | class_offset, |
| 3953 | maybe_temp_loc, |
| 3954 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3955 | __ Cmp(out, cls); |
| 3956 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3957 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3958 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3959 | codegen_->AddSlowPath(slow_path); |
| 3960 | __ B(ne, slow_path->GetEntryLabel()); |
| 3961 | __ Mov(out, 1); |
| 3962 | if (zero.IsLinked()) { |
| 3963 | __ B(&done); |
| 3964 | } |
| 3965 | break; |
| 3966 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3967 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3968 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3969 | case TypeCheckKind::kInterfaceCheck: { |
| 3970 | // Note that we indeed only call on slow path, but we always go |
| 3971 | // into the slow path for the unresolved and interface check |
| 3972 | // cases. |
| 3973 | // |
| 3974 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3975 | // entry point without resorting to a type checking slow path |
| 3976 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3977 | // require to assign fixed registers for the inputs of this |
| 3978 | // HInstanceOf instruction (following the runtime calling |
| 3979 | // convention), which might be cluttered by the potential first |
| 3980 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3981 | // |
| 3982 | // TODO: Introduce a new runtime entry point taking the object |
| 3983 | // to test (instead of its class) as argument, and let it deal |
| 3984 | // with the read barrier issues. This will let us refactor this |
| 3985 | // case of the `switch` code as it was previously (with a direct |
| 3986 | // call to the runtime not using a type checking slow path). |
| 3987 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3988 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3989 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3990 | /* is_fatal */ false); |
| 3991 | codegen_->AddSlowPath(slow_path); |
| 3992 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3993 | if (zero.IsLinked()) { |
| 3994 | __ B(&done); |
| 3995 | } |
| 3996 | break; |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | if (zero.IsLinked()) { |
| 4001 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4002 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | if (done.IsLinked()) { |
| 4006 | __ Bind(&done); |
| 4007 | } |
| 4008 | |
| 4009 | if (slow_path != nullptr) { |
| 4010 | __ Bind(slow_path->GetExitLabel()); |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4015 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4016 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4017 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4018 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4019 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4020 | case TypeCheckKind::kExactCheck: |
| 4021 | case TypeCheckKind::kAbstractClassCheck: |
| 4022 | case TypeCheckKind::kClassHierarchyCheck: |
| 4023 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4024 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4025 | LocationSummary::kCallOnSlowPath : |
| 4026 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4027 | break; |
| 4028 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4029 | case TypeCheckKind::kUnresolvedCheck: |
| 4030 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4032 | break; |
| 4033 | } |
| 4034 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4035 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4036 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4037 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4038 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4039 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4043 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4044 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4045 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4046 | Register obj = InputRegisterAt(instruction, 0); |
| 4047 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4048 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4049 | DCHECK_GE(num_temps, 1u); |
| 4050 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4051 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4052 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4053 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4054 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4055 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4056 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4057 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4058 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4059 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4060 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4061 | const uint32_t object_array_data_offset = |
| 4062 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4063 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4064 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4065 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4066 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4067 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4068 | if (!kEmitCompilerReadBarrier) { |
| 4069 | is_type_check_slow_path_fatal = |
| 4070 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4071 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4072 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4073 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4074 | !instruction->CanThrowIntoCatchBlock(); |
| 4075 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4076 | SlowPathCodeARM64* type_check_slow_path = |
| 4077 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4078 | is_type_check_slow_path_fatal); |
| 4079 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4080 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4081 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4082 | // Avoid null check if we know obj is not null. |
| 4083 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4084 | __ Cbz(obj, &done); |
| 4085 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4086 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4087 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4088 | case TypeCheckKind::kExactCheck: |
| 4089 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4090 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4091 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4092 | temp_loc, |
| 4093 | obj_loc, |
| 4094 | class_offset, |
| 4095 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4096 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4097 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4098 | __ Cmp(temp, cls); |
| 4099 | // Jump to slow path for throwing the exception or doing a |
| 4100 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4101 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4102 | break; |
| 4103 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4104 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4105 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4106 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4107 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4108 | temp_loc, |
| 4109 | obj_loc, |
| 4110 | class_offset, |
| 4111 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4112 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4113 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4114 | // If the class is abstract, we eagerly fetch the super class of the |
| 4115 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4116 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4117 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4118 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4119 | GenerateReferenceLoadOneRegister(instruction, |
| 4120 | temp_loc, |
| 4121 | super_offset, |
| 4122 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4123 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4124 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4125 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4126 | // exception. |
| 4127 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4128 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4129 | __ Cmp(temp, cls); |
| 4130 | __ B(ne, &loop); |
| 4131 | break; |
| 4132 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4133 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4134 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4135 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4136 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4137 | temp_loc, |
| 4138 | obj_loc, |
| 4139 | class_offset, |
| 4140 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4141 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4142 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4143 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4144 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4145 | __ Bind(&loop); |
| 4146 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4147 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4148 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4149 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4150 | GenerateReferenceLoadOneRegister(instruction, |
| 4151 | temp_loc, |
| 4152 | super_offset, |
| 4153 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4154 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4155 | |
| 4156 | // If the class reference currently in `temp` is not null, jump |
| 4157 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4158 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4159 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4160 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4161 | break; |
| 4162 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4163 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4164 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4165 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4166 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4167 | temp_loc, |
| 4168 | obj_loc, |
| 4169 | class_offset, |
| 4170 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4171 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4172 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4173 | // Do an exact check. |
| 4174 | __ Cmp(temp, cls); |
| 4175 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4176 | |
| 4177 | // 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] | 4178 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4179 | GenerateReferenceLoadOneRegister(instruction, |
| 4180 | temp_loc, |
| 4181 | component_offset, |
| 4182 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4183 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4184 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4185 | // If the component type is null, jump to the slow path to throw the exception. |
| 4186 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4187 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4188 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4189 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4190 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4191 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4192 | break; |
| 4193 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4194 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4195 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4196 | // 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] | 4197 | // |
| 4198 | // We cannot directly call the CheckCast runtime entry point |
| 4199 | // without resorting to a type checking slow path here (i.e. by |
| 4200 | // calling InvokeRuntime directly), as it would require to |
| 4201 | // assign fixed registers for the inputs of this HInstanceOf |
| 4202 | // instruction (following the runtime calling convention), which |
| 4203 | // might be cluttered by the potential first read barrier |
| 4204 | // emission at the beginning of this method. |
| 4205 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4206 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4207 | case TypeCheckKind::kInterfaceCheck: { |
| 4208 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4209 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4210 | temp_loc, |
| 4211 | obj_loc, |
| 4212 | class_offset, |
| 4213 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4214 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4215 | |
| 4216 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4217 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4218 | temp_loc, |
| 4219 | temp_loc, |
| 4220 | iftable_offset, |
| 4221 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4222 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4223 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4224 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4225 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4226 | vixl::aarch64::Label start_loop; |
| 4227 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4228 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4229 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4230 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4231 | // Go to next interface. |
| 4232 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4233 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4234 | // Compare the classes and continue the loop if they do not match. |
| 4235 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4236 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4237 | break; |
| 4238 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4239 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4240 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4241 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4242 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4243 | } |
| 4244 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4245 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4246 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4247 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4248 | } |
| 4249 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4250 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4251 | // Will be generated at use site. |
| 4252 | } |
| 4253 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4254 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4255 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4256 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4257 | } |
| 4258 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4259 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4260 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4261 | } |
| 4262 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4263 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4264 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4265 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4266 | // the method_idx. |
| 4267 | HandleInvoke(invoke); |
| 4268 | } |
| 4269 | |
| 4270 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4271 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4272 | } |
| 4273 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4274 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4275 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4276 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4277 | } |
| 4278 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4279 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4280 | HandleInvoke(invoke); |
| 4281 | } |
| 4282 | |
| 4283 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4284 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4285 | LocationSummary* locations = invoke->GetLocations(); |
| 4286 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4287 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4288 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4289 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4290 | |
| 4291 | // The register ip1 is required to be used for the hidden argument in |
| 4292 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4293 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4294 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4295 | scratch_scope.Exclude(ip1); |
| 4296 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4297 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4298 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4299 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4300 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4301 | { |
| 4302 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4303 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4304 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4305 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4306 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4307 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4308 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4309 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4310 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4311 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4312 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4313 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4314 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4315 | // emit a read barrier for the previous class reference load. |
| 4316 | // However this is not required in practice, as this is an |
| 4317 | // intermediate/temporary reference and because the current |
| 4318 | // concurrent copying collector keeps the from-space memory |
| 4319 | // intact/accessible until the end of the marking phase (the |
| 4320 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4321 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4322 | __ Ldr(temp, |
| 4323 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4324 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4325 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4326 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4327 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4328 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4329 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4330 | |
| 4331 | { |
| 4332 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4333 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4334 | |
| 4335 | // lr(); |
| 4336 | __ blr(lr); |
| 4337 | DCHECK(!codegen_->IsLeafMethod()); |
| 4338 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4339 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4343 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4344 | if (intrinsic.TryDispatch(invoke)) { |
| 4345 | return; |
| 4346 | } |
| 4347 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4348 | HandleInvoke(invoke); |
| 4349 | } |
| 4350 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4351 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4352 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4353 | // art::PrepareForRegisterAllocation. |
| 4354 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4355 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4356 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4357 | if (intrinsic.TryDispatch(invoke)) { |
| 4358 | return; |
| 4359 | } |
| 4360 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4361 | HandleInvoke(invoke); |
| 4362 | } |
| 4363 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4364 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4365 | if (invoke->GetLocations()->Intrinsified()) { |
| 4366 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4367 | intrinsic.Dispatch(invoke); |
| 4368 | return true; |
| 4369 | } |
| 4370 | return false; |
| 4371 | } |
| 4372 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4373 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4374 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4375 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4376 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4377 | return desired_dispatch_info; |
| 4378 | } |
| 4379 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 4380 | Location CodeGeneratorARM64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4381 | Location temp) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4382 | // 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] | 4383 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4384 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4385 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4386 | uint32_t offset = |
| 4387 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4388 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4389 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4390 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4391 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4392 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4393 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4394 | break; |
| 4395 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4396 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4397 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4398 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4399 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4400 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4401 | const DexFile& dex_file = invoke->GetDexFileForPcRelativeDexCache(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4402 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4403 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4404 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4405 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4406 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4407 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4408 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4409 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4410 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4411 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4412 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4413 | Register reg = XRegisterFrom(temp); |
| 4414 | Register method_reg; |
| 4415 | if (current_method.IsRegister()) { |
| 4416 | method_reg = XRegisterFrom(current_method); |
| 4417 | } else { |
| 4418 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4419 | DCHECK(!current_method.IsValid()); |
| 4420 | method_reg = reg; |
| 4421 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 4422 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 4423 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4424 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4425 | __ Ldr(reg.X(), |
| 4426 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4427 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4428 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4429 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4430 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4431 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 4432 | break; |
| 4433 | } |
| 4434 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 4435 | return callee_method; |
| 4436 | } |
| 4437 | |
| 4438 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4439 | // All registers are assumed to be correctly set up. |
| 4440 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4441 | |
| 4442 | switch (invoke->GetCodePtrLocation()) { |
| 4443 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4444 | __ Bl(&frame_entry_label_); |
| 4445 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4446 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4447 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4448 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4449 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4450 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4451 | { |
| 4452 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4453 | // BLR must be the last instruction emitted in this function. |
| 4454 | // Recording the pc will occur right after returning from this function. |
| 4455 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4456 | kInstructionSize, |
| 4457 | CodeBufferCheckScope::kExactSize); |
| 4458 | // lr() |
| 4459 | __ blr(lr); |
| 4460 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4461 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4462 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4463 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4464 | DCHECK(!IsLeafMethod()); |
| 4465 | } |
| 4466 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4467 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4468 | // Use the calling convention instead of the location of the receiver, as |
| 4469 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4470 | // slow path, the arguments have been moved to the right place, so here we are |
| 4471 | // guaranteed that the receiver is the first register of the calling convention. |
| 4472 | InvokeDexCallingConvention calling_convention; |
| 4473 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4474 | Register temp = XRegisterFrom(temp_in); |
| 4475 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4476 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4477 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4478 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4479 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4480 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4481 | |
| 4482 | { |
| 4483 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4484 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4485 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4486 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4487 | MaybeRecordImplicitNullCheck(invoke); |
| 4488 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4489 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4490 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4491 | // intermediate/temporary reference and because the current |
| 4492 | // concurrent copying collector keeps the from-space memory |
| 4493 | // intact/accessible until the end of the marking phase (the |
| 4494 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4495 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4496 | // temp = temp->GetMethodAt(method_offset); |
| 4497 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4498 | // lr = temp->GetEntryPoint(); |
| 4499 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4500 | { |
| 4501 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4502 | // BLR should be the last instruction emitted in this function. |
| 4503 | // Recording the pc will occur right after returning from this function. |
| 4504 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4505 | // lr(); |
| 4506 | __ blr(lr); |
| 4507 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4510 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4511 | HandleInvoke(invoke); |
| 4512 | } |
| 4513 | |
| 4514 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4515 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4516 | } |
| 4517 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4518 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4519 | const DexFile& dex_file, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4520 | dex::StringIndex string_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4521 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4522 | return |
| 4523 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4526 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4527 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4528 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4529 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4530 | 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] | 4531 | } |
| 4532 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4533 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4534 | const DexFile& dex_file, |
| 4535 | dex::TypeIndex type_index, |
| 4536 | vixl::aarch64::Label* adrp_label) { |
| 4537 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4538 | } |
| 4539 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4540 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4541 | const DexFile& dex_file, |
| 4542 | uint32_t element_offset, |
| 4543 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4544 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4545 | } |
| 4546 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4547 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4548 | const DexFile& dex_file, |
| 4549 | uint32_t offset_or_index, |
| 4550 | vixl::aarch64::Label* adrp_label, |
| 4551 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4552 | // Add a patch entry and return the label. |
| 4553 | patches->emplace_back(dex_file, offset_or_index); |
| 4554 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4555 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4556 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4557 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4558 | return label; |
| 4559 | } |
| 4560 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4561 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4562 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4563 | return boot_image_string_patches_.GetOrCreate( |
| 4564 | StringReference(&dex_file, string_index), |
| 4565 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4566 | } |
| 4567 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4568 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4569 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4570 | return boot_image_type_patches_.GetOrCreate( |
| 4571 | TypeReference(&dex_file, type_index), |
| 4572 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4573 | } |
| 4574 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4575 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4576 | uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 4577 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4580 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4581 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4582 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4583 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4584 | return jit_string_patches_.GetOrCreate( |
| 4585 | StringReference(&dex_file, string_index), |
| 4586 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4587 | } |
| 4588 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4589 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4590 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4591 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4592 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4593 | return jit_class_patches_.GetOrCreate( |
| 4594 | TypeReference(&dex_file, type_index), |
| 4595 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4596 | } |
| 4597 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4598 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4599 | vixl::aarch64::Register reg) { |
| 4600 | DCHECK(reg.IsX()); |
| 4601 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4602 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4603 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4607 | vixl::aarch64::Register out, |
| 4608 | vixl::aarch64::Register base) { |
| 4609 | DCHECK(out.IsX()); |
| 4610 | DCHECK(base.IsX()); |
| 4611 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4612 | __ Bind(fixup_label); |
| 4613 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4614 | } |
| 4615 | |
| 4616 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4617 | vixl::aarch64::Register out, |
| 4618 | vixl::aarch64::Register base) { |
| 4619 | DCHECK(base.IsX()); |
| 4620 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4621 | __ Bind(fixup_label); |
| 4622 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4623 | } |
| 4624 | |
| 4625 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4626 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4627 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4628 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4629 | for (const PcRelativePatchInfo& info : infos) { |
| 4630 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4631 | &info.target_dex_file, |
| 4632 | info.pc_insn_label->GetLocation(), |
| 4633 | info.offset_or_index)); |
| 4634 | } |
| 4635 | } |
| 4636 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4637 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4638 | DCHECK(linker_patches->empty()); |
| 4639 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4640 | pc_relative_dex_cache_patches_.size() + |
| 4641 | boot_image_string_patches_.size() + |
| 4642 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4643 | boot_image_type_patches_.size() + |
| 4644 | pc_relative_type_patches_.size() + |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 4645 | type_bss_entry_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4646 | linker_patches->reserve(size); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4647 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4648 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4649 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4650 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4651 | info.offset_or_index)); |
| 4652 | } |
| 4653 | for (const auto& entry : boot_image_string_patches_) { |
| 4654 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4655 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4656 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4657 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4658 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4659 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4660 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4661 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4662 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4663 | linker_patches); |
| 4664 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4665 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4666 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4667 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4668 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4669 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4670 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4671 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4672 | for (const auto& entry : boot_image_type_patches_) { |
| 4673 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4674 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4675 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4676 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4677 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4678 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4679 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4680 | } |
| 4681 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4682 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4683 | Uint32ToLiteralMap* map) { |
| 4684 | return map->GetOrCreate( |
| 4685 | value, |
| 4686 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4687 | } |
| 4688 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4689 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4690 | return uint64_literals_.GetOrCreate( |
| 4691 | value, |
| 4692 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4695 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4696 | MethodReference target_method, |
| 4697 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4698 | return map->GetOrCreate( |
| 4699 | target_method, |
| 4700 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4701 | } |
| 4702 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4703 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4704 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4705 | // art::PrepareForRegisterAllocation. |
| 4706 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4707 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4708 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4709 | return; |
| 4710 | } |
| 4711 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4712 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4713 | // are no pools emitted. |
| 4714 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4715 | LocationSummary* locations = invoke->GetLocations(); |
| 4716 | codegen_->GenerateStaticOrDirectCall( |
| 4717 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4718 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4722 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4723 | return; |
| 4724 | } |
| 4725 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4726 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4727 | // are no pools emitted. |
| 4728 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4729 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4730 | DCHECK(!codegen_->IsLeafMethod()); |
| 4731 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4732 | } |
| 4733 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4734 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4735 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4736 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4737 | case HLoadClass::LoadKind::kInvalid: |
| 4738 | LOG(FATAL) << "UNREACHABLE"; |
| 4739 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4740 | case HLoadClass::LoadKind::kReferrersClass: |
| 4741 | break; |
| 4742 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4743 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4744 | break; |
| 4745 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4746 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4747 | break; |
| 4748 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4749 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4750 | case HLoadClass::LoadKind::kBssEntry: |
| 4751 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4752 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4753 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4754 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4755 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4756 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4757 | break; |
| 4758 | } |
| 4759 | return desired_class_load_kind; |
| 4760 | } |
| 4761 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4762 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4763 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4764 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4765 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4766 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4767 | cls, |
| 4768 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4769 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4770 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4771 | return; |
| 4772 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4773 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4774 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4775 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4776 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4777 | ? LocationSummary::kCallOnSlowPath |
| 4778 | : LocationSummary::kNoCall; |
| 4779 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4780 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4781 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4784 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4786 | } |
| 4787 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4788 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4789 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4790 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 4791 | // Note that IP0 may be clobbered by saving/restoring the live register (only one thanks |
| 4792 | // to the custom calling convention) or by marking, so we shall use IP1. |
| 4793 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4794 | InvokeRuntimeCallingConvention calling_convention; |
| 4795 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4796 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4797 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4798 | Primitive::kPrimNot).GetCode()); |
| 4799 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4800 | } else { |
| 4801 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4802 | } |
| 4803 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4806 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4807 | // move. |
| 4808 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4809 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4810 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4811 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4812 | return; |
| 4813 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4814 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4815 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4816 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4817 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4818 | Register bss_entry_temp; |
| 4819 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4820 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4821 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4822 | ? kWithoutReadBarrier |
| 4823 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4824 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4825 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4826 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4827 | DCHECK(!cls->CanCallRuntime()); |
| 4828 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4829 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4830 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4831 | GenerateGcRootFieldLoad(cls, |
| 4832 | out_loc, |
| 4833 | current_method, |
| 4834 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4835 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4836 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4837 | break; |
| 4838 | } |
| 4839 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4840 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4841 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4842 | cls->GetTypeIndex())); |
| 4843 | break; |
| 4844 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4845 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4846 | // Add ADRP with its PC-relative type patch. |
| 4847 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4848 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4849 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4850 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4851 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4852 | vixl::aarch64::Label* add_label = |
| 4853 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4854 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4855 | break; |
| 4856 | } |
| 4857 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4858 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4859 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4860 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4861 | DCHECK_NE(address, 0u); |
| 4862 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4863 | break; |
| 4864 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4865 | case HLoadClass::LoadKind::kBssEntry: { |
| 4866 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4867 | const DexFile& dex_file = cls->GetDexFile(); |
| 4868 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4869 | // We can go to slow path even with non-zero reference and in that case marking |
| 4870 | // can clobber IP0, so we need to use IP1 which shall be preserved. |
| 4871 | bss_entry_temp = ip1; |
| 4872 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4873 | temps.Exclude(bss_entry_temp); |
| 4874 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4875 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4876 | // Add LDR with its PC-relative Class patch. |
| 4877 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4878 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4879 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4880 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4881 | out_loc, |
| 4882 | bss_entry_temp, |
| 4883 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4884 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4885 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4886 | generate_null_check = true; |
| 4887 | break; |
| 4888 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4889 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4890 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4891 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4892 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4893 | GenerateGcRootFieldLoad(cls, |
| 4894 | out_loc, |
| 4895 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4896 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4897 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4898 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4899 | break; |
| 4900 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4901 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4902 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4903 | LOG(FATAL) << "UNREACHABLE"; |
| 4904 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4905 | } |
| 4906 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4907 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4908 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4909 | DCHECK(cls->CanCallRuntime()); |
| 4910 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4911 | 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] | 4912 | codegen_->AddSlowPath(slow_path); |
| 4913 | if (generate_null_check) { |
| 4914 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4915 | } |
| 4916 | if (cls->MustGenerateClinitCheck()) { |
| 4917 | GenerateClassInitializationCheck(slow_path, out); |
| 4918 | } else { |
| 4919 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4920 | } |
| 4921 | } |
| 4922 | } |
| 4923 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4924 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4925 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4926 | } |
| 4927 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4928 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4929 | LocationSummary* locations = |
| 4930 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4931 | locations->SetOut(Location::RequiresRegister()); |
| 4932 | } |
| 4933 | |
| 4934 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4935 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4936 | } |
| 4937 | |
| 4938 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4939 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4940 | } |
| 4941 | |
| 4942 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4943 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4946 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4947 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4948 | switch (desired_string_load_kind) { |
| 4949 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4950 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4951 | break; |
| 4952 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4953 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4954 | break; |
| 4955 | case HLoadString::LoadKind::kBootImageAddress: |
| 4956 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4957 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4958 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4959 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4960 | case HLoadString::LoadKind::kJitTableAddress: |
| 4961 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4962 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4963 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4964 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4965 | } |
| 4966 | return desired_string_load_kind; |
| 4967 | } |
| 4968 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4969 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4970 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4971 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4972 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4973 | InvokeRuntimeCallingConvention calling_convention; |
| 4974 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4975 | } else { |
| 4976 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4977 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4978 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4979 | // Rely on the pResolveString and marking to save everything we need. |
| 4980 | // Note that IP0 may be clobbered by saving/restoring the live register (only one thanks |
| 4981 | // to the custom calling convention) or by marking, so we shall use IP1. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4982 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4983 | InvokeRuntimeCallingConvention calling_convention; |
| 4984 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4985 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4986 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4987 | Primitive::kPrimNot).GetCode()); |
| 4988 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4989 | } else { |
| 4990 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4991 | } |
| 4992 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4993 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4996 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4997 | // move. |
| 4998 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4999 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5000 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5001 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5002 | switch (load->GetLoadKind()) { |
| 5003 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5004 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5005 | load->GetStringIndex())); |
| 5006 | return; // No dex cache slow path. |
| 5007 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5008 | // Add ADRP with its PC-relative String patch. |
| 5009 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5010 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5011 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5012 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5013 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5014 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5015 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5016 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5017 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5018 | return; // No dex cache slow path. |
| 5019 | } |
| 5020 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5021 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5022 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5023 | DCHECK_NE(address, 0u); |
| 5024 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5025 | return; // No dex cache slow path. |
| 5026 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5027 | case HLoadString::LoadKind::kBssEntry: { |
| 5028 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5029 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5030 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5031 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5032 | // We could use IP0 as the marking shall not clobber IP0 if the reference is null and |
| 5033 | // that's when we need the slow path. But let's not rely on such details and use IP1. |
| 5034 | Register temp = ip1; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5035 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5036 | temps.Exclude(temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5037 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5038 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5039 | // Add LDR with its PC-relative String patch. |
| 5040 | vixl::aarch64::Label* ldr_label = |
| 5041 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5042 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5043 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5044 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5045 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5046 | /* offset placeholder */ 0u, |
| 5047 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5048 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5049 | SlowPathCodeARM64* slow_path = |
| 5050 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5051 | codegen_->AddSlowPath(slow_path); |
| 5052 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5053 | __ Bind(slow_path->GetExitLabel()); |
| 5054 | return; |
| 5055 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5056 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5057 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5058 | load->GetStringIndex(), |
| 5059 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5060 | GenerateGcRootFieldLoad(load, |
| 5061 | out_loc, |
| 5062 | out.X(), |
| 5063 | /* offset */ 0, |
| 5064 | /* fixup_label */ nullptr, |
| 5065 | kCompilerReadBarrierOption); |
| 5066 | return; |
| 5067 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5068 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5069 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5070 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5071 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5072 | // 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] | 5073 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5074 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5075 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5076 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5077 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5080 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5081 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5082 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5083 | } |
| 5084 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5085 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5086 | // Will be generated at use site. |
| 5087 | } |
| 5088 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5089 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5090 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5091 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5092 | InvokeRuntimeCallingConvention calling_convention; |
| 5093 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5097 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5098 | instruction, |
| 5099 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5100 | if (instruction->IsEnter()) { |
| 5101 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5102 | } else { |
| 5103 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5104 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5105 | } |
| 5106 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5107 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5108 | LocationSummary* locations = |
| 5109 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5110 | switch (mul->GetResultType()) { |
| 5111 | case Primitive::kPrimInt: |
| 5112 | case Primitive::kPrimLong: |
| 5113 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5114 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5115 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5116 | break; |
| 5117 | |
| 5118 | case Primitive::kPrimFloat: |
| 5119 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5120 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5121 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5122 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5123 | break; |
| 5124 | |
| 5125 | default: |
| 5126 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5131 | switch (mul->GetResultType()) { |
| 5132 | case Primitive::kPrimInt: |
| 5133 | case Primitive::kPrimLong: |
| 5134 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5135 | break; |
| 5136 | |
| 5137 | case Primitive::kPrimFloat: |
| 5138 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5139 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5140 | break; |
| 5141 | |
| 5142 | default: |
| 5143 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5144 | } |
| 5145 | } |
| 5146 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5147 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5148 | LocationSummary* locations = |
| 5149 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5150 | switch (neg->GetResultType()) { |
| 5151 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5152 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5153 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5154 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5155 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5156 | |
| 5157 | case Primitive::kPrimFloat: |
| 5158 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5159 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5160 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5161 | break; |
| 5162 | |
| 5163 | default: |
| 5164 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5165 | } |
| 5166 | } |
| 5167 | |
| 5168 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5169 | switch (neg->GetResultType()) { |
| 5170 | case Primitive::kPrimInt: |
| 5171 | case Primitive::kPrimLong: |
| 5172 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5173 | break; |
| 5174 | |
| 5175 | case Primitive::kPrimFloat: |
| 5176 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5177 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5178 | break; |
| 5179 | |
| 5180 | default: |
| 5181 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5186 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5187 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5188 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5189 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5190 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5191 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5195 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5196 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5197 | QuickEntrypointEnum entrypoint = |
| 5198 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5199 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5200 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5201 | } |
| 5202 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5203 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5204 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5205 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5206 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5207 | if (instruction->IsStringAlloc()) { |
| 5208 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5209 | } else { |
| 5210 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5211 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5212 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5213 | } |
| 5214 | |
| 5215 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5216 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5217 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5218 | if (instruction->IsStringAlloc()) { |
| 5219 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5220 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5221 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5222 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5223 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5224 | |
| 5225 | { |
| 5226 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5227 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5228 | kInstructionSize, |
| 5229 | CodeBufferCheckScope::kExactSize); |
| 5230 | __ blr(lr); |
| 5231 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5232 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5233 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5234 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5235 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5236 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5240 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5241 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5242 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5246 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5247 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5248 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5249 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5250 | break; |
| 5251 | |
| 5252 | default: |
| 5253 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5254 | } |
| 5255 | } |
| 5256 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5257 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5258 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5259 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5260 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5261 | } |
| 5262 | |
| 5263 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5264 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5265 | } |
| 5266 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5267 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5268 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5269 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5270 | } |
| 5271 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5272 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5273 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5274 | return; |
| 5275 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5276 | { |
| 5277 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5278 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5279 | Location obj = instruction->GetLocations()->InAt(0); |
| 5280 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5281 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5282 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5283 | } |
| 5284 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5285 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5286 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5287 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5288 | |
| 5289 | LocationSummary* locations = instruction->GetLocations(); |
| 5290 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5291 | |
| 5292 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5293 | } |
| 5294 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5295 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5296 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5299 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5300 | HandleBinaryOp(instruction); |
| 5301 | } |
| 5302 | |
| 5303 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5304 | HandleBinaryOp(instruction); |
| 5305 | } |
| 5306 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5307 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5308 | LOG(FATAL) << "Unreachable"; |
| 5309 | } |
| 5310 | |
| 5311 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5312 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5313 | } |
| 5314 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5315 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5316 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5317 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5318 | if (location.IsStackSlot()) { |
| 5319 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5320 | } else if (location.IsDoubleStackSlot()) { |
| 5321 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5322 | } |
| 5323 | locations->SetOut(location); |
| 5324 | } |
| 5325 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5326 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5327 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5328 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5332 | LocationSummary* locations = |
| 5333 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5334 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5338 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5339 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5343 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5344 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5345 | locations->SetInAt(i, Location::Any()); |
| 5346 | } |
| 5347 | locations->SetOut(Location::Any()); |
| 5348 | } |
| 5349 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5350 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5351 | LOG(FATAL) << "Unreachable"; |
| 5352 | } |
| 5353 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5354 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5355 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5356 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5357 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5358 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5359 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5360 | |
| 5361 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5362 | case Primitive::kPrimInt: |
| 5363 | case Primitive::kPrimLong: |
| 5364 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5365 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5366 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5367 | break; |
| 5368 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5369 | case Primitive::kPrimFloat: |
| 5370 | case Primitive::kPrimDouble: { |
| 5371 | InvokeRuntimeCallingConvention calling_convention; |
| 5372 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5373 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5374 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5375 | |
| 5376 | break; |
| 5377 | } |
| 5378 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5379 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5380 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5381 | } |
| 5382 | } |
| 5383 | |
| 5384 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5385 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5386 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5387 | switch (type) { |
| 5388 | case Primitive::kPrimInt: |
| 5389 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5390 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5391 | break; |
| 5392 | } |
| 5393 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5394 | case Primitive::kPrimFloat: |
| 5395 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5396 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5397 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5398 | if (type == Primitive::kPrimFloat) { |
| 5399 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5400 | } else { |
| 5401 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5402 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5403 | break; |
| 5404 | } |
| 5405 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5406 | default: |
| 5407 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5408 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5409 | } |
| 5410 | } |
| 5411 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5412 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5413 | memory_barrier->SetLocations(nullptr); |
| 5414 | } |
| 5415 | |
| 5416 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5417 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5418 | } |
| 5419 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5420 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5421 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5422 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5423 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5424 | } |
| 5425 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5426 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5427 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5431 | instruction->SetLocations(nullptr); |
| 5432 | } |
| 5433 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5434 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5435 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5436 | } |
| 5437 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5438 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5439 | HandleBinaryOp(ror); |
| 5440 | } |
| 5441 | |
| 5442 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5443 | HandleBinaryOp(ror); |
| 5444 | } |
| 5445 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5446 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5447 | HandleShift(shl); |
| 5448 | } |
| 5449 | |
| 5450 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5451 | HandleShift(shl); |
| 5452 | } |
| 5453 | |
| 5454 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5455 | HandleShift(shr); |
| 5456 | } |
| 5457 | |
| 5458 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5459 | HandleShift(shr); |
| 5460 | } |
| 5461 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5462 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5463 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5467 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5470 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5471 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5475 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5479 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5480 | } |
| 5481 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5482 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5483 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5484 | } |
| 5485 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5486 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5487 | HUnresolvedInstanceFieldGet* instruction) { |
| 5488 | FieldAccessCallingConventionARM64 calling_convention; |
| 5489 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5490 | instruction, instruction->GetFieldType(), calling_convention); |
| 5491 | } |
| 5492 | |
| 5493 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5494 | HUnresolvedInstanceFieldGet* instruction) { |
| 5495 | FieldAccessCallingConventionARM64 calling_convention; |
| 5496 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5497 | instruction->GetFieldType(), |
| 5498 | instruction->GetFieldIndex(), |
| 5499 | instruction->GetDexPc(), |
| 5500 | calling_convention); |
| 5501 | } |
| 5502 | |
| 5503 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5504 | HUnresolvedInstanceFieldSet* instruction) { |
| 5505 | FieldAccessCallingConventionARM64 calling_convention; |
| 5506 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5507 | instruction, instruction->GetFieldType(), calling_convention); |
| 5508 | } |
| 5509 | |
| 5510 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5511 | HUnresolvedInstanceFieldSet* instruction) { |
| 5512 | FieldAccessCallingConventionARM64 calling_convention; |
| 5513 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5514 | instruction->GetFieldType(), |
| 5515 | instruction->GetFieldIndex(), |
| 5516 | instruction->GetDexPc(), |
| 5517 | calling_convention); |
| 5518 | } |
| 5519 | |
| 5520 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5521 | HUnresolvedStaticFieldGet* instruction) { |
| 5522 | FieldAccessCallingConventionARM64 calling_convention; |
| 5523 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5524 | instruction, instruction->GetFieldType(), calling_convention); |
| 5525 | } |
| 5526 | |
| 5527 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5528 | HUnresolvedStaticFieldGet* instruction) { |
| 5529 | FieldAccessCallingConventionARM64 calling_convention; |
| 5530 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5531 | instruction->GetFieldType(), |
| 5532 | instruction->GetFieldIndex(), |
| 5533 | instruction->GetDexPc(), |
| 5534 | calling_convention); |
| 5535 | } |
| 5536 | |
| 5537 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5538 | HUnresolvedStaticFieldSet* instruction) { |
| 5539 | FieldAccessCallingConventionARM64 calling_convention; |
| 5540 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5541 | instruction, instruction->GetFieldType(), calling_convention); |
| 5542 | } |
| 5543 | |
| 5544 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5545 | HUnresolvedStaticFieldSet* instruction) { |
| 5546 | FieldAccessCallingConventionARM64 calling_convention; |
| 5547 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5548 | instruction->GetFieldType(), |
| 5549 | instruction->GetFieldIndex(), |
| 5550 | instruction->GetDexPc(), |
| 5551 | calling_convention); |
| 5552 | } |
| 5553 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5554 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5555 | LocationSummary* locations = |
| 5556 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5557 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5558 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5559 | // registers in full width (since the runtime only saves/restores lower part). |
| 5560 | locations->SetCustomSlowPathCallerSaves( |
| 5561 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5565 | HBasicBlock* block = instruction->GetBlock(); |
| 5566 | if (block->GetLoopInformation() != nullptr) { |
| 5567 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5568 | // The back edge will generate the suspend check. |
| 5569 | return; |
| 5570 | } |
| 5571 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5572 | // The goto will generate the suspend check. |
| 5573 | return; |
| 5574 | } |
| 5575 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5576 | } |
| 5577 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5578 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5579 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5580 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5581 | InvokeRuntimeCallingConvention calling_convention; |
| 5582 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5583 | } |
| 5584 | |
| 5585 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5586 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5587 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5591 | LocationSummary* locations = |
| 5592 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5593 | Primitive::Type input_type = conversion->GetInputType(); |
| 5594 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5595 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5596 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5597 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5598 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5599 | } |
| 5600 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5601 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5602 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5603 | } else { |
| 5604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5605 | } |
| 5606 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5607 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5608 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5609 | } else { |
| 5610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5615 | Primitive::Type result_type = conversion->GetResultType(); |
| 5616 | Primitive::Type input_type = conversion->GetInputType(); |
| 5617 | |
| 5618 | DCHECK_NE(input_type, result_type); |
| 5619 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5620 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5621 | int result_size = Primitive::ComponentSize(result_type); |
| 5622 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5623 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5624 | Register output = OutputRegister(conversion); |
| 5625 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5626 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5627 | // 'int' values are used directly as W registers, discarding the top |
| 5628 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5629 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5630 | // top 32 bits of the target register. We theoretically could leave those |
| 5631 | // bits unchanged, but we would have to make sure that no code uses a |
| 5632 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5633 | // zero. |
| 5634 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5635 | } else if (result_type == Primitive::kPrimChar || |
| 5636 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5637 | __ Ubfx(output, |
| 5638 | output.IsX() ? source.X() : source.W(), |
| 5639 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5640 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5641 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5642 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5643 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5644 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5645 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5646 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5647 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5648 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5649 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5650 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5651 | } else { |
| 5652 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5653 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5654 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5655 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5656 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5657 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5658 | HandleShift(ushr); |
| 5659 | } |
| 5660 | |
| 5661 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5662 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5666 | HandleBinaryOp(instruction); |
| 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5670 | HandleBinaryOp(instruction); |
| 5671 | } |
| 5672 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5673 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5674 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5675 | LOG(FATAL) << "Unreachable"; |
| 5676 | } |
| 5677 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5678 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5679 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5680 | LOG(FATAL) << "Unreachable"; |
| 5681 | } |
| 5682 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5683 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5684 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5685 | LocationSummary* locations = |
| 5686 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5687 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5688 | } |
| 5689 | |
| 5690 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5691 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5692 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5693 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5694 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5695 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5696 | // 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] | 5697 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5698 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5699 | // make sure we don't emit it if the target may run out of range. |
| 5700 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5701 | // ranges and emit the tables only as required. |
| 5702 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5703 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5704 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5705 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5706 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5707 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5708 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5709 | Register temp = temps.AcquireW(); |
| 5710 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5711 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5712 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5713 | // Jump to successors[0] if value == lower_bound. |
| 5714 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5715 | int32_t last_index = 0; |
| 5716 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5717 | __ Subs(temp, temp, Operand(2)); |
| 5718 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5719 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5720 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5721 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5722 | } |
| 5723 | if (num_entries - last_index == 2) { |
| 5724 | // The last missing case_value. |
| 5725 | __ Cmp(temp, Operand(1)); |
| 5726 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | // And the default for any other value. |
| 5730 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5731 | __ B(codegen_->GetLabelOf(default_block)); |
| 5732 | } |
| 5733 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5734 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5735 | |
| 5736 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5737 | |
| 5738 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5739 | // registers, we are free to block one. |
| 5740 | Register temp_w = temps.AcquireW(); |
| 5741 | Register index; |
| 5742 | // Remove the bias. |
| 5743 | if (lower_bound != 0) { |
| 5744 | index = temp_w; |
| 5745 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5746 | } else { |
| 5747 | index = value_reg; |
| 5748 | } |
| 5749 | |
| 5750 | // Jump to default block if index is out of the range. |
| 5751 | __ Cmp(index, Operand(num_entries)); |
| 5752 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5753 | |
| 5754 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5755 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5756 | // register pressure. |
| 5757 | Register table_base = temps.AcquireX(); |
| 5758 | // Load jump offset from the table. |
| 5759 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5760 | Register jump_offset = temp_w; |
| 5761 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5762 | |
| 5763 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5764 | Register target_address = table_base; |
| 5765 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5766 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5767 | } |
| 5768 | } |
| 5769 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5770 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5771 | HInstruction* instruction, |
| 5772 | Location out, |
| 5773 | uint32_t offset, |
| 5774 | Location maybe_temp, |
| 5775 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5776 | Primitive::Type type = Primitive::kPrimNot; |
| 5777 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5778 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5779 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5780 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5781 | if (kUseBakerReadBarrier) { |
| 5782 | // Load with fast path based Baker's read barrier. |
| 5783 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5784 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5785 | out, |
| 5786 | out_reg, |
| 5787 | offset, |
| 5788 | temp_reg, |
| 5789 | /* needs_null_check */ false, |
| 5790 | /* use_load_acquire */ false); |
| 5791 | } else { |
| 5792 | // Load with slow path based read barrier. |
| 5793 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5794 | // in the following move operation, as we will need it for the |
| 5795 | // read barrier below. |
| 5796 | __ Mov(temp_reg, out_reg); |
| 5797 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5798 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5799 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5800 | } |
| 5801 | } else { |
| 5802 | // Plain load with no read barrier. |
| 5803 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5804 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5805 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5806 | } |
| 5807 | } |
| 5808 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5809 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5810 | HInstruction* instruction, |
| 5811 | Location out, |
| 5812 | Location obj, |
| 5813 | uint32_t offset, |
| 5814 | Location maybe_temp, |
| 5815 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5816 | Primitive::Type type = Primitive::kPrimNot; |
| 5817 | Register out_reg = RegisterFrom(out, type); |
| 5818 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5819 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5820 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5821 | if (kUseBakerReadBarrier) { |
| 5822 | // Load with fast path based Baker's read barrier. |
| 5823 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5824 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5825 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5826 | out, |
| 5827 | obj_reg, |
| 5828 | offset, |
| 5829 | temp_reg, |
| 5830 | /* needs_null_check */ false, |
| 5831 | /* use_load_acquire */ false); |
| 5832 | } else { |
| 5833 | // Load with slow path based read barrier. |
| 5834 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5835 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5836 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5837 | } |
| 5838 | } else { |
| 5839 | // Plain load with no read barrier. |
| 5840 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5841 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5842 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5843 | } |
| 5844 | } |
| 5845 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5846 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5847 | HInstruction* instruction, |
| 5848 | Location root, |
| 5849 | Register obj, |
| 5850 | uint32_t offset, |
| 5851 | vixl::aarch64::Label* fixup_label, |
| 5852 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5853 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5854 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5855 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5856 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5857 | if (kUseBakerReadBarrier) { |
| 5858 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5859 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5860 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5861 | // Note that we do not actually check the value of |
| 5862 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 5863 | // root or not. Instead, we load into `temp` the read barrier |
| 5864 | // mark entry point corresponding to register `root`. If `temp` |
| 5865 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 5866 | // versa. |
| 5867 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5868 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5869 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5870 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 5871 | // // Slow path. |
| 5872 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5873 | // } |
| 5874 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5875 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 5876 | Register temp = lr; |
| 5877 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64( |
| 5878 | instruction, root, /* entrypoint */ LocationFrom(temp)); |
| 5879 | codegen_->AddSlowPath(slow_path); |
| 5880 | |
| 5881 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5882 | const int32_t entry_point_offset = |
| 5883 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 5884 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5885 | // threads are suspended or running a checkpoint. |
| 5886 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
| 5887 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5888 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5889 | if (fixup_label == nullptr) { |
| 5890 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5891 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5892 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5893 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5894 | static_assert( |
| 5895 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5896 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5897 | "have different sizes."); |
| 5898 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5899 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5900 | "have different sizes."); |
| 5901 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5902 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 5903 | // checking GetIsGcMarking. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5904 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5905 | __ Bind(slow_path->GetExitLabel()); |
| 5906 | } else { |
| 5907 | // GC root loaded through a slow path for read barriers other |
| 5908 | // than Baker's. |
| 5909 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5910 | if (fixup_label == nullptr) { |
| 5911 | __ Add(root_reg.X(), obj.X(), offset); |
| 5912 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5913 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5914 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5915 | // /* mirror::Object* */ root = root->Read() |
| 5916 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5917 | } |
| 5918 | } else { |
| 5919 | // Plain GC root load with no read barrier. |
| 5920 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5921 | if (fixup_label == nullptr) { |
| 5922 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5923 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5924 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5925 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5926 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5927 | // do not have to unpoison `root_reg` here. |
| 5928 | } |
| 5929 | } |
| 5930 | |
| 5931 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5932 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5933 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5934 | uint32_t offset, |
| 5935 | Register temp, |
| 5936 | bool needs_null_check, |
| 5937 | bool use_load_acquire) { |
| 5938 | DCHECK(kEmitCompilerReadBarrier); |
| 5939 | DCHECK(kUseBakerReadBarrier); |
| 5940 | |
| 5941 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5942 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5943 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5944 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5945 | ref, |
| 5946 | obj, |
| 5947 | offset, |
| 5948 | no_index, |
| 5949 | no_scale_factor, |
| 5950 | temp, |
| 5951 | needs_null_check, |
| 5952 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5956 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5957 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5958 | uint32_t data_offset, |
| 5959 | Location index, |
| 5960 | Register temp, |
| 5961 | bool needs_null_check) { |
| 5962 | DCHECK(kEmitCompilerReadBarrier); |
| 5963 | DCHECK(kUseBakerReadBarrier); |
| 5964 | |
| 5965 | // Array cells are never volatile variables, therefore array loads |
| 5966 | // never use Load-Acquire instructions on ARM64. |
| 5967 | const bool use_load_acquire = false; |
| 5968 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5969 | static_assert( |
| 5970 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5971 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5972 | // /* HeapReference<Object> */ ref = |
| 5973 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5974 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5975 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5976 | ref, |
| 5977 | obj, |
| 5978 | data_offset, |
| 5979 | index, |
| 5980 | scale_factor, |
| 5981 | temp, |
| 5982 | needs_null_check, |
| 5983 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5984 | } |
| 5985 | |
| 5986 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5987 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5988 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5989 | uint32_t offset, |
| 5990 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5991 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5992 | Register temp, |
| 5993 | bool needs_null_check, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5994 | bool use_load_acquire, |
| 5995 | bool always_update_field) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5996 | DCHECK(kEmitCompilerReadBarrier); |
| 5997 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5998 | // If we are emitting an array load, we should not be using a |
| 5999 | // Load Acquire instruction. In other words: |
| 6000 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6001 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6002 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6003 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6004 | // whether we need to enter the slow path to mark the reference. |
| 6005 | // Then, in the slow path, check the gray bit in the lock word of |
| 6006 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 6007 | // not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6008 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6009 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6010 | // instead, we load into `temp2` the read barrier mark entry point |
| 6011 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6012 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6013 | // |
| 6014 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6015 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6016 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6017 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6018 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6019 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6020 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6021 | // if (is_gray) { |
| 6022 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6023 | // } |
| 6024 | // } else { |
| 6025 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6026 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6027 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6028 | // Slow path marking the object `ref` when the GC is marking. The |
| 6029 | // entrypoint will already be loaded in `temp2`. |
| 6030 | Register temp2 = lr; |
| 6031 | Location temp2_loc = LocationFrom(temp2); |
| 6032 | SlowPathCodeARM64* slow_path; |
| 6033 | if (always_update_field) { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6034 | // LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 6035 | // only supports address of the form `obj + field_offset`, where |
| 6036 | // `obj` is a register and `field_offset` is a register. Thus |
| 6037 | // `offset` and `scale_factor` above are expected to be null in |
| 6038 | // this code path. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6039 | DCHECK_EQ(offset, 0u); |
| 6040 | DCHECK_EQ(scale_factor, 0u); /* "times 1" */ |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6041 | Location field_offset = index; |
| 6042 | slow_path = |
| 6043 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6044 | instruction, |
| 6045 | ref, |
| 6046 | obj, |
| 6047 | offset, |
| 6048 | /* index */ field_offset, |
| 6049 | scale_factor, |
| 6050 | needs_null_check, |
| 6051 | use_load_acquire, |
| 6052 | temp, |
| 6053 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6054 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6055 | slow_path = new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6056 | instruction, |
| 6057 | ref, |
| 6058 | obj, |
| 6059 | offset, |
| 6060 | index, |
| 6061 | scale_factor, |
| 6062 | needs_null_check, |
| 6063 | use_load_acquire, |
| 6064 | temp, |
| 6065 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6066 | } |
| 6067 | AddSlowPath(slow_path); |
| 6068 | |
| 6069 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6070 | const int32_t entry_point_offset = |
| 6071 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6072 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6073 | // threads are suspended or running a checkpoint. |
| 6074 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6075 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6076 | // checking GetIsGcMarking. |
| 6077 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6078 | // Fast path: just load the reference. |
| 6079 | GenerateRawReferenceLoad( |
| 6080 | 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] | 6081 | __ Bind(slow_path->GetExitLabel()); |
| 6082 | } |
| 6083 | |
| 6084 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6085 | Location ref, |
| 6086 | Register obj, |
| 6087 | uint32_t offset, |
| 6088 | Location index, |
| 6089 | size_t scale_factor, |
| 6090 | bool needs_null_check, |
| 6091 | bool use_load_acquire) { |
| 6092 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6093 | Primitive::Type type = Primitive::kPrimNot; |
| 6094 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6095 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6096 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6097 | // that no pools are emitted between the load (macro) instruction |
| 6098 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6099 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6100 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6101 | // Load types involving an "index": ArrayGet, |
| 6102 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6103 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6104 | if (use_load_acquire) { |
| 6105 | // UnsafeGetObjectVolatile intrinsic case. |
| 6106 | // Register `index` is not an index in an object array, but an |
| 6107 | // offset to an object reference field within object `obj`. |
| 6108 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6109 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6110 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6111 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6112 | DCHECK_EQ(offset, 0u); |
| 6113 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6114 | DCHECK_EQ(needs_null_check, false); |
| 6115 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6116 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6117 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6118 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6119 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6120 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6121 | if (index.IsConstant()) { |
| 6122 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6123 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6124 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6125 | if (needs_null_check) { |
| 6126 | MaybeRecordImplicitNullCheck(instruction); |
| 6127 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6128 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6129 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6130 | Register temp = temps.AcquireW(); |
| 6131 | __ Add(temp, obj, offset); |
| 6132 | { |
| 6133 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6134 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6135 | if (needs_null_check) { |
| 6136 | MaybeRecordImplicitNullCheck(instruction); |
| 6137 | } |
| 6138 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6139 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6140 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6141 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6142 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6143 | MemOperand field = HeapOperand(obj, offset); |
| 6144 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6145 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6146 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6147 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6148 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6149 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6150 | if (needs_null_check) { |
| 6151 | MaybeRecordImplicitNullCheck(instruction); |
| 6152 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6157 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6161 | Location out, |
| 6162 | Location ref, |
| 6163 | Location obj, |
| 6164 | uint32_t offset, |
| 6165 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6166 | DCHECK(kEmitCompilerReadBarrier); |
| 6167 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6168 | // Insert a slow path based read barrier *after* the reference load. |
| 6169 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6170 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6171 | // reference will be carried out by the runtime within the slow |
| 6172 | // path. |
| 6173 | // |
| 6174 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6175 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6176 | // not used by the artReadBarrierSlow entry point. |
| 6177 | // |
| 6178 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6179 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6180 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6181 | AddSlowPath(slow_path); |
| 6182 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6183 | __ B(slow_path->GetEntryLabel()); |
| 6184 | __ Bind(slow_path->GetExitLabel()); |
| 6185 | } |
| 6186 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6187 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6188 | Location out, |
| 6189 | Location ref, |
| 6190 | Location obj, |
| 6191 | uint32_t offset, |
| 6192 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6193 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6194 | // Baker's read barriers shall be handled by the fast path |
| 6195 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6196 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6197 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6198 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6199 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6200 | } else if (kPoisonHeapReferences) { |
| 6201 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6202 | } |
| 6203 | } |
| 6204 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6205 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6206 | Location out, |
| 6207 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6208 | DCHECK(kEmitCompilerReadBarrier); |
| 6209 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6210 | // Insert a slow path based read barrier *after* the GC root load. |
| 6211 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6212 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6213 | // not need to do anything special for this here. |
| 6214 | SlowPathCodeARM64* slow_path = |
| 6215 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6216 | AddSlowPath(slow_path); |
| 6217 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6218 | __ B(slow_path->GetEntryLabel()); |
| 6219 | __ Bind(slow_path->GetExitLabel()); |
| 6220 | } |
| 6221 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6222 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6223 | LocationSummary* locations = |
| 6224 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6225 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6226 | locations->SetOut(Location::RequiresRegister()); |
| 6227 | } |
| 6228 | |
| 6229 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6230 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6231 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6232 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6233 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6234 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6235 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6236 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6237 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6238 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6239 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6240 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6241 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6242 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6243 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6244 | } |
| 6245 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6246 | static void PatchJitRootUse(uint8_t* code, |
| 6247 | const uint8_t* roots_data, |
| 6248 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6249 | uint64_t index_in_table) { |
| 6250 | uint32_t literal_offset = literal->GetOffset(); |
| 6251 | uintptr_t address = |
| 6252 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6253 | uint8_t* data = code + literal_offset; |
| 6254 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6255 | } |
| 6256 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6257 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6258 | for (const auto& entry : jit_string_patches_) { |
| 6259 | const auto& it = jit_string_roots_.find(entry.first); |
| 6260 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6261 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 6262 | } |
| 6263 | for (const auto& entry : jit_class_patches_) { |
| 6264 | const auto& it = jit_class_roots_.find(entry.first); |
| 6265 | DCHECK(it != jit_class_roots_.end()); |
| 6266 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6267 | } |
| 6268 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6269 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6270 | #undef __ |
| 6271 | #undef QUICK_ENTRY_POINT |
| 6272 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6273 | } // namespace arm64 |
| 6274 | } // namespace art |