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; |
| 71 | using helpers::RegisterFrom; |
| 72 | using helpers::StackOperandFrom; |
| 73 | using helpers::VIXLRegCodeFromART; |
| 74 | using helpers::WRegisterFrom; |
| 75 | using helpers::XRegisterFrom; |
| 76 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 77 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 78 | // 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] | 79 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 80 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 81 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 82 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 83 | inline Condition ARM64Condition(IfCondition cond) { |
| 84 | switch (cond) { |
| 85 | case kCondEQ: return eq; |
| 86 | case kCondNE: return ne; |
| 87 | case kCondLT: return lt; |
| 88 | case kCondLE: return le; |
| 89 | case kCondGT: return gt; |
| 90 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 91 | case kCondB: return lo; |
| 92 | case kCondBE: return ls; |
| 93 | case kCondA: return hi; |
| 94 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 95 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 96 | LOG(FATAL) << "Unreachable"; |
| 97 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 100 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 101 | // The ARM64 condition codes can express all the necessary branches, see the |
| 102 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 103 | // There is no dex instruction or HIR that would need the missing conditions |
| 104 | // "equal or unordered" or "not equal". |
| 105 | switch (cond) { |
| 106 | case kCondEQ: return eq; |
| 107 | case kCondNE: return ne /* unordered */; |
| 108 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 109 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 110 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 111 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 112 | default: |
| 113 | LOG(FATAL) << "UNREACHABLE"; |
| 114 | UNREACHABLE(); |
| 115 | } |
| 116 | } |
| 117 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 118 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 119 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 120 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 121 | // but we use the exact registers for clarity. |
| 122 | if (return_type == Primitive::kPrimFloat) { |
| 123 | return LocationFrom(s0); |
| 124 | } else if (return_type == Primitive::kPrimDouble) { |
| 125 | return LocationFrom(d0); |
| 126 | } else if (return_type == Primitive::kPrimLong) { |
| 127 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 128 | } else if (return_type == Primitive::kPrimVoid) { |
| 129 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 130 | } else { |
| 131 | return LocationFrom(w0); |
| 132 | } |
| 133 | } |
| 134 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 135 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 136 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 139 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 140 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 141 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 142 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 143 | // Calculate memory accessing operand for save/restore live registers. |
| 144 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 145 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 146 | int64_t spill_offset, |
| 147 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 148 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 149 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 150 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 151 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 152 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 153 | codegen->GetNumberOfFloatingPointRegisters())); |
| 154 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 155 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
| 156 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 157 | |
| 158 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 159 | UseScratchRegisterScope temps(masm); |
| 160 | |
| 161 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 162 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 163 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 164 | int64_t reg_size = kXRegSizeInBytes; |
| 165 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 166 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 167 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 168 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 169 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 170 | // to compute the base address(float point registers spill base address). |
| 171 | Register new_base = temps.AcquireSameSizeAs(base); |
| 172 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 173 | base = new_base; |
| 174 | spill_offset = -core_spill_size; |
| 175 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 176 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 177 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 178 | } |
| 179 | |
| 180 | if (is_save) { |
| 181 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 182 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 183 | } else { |
| 184 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 185 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 190 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 191 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 192 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 193 | // If the register holds an object, update the stack mask. |
| 194 | if (locations->RegisterContainsObject(i)) { |
| 195 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 196 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 197 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 198 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 199 | saved_core_stack_offsets_[i] = stack_offset; |
| 200 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 201 | } |
| 202 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 203 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 204 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 205 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 206 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 207 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 208 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 209 | } |
| 210 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 211 | SaveRestoreLiveRegistersHelper(codegen, |
| 212 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 213 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 214 | } |
| 215 | |
| 216 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 217 | SaveRestoreLiveRegistersHelper(codegen, |
| 218 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 219 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 220 | } |
| 221 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 222 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 223 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 224 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 225 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 226 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 227 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 228 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 229 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 230 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 231 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 232 | // Live registers will be restored in the catch block if caught. |
| 233 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 234 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 235 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 236 | // move resolver. |
| 237 | InvokeRuntimeCallingConvention calling_convention; |
| 238 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 239 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 240 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 241 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 242 | ? kQuickThrowStringBounds |
| 243 | : kQuickThrowArrayBounds; |
| 244 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 245 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 246 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 249 | bool IsFatal() const OVERRIDE { return true; } |
| 250 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 251 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 252 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 253 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 254 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 255 | }; |
| 256 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 257 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 258 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 259 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 260 | |
| 261 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 262 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 263 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 264 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 265 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 268 | bool IsFatal() const OVERRIDE { return true; } |
| 269 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 270 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 271 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 272 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 273 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 274 | }; |
| 275 | |
| 276 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 277 | public: |
| 278 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 279 | HInstruction* at, |
| 280 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 281 | bool do_clinit, |
| 282 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 283 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 284 | : SlowPathCodeARM64(at), |
| 285 | cls_(cls), |
| 286 | dex_pc_(dex_pc), |
| 287 | do_clinit_(do_clinit), |
| 288 | bss_entry_temp_(bss_entry_temp), |
| 289 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 291 | } |
| 292 | |
| 293 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 294 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 295 | Location out = locations->Out(); |
| 296 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 297 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 298 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 299 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the page address of |
| 300 | // the entry which is in a scratch register. Make sure it's not used for saving/restoring |
| 301 | // registers. Exclude the scratch register also for non-Baker read barrier for simplicity. |
| 302 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 303 | bool is_load_class_bss_entry = |
| 304 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 305 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 306 | if (is_load_class_bss_entry) { |
| 307 | // This temp is a scratch register. |
| 308 | DCHECK(bss_entry_temp_.IsValid()); |
| 309 | temps.Exclude(bss_entry_temp_); |
| 310 | } |
| 311 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 312 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 313 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 314 | |
| 315 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 316 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 317 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 318 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 319 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 320 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 321 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 322 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 323 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 324 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 325 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | |
| 327 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 328 | if (out.IsValid()) { |
| 329 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 330 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 331 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 332 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 333 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 334 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 335 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 336 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 337 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 338 | if (call_saves_everything_except_r0_ip0) { |
| 339 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 340 | } else { |
| 341 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 342 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 343 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 344 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 345 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 346 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 347 | { |
| 348 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 349 | __ Bind(strp_label); |
| 350 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 351 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | __ B(GetExitLabel()); |
| 355 | } |
| 356 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 357 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 358 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 359 | private: |
| 360 | // The class this slow path will load. |
| 361 | HLoadClass* const cls_; |
| 362 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 363 | // The dex PC of `at_`. |
| 364 | const uint32_t dex_pc_; |
| 365 | |
| 366 | // Whether to initialize the class. |
| 367 | const bool do_clinit_; |
| 368 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 369 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 370 | vixl::aarch64::Register bss_entry_temp_; |
| 371 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 372 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 373 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 374 | }; |
| 375 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 376 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 377 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 378 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 379 | : SlowPathCodeARM64(instruction), |
| 380 | temp_(temp), |
| 381 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 382 | |
| 383 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 384 | LocationSummary* locations = instruction_->GetLocations(); |
| 385 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 386 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 387 | |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 388 | // temp_ is a scratch register. Make sure it's not used for saving/restoring registers. |
| 389 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 390 | temps.Exclude(temp_); |
| 391 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 392 | __ Bind(GetEntryLabel()); |
| 393 | SaveLiveRegisters(codegen, locations); |
| 394 | |
| 395 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 396 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 397 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 398 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 399 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 400 | Primitive::Type type = instruction_->GetType(); |
| 401 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 402 | |
| 403 | RestoreLiveRegisters(codegen, locations); |
| 404 | |
| 405 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 406 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 407 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 408 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 409 | } else { |
| 410 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 411 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 412 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 413 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 414 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 415 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 416 | { |
| 417 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 418 | __ Bind(strp_label); |
| 419 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 420 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | __ B(GetExitLabel()); |
| 424 | } |
| 425 | |
| 426 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 427 | |
| 428 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 429 | const Register temp_; |
| 430 | vixl::aarch64::Label* adrp_label_; |
| 431 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 433 | }; |
| 434 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 435 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 436 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 437 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 438 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 439 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 440 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 441 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 442 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 443 | // Live registers will be restored in the catch block if caught. |
| 444 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 445 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 446 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 447 | instruction_, |
| 448 | instruction_->GetDexPc(), |
| 449 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 450 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 451 | } |
| 452 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 453 | bool IsFatal() const OVERRIDE { return true; } |
| 454 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 455 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 456 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 457 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 458 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 459 | }; |
| 460 | |
| 461 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 462 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 463 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 464 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 465 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 466 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 467 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 468 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 469 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 470 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 471 | if (successor_ == nullptr) { |
| 472 | __ B(GetReturnLabel()); |
| 473 | } else { |
| 474 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 475 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 478 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 479 | DCHECK(successor_ == nullptr); |
| 480 | return &return_label_; |
| 481 | } |
| 482 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 483 | HBasicBlock* GetSuccessor() const { |
| 484 | return successor_; |
| 485 | } |
| 486 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 487 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 488 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 489 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 490 | // If not null, the block to branch to after the suspend check. |
| 491 | HBasicBlock* const successor_; |
| 492 | |
| 493 | // 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] | 494 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 495 | |
| 496 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 497 | }; |
| 498 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 499 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 500 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 501 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 502 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 503 | |
| 504 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 505 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 506 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 507 | DCHECK(instruction_->IsCheckCast() |
| 508 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 509 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 510 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 511 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 512 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 513 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 514 | if (!is_fatal_) { |
| 515 | SaveLiveRegisters(codegen, locations); |
| 516 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 517 | |
| 518 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 519 | // move resolver. |
| 520 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 521 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 522 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 523 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 524 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 525 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 526 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 527 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 528 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 529 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 530 | Primitive::Type ret_type = instruction_->GetType(); |
| 531 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 532 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 533 | } else { |
| 534 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 535 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 536 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 539 | if (!is_fatal_) { |
| 540 | RestoreLiveRegisters(codegen, locations); |
| 541 | __ B(GetExitLabel()); |
| 542 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 545 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 546 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 547 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 548 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 549 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 550 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 551 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 552 | }; |
| 553 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 554 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 555 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 556 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 557 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 558 | |
| 559 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 560 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 561 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 562 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 563 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 566 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 567 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 568 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 569 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 570 | }; |
| 571 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 572 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 573 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 574 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 575 | |
| 576 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 577 | LocationSummary* locations = instruction_->GetLocations(); |
| 578 | __ Bind(GetEntryLabel()); |
| 579 | SaveLiveRegisters(codegen, locations); |
| 580 | |
| 581 | InvokeRuntimeCallingConvention calling_convention; |
| 582 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 583 | parallel_move.AddMove( |
| 584 | locations->InAt(0), |
| 585 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 586 | Primitive::kPrimNot, |
| 587 | nullptr); |
| 588 | parallel_move.AddMove( |
| 589 | locations->InAt(1), |
| 590 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 591 | Primitive::kPrimInt, |
| 592 | nullptr); |
| 593 | parallel_move.AddMove( |
| 594 | locations->InAt(2), |
| 595 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 596 | Primitive::kPrimNot, |
| 597 | nullptr); |
| 598 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 599 | |
| 600 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 601 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 602 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 603 | RestoreLiveRegisters(codegen, locations); |
| 604 | __ B(GetExitLabel()); |
| 605 | } |
| 606 | |
| 607 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 608 | |
| 609 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 610 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 611 | }; |
| 612 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 613 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 614 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 615 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 616 | |
| 617 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 618 | // 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] | 619 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 620 | num_entries * sizeof(int32_t), |
| 621 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 622 | |
| 623 | __ Bind(&table_start_); |
| 624 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 625 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 626 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 627 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 628 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 629 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 630 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 631 | Literal<int32_t> literal(jump_offset); |
| 632 | __ place(&literal); |
| 633 | } |
| 634 | } |
| 635 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 636 | // Slow path marking an object reference `ref` during a read |
| 637 | // barrier. The field `obj.field` in the object `obj` holding this |
| 638 | // reference does not get updated by this slow path after marking (see |
| 639 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 below for that). |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 640 | // |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 641 | // This means that after the execution of this slow path, `ref` will |
| 642 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 643 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 644 | // probably still be a from-space reference (unless it gets updated by |
| 645 | // another thread, or if another thread installed another object |
| 646 | // reference (different from `ref`) in `obj.field`). |
| 647 | // |
| 648 | // If `entrypoint` is a valid location it is assumed to already be |
| 649 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 650 | // is for the GcRoot read barrier. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 651 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 652 | public: |
| 653 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 654 | Location ref, |
| 655 | Location entrypoint = Location::NoLocation()) |
| 656 | : SlowPathCodeARM64(instruction), |
| 657 | ref_(ref), |
| 658 | entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 659 | DCHECK(kEmitCompilerReadBarrier); |
| 660 | } |
| 661 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 662 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 663 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 664 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 665 | LocationSummary* locations = instruction_->GetLocations(); |
| 666 | DCHECK(locations->CanCall()); |
| 667 | DCHECK(ref_.IsRegister()) << ref_; |
| 668 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 669 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 670 | instruction_->IsStaticFieldGet() || |
| 671 | instruction_->IsArrayGet() || |
| 672 | instruction_->IsArraySet() || |
| 673 | instruction_->IsLoadClass() || |
| 674 | instruction_->IsLoadString() || |
| 675 | instruction_->IsInstanceOf() || |
| 676 | instruction_->IsCheckCast() || |
| 677 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 678 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 679 | << "Unexpected instruction in read barrier marking slow path: " |
| 680 | << instruction_->DebugName(); |
| 681 | // The read barrier instrumentation of object ArrayGet |
| 682 | // instructions does not support the HIntermediateAddress |
| 683 | // instruction. |
| 684 | DCHECK(!(instruction_->IsArrayGet() && |
| 685 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 686 | |
| 687 | __ Bind(GetEntryLabel()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 688 | // No need to save live registers; it's taken care of by the |
| 689 | // entrypoint. Also, there is no need to update the stack mask, |
| 690 | // as this runtime call will not trigger a garbage collection. |
| 691 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 692 | DCHECK_NE(ref_.reg(), LR); |
| 693 | DCHECK_NE(ref_.reg(), WSP); |
| 694 | DCHECK_NE(ref_.reg(), WZR); |
| 695 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 696 | // as a temporary, it cannot be the entry point's input/output. |
| 697 | DCHECK_NE(ref_.reg(), IP0); |
| 698 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 699 | // "Compact" slow path, saving two moves. |
| 700 | // |
| 701 | // Instead of using the standard runtime calling convention (input |
| 702 | // and output in W0): |
| 703 | // |
| 704 | // W0 <- ref |
| 705 | // W0 <- ReadBarrierMark(W0) |
| 706 | // ref <- W0 |
| 707 | // |
| 708 | // we just use rX (the register containing `ref`) as input and output |
| 709 | // of a dedicated entrypoint: |
| 710 | // |
| 711 | // rX <- ReadBarrierMarkRegX(rX) |
| 712 | // |
| 713 | if (entrypoint_.IsValid()) { |
| 714 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 715 | __ Blr(XRegisterFrom(entrypoint_)); |
| 716 | } else { |
| 717 | // Entrypoint is not already loaded, load from the thread. |
| 718 | int32_t entry_point_offset = |
| 719 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 720 | // This runtime call does not require a stack map. |
| 721 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 722 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 723 | __ B(GetExitLabel()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 726 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 727 | // The location (register) of the marked object reference. |
| 728 | const Location ref_; |
| 729 | |
| 730 | // The location of the entrypoint if it is already loaded. |
| 731 | const Location entrypoint_; |
| 732 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 733 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 734 | }; |
| 735 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 736 | // Slow path marking an object reference `ref` during a read barrier, |
| 737 | // and if needed, atomically updating the field `obj.field` in the |
| 738 | // object `obj` holding this reference after marking (contrary to |
| 739 | // ReadBarrierMarkSlowPathARM64 above, which never tries to update |
| 740 | // `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 741 | // |
| 742 | // This means that after the execution of this slow path, both `ref` |
| 743 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 744 | // hold the same to-space reference (unless another thread installed |
| 745 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 746 | class ReadBarrierMarkAndUpdateFieldSlowPathARM64 : public SlowPathCodeARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 747 | public: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 748 | ReadBarrierMarkAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 749 | Location ref, |
| 750 | Register obj, |
| 751 | Location field_offset, |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 752 | Register temp) |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 753 | : SlowPathCodeARM64(instruction), |
| 754 | ref_(ref), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 755 | obj_(obj), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 756 | field_offset_(field_offset), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 757 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 758 | DCHECK(kEmitCompilerReadBarrier); |
| 759 | } |
| 760 | |
| 761 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 762 | return "ReadBarrierMarkAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 766 | LocationSummary* locations = instruction_->GetLocations(); |
| 767 | Register ref_reg = WRegisterFrom(ref_); |
| 768 | DCHECK(locations->CanCall()); |
| 769 | DCHECK(ref_.IsRegister()) << ref_; |
| 770 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 771 | // This slow path is only used by the UnsafeCASObject intrinsic. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 772 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 773 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 774 | << instruction_->DebugName(); |
| 775 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 776 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 777 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 778 | |
| 779 | __ Bind(GetEntryLabel()); |
| 780 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 781 | // Save the old reference. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 782 | // Note that we cannot use IP to save the old reference, as IP is |
| 783 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 784 | // need the old reference after the call to that entry point. |
| 785 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 786 | __ Mov(temp_.W(), ref_reg); |
| 787 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 788 | // No need to save live registers; it's taken care of by the |
| 789 | // entrypoint. Also, there is no need to update the stack mask, |
| 790 | // as this runtime call will not trigger a garbage collection. |
| 791 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 792 | DCHECK_NE(ref_.reg(), LR); |
| 793 | DCHECK_NE(ref_.reg(), WSP); |
| 794 | DCHECK_NE(ref_.reg(), WZR); |
| 795 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 796 | // as a temporary, it cannot be the entry point's input/output. |
| 797 | DCHECK_NE(ref_.reg(), IP0); |
| 798 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 799 | // "Compact" slow path, saving two moves. |
| 800 | // |
| 801 | // Instead of using the standard runtime calling convention (input |
| 802 | // and output in W0): |
| 803 | // |
| 804 | // W0 <- ref |
| 805 | // W0 <- ReadBarrierMark(W0) |
| 806 | // ref <- W0 |
| 807 | // |
| 808 | // we just use rX (the register containing `ref`) as input and output |
| 809 | // of a dedicated entrypoint: |
| 810 | // |
| 811 | // rX <- ReadBarrierMarkRegX(rX) |
| 812 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 813 | int32_t entry_point_offset = |
| 814 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 815 | // This runtime call does not require a stack map. |
| 816 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 817 | |
| 818 | // If the new reference is different from the old reference, |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 819 | // update the field in the holder (`*(obj_ + field_offset_)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 820 | // |
| 821 | // Note that this field could also hold a different object, if |
| 822 | // another thread had concurrently changed it. In that case, the |
| 823 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 824 | // (CAS) operation below would abort the CAS, leaving the field |
| 825 | // as-is. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 826 | vixl::aarch64::Label done; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 827 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 828 | __ B(eq, &done); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 829 | |
| 830 | // Update the the holder's field atomically. This may fail if |
| 831 | // mutator updates before us, but it's OK. This is achieved |
| 832 | // using a strong compare-and-set (CAS) operation with relaxed |
| 833 | // memory synchronization ordering, where the expected value is |
| 834 | // the old reference and the desired value is the new reference. |
| 835 | |
| 836 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 837 | UseScratchRegisterScope temps(masm); |
| 838 | |
| 839 | // Convenience aliases. |
| 840 | Register base = obj_.W(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 841 | Register offset = XRegisterFrom(field_offset_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 842 | Register expected = temp_.W(); |
| 843 | Register value = ref_reg; |
| 844 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 845 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 846 | |
| 847 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 848 | |
| 849 | if (kPoisonHeapReferences) { |
| 850 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 851 | if (value.Is(expected)) { |
| 852 | // Do not poison `value`, as it is the same register as |
| 853 | // `expected`, which has just been poisoned. |
| 854 | } else { |
| 855 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | // do { |
| 860 | // tmp_value = [tmp_ptr] - expected; |
| 861 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 862 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 863 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 864 | __ Bind(&loop_head); |
| 865 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 866 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 867 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 868 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 869 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 870 | __ B(&exit_loop); |
| 871 | __ Bind(&comparison_failed); |
| 872 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 873 | __ Bind(&exit_loop); |
| 874 | |
| 875 | if (kPoisonHeapReferences) { |
| 876 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 877 | if (value.Is(expected)) { |
| 878 | // Do not unpoison `value`, as it is the same register as |
| 879 | // `expected`, which has just been unpoisoned. |
| 880 | } else { |
| 881 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 882 | } |
| 883 | } |
| 884 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 885 | __ Bind(&done); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 886 | __ B(GetExitLabel()); |
| 887 | } |
| 888 | |
| 889 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 890 | // The location (register) of the marked object reference. |
| 891 | const Location ref_; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 892 | // The register containing the object holding the marked object reference field. |
| 893 | const Register obj_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 894 | // The location of the offset of the marked reference field within `obj_`. |
| 895 | Location field_offset_; |
| 896 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 897 | const Register temp_; |
| 898 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 899 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 900 | }; |
| 901 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 902 | // Slow path generating a read barrier for a heap reference. |
| 903 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 904 | public: |
| 905 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 906 | Location out, |
| 907 | Location ref, |
| 908 | Location obj, |
| 909 | uint32_t offset, |
| 910 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 911 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 912 | out_(out), |
| 913 | ref_(ref), |
| 914 | obj_(obj), |
| 915 | offset_(offset), |
| 916 | index_(index) { |
| 917 | DCHECK(kEmitCompilerReadBarrier); |
| 918 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 919 | // has been overwritten by (or after) the heap object reference load |
| 920 | // to be instrumented, e.g.: |
| 921 | // |
| 922 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 923 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 924 | // |
| 925 | // In that case, we have lost the information about the original |
| 926 | // object, and the emitted read barrier cannot work properly. |
| 927 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 928 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 929 | } |
| 930 | |
| 931 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 932 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 933 | LocationSummary* locations = instruction_->GetLocations(); |
| 934 | Primitive::Type type = Primitive::kPrimNot; |
| 935 | DCHECK(locations->CanCall()); |
| 936 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 937 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 938 | instruction_->IsStaticFieldGet() || |
| 939 | instruction_->IsArrayGet() || |
| 940 | instruction_->IsInstanceOf() || |
| 941 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 942 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 943 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 944 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 945 | // The read barrier instrumentation of object ArrayGet |
| 946 | // instructions does not support the HIntermediateAddress |
| 947 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 948 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 949 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 950 | |
| 951 | __ Bind(GetEntryLabel()); |
| 952 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 953 | SaveLiveRegisters(codegen, locations); |
| 954 | |
| 955 | // We may have to change the index's value, but as `index_` is a |
| 956 | // constant member (like other "inputs" of this slow path), |
| 957 | // introduce a copy of it, `index`. |
| 958 | Location index = index_; |
| 959 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 960 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 961 | if (instruction_->IsArrayGet()) { |
| 962 | // Compute the actual memory offset and store it in `index`. |
| 963 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 964 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 965 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 966 | // We are about to change the value of `index_reg` (see the |
| 967 | // calls to vixl::MacroAssembler::Lsl and |
| 968 | // vixl::MacroAssembler::Mov below), but it has |
| 969 | // not been saved by the previous call to |
| 970 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 971 | // callee-save register -- |
| 972 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 973 | // callee-save registers, as it has been designed with the |
| 974 | // assumption that callee-save registers are supposed to be |
| 975 | // handled by the called function. So, as a callee-save |
| 976 | // register, `index_reg` _would_ eventually be saved onto |
| 977 | // the stack, but it would be too late: we would have |
| 978 | // changed its value earlier. Therefore, we manually save |
| 979 | // it here into another freely available register, |
| 980 | // `free_reg`, chosen of course among the caller-save |
| 981 | // registers (as a callee-save `free_reg` register would |
| 982 | // exhibit the same problem). |
| 983 | // |
| 984 | // Note we could have requested a temporary register from |
| 985 | // the register allocator instead; but we prefer not to, as |
| 986 | // this is a slow path, and we know we can find a |
| 987 | // caller-save register that is available. |
| 988 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 989 | __ Mov(free_reg.W(), index_reg); |
| 990 | index_reg = free_reg; |
| 991 | index = LocationFrom(index_reg); |
| 992 | } else { |
| 993 | // The initial register stored in `index_` has already been |
| 994 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 995 | // (as it is not a callee-save register), so we can freely |
| 996 | // use it. |
| 997 | } |
| 998 | // Shifting the index value contained in `index_reg` by the scale |
| 999 | // factor (2) cannot overflow in practice, as the runtime is |
| 1000 | // unable to allocate object arrays with a size larger than |
| 1001 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1002 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1003 | static_assert( |
| 1004 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1005 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1006 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1007 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1008 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1009 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1010 | // (as in the case of ArrayGet), as it is actually an offset |
| 1011 | // to an object field within an object. |
| 1012 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1013 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1014 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1015 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1016 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1017 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1018 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | // We're moving two or three locations to locations that could |
| 1023 | // overlap, so we need a parallel move resolver. |
| 1024 | InvokeRuntimeCallingConvention calling_convention; |
| 1025 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1026 | parallel_move.AddMove(ref_, |
| 1027 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1028 | type, |
| 1029 | nullptr); |
| 1030 | parallel_move.AddMove(obj_, |
| 1031 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1032 | type, |
| 1033 | nullptr); |
| 1034 | if (index.IsValid()) { |
| 1035 | parallel_move.AddMove(index, |
| 1036 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1037 | Primitive::kPrimInt, |
| 1038 | nullptr); |
| 1039 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1040 | } else { |
| 1041 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1042 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1043 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1044 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1045 | instruction_, |
| 1046 | instruction_->GetDexPc(), |
| 1047 | this); |
| 1048 | CheckEntrypointTypes< |
| 1049 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1050 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1051 | |
| 1052 | RestoreLiveRegisters(codegen, locations); |
| 1053 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1054 | __ B(GetExitLabel()); |
| 1055 | } |
| 1056 | |
| 1057 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1058 | |
| 1059 | private: |
| 1060 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1061 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1062 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1063 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1064 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1065 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1066 | } |
| 1067 | } |
| 1068 | // We shall never fail to find a free caller-save register, as |
| 1069 | // there are more than two core caller-save registers on ARM64 |
| 1070 | // (meaning it is possible to find one which is different from |
| 1071 | // `ref` and `obj`). |
| 1072 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1073 | LOG(FATAL) << "Could not find a free register"; |
| 1074 | UNREACHABLE(); |
| 1075 | } |
| 1076 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1077 | const Location out_; |
| 1078 | const Location ref_; |
| 1079 | const Location obj_; |
| 1080 | const uint32_t offset_; |
| 1081 | // An additional location containing an index to an array. |
| 1082 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1083 | // UnsafeGetObjectVolatile intrinsics. |
| 1084 | const Location index_; |
| 1085 | |
| 1086 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1087 | }; |
| 1088 | |
| 1089 | // Slow path generating a read barrier for a GC root. |
| 1090 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1091 | public: |
| 1092 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1093 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1094 | DCHECK(kEmitCompilerReadBarrier); |
| 1095 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1096 | |
| 1097 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1098 | LocationSummary* locations = instruction_->GetLocations(); |
| 1099 | Primitive::Type type = Primitive::kPrimNot; |
| 1100 | DCHECK(locations->CanCall()); |
| 1101 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1102 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1103 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1104 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1105 | |
| 1106 | __ Bind(GetEntryLabel()); |
| 1107 | SaveLiveRegisters(codegen, locations); |
| 1108 | |
| 1109 | InvokeRuntimeCallingConvention calling_convention; |
| 1110 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1111 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1112 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1113 | // thus we need a 64-bit move here, and we cannot use |
| 1114 | // |
| 1115 | // arm64_codegen->MoveLocation( |
| 1116 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1117 | // root_, |
| 1118 | // type); |
| 1119 | // |
| 1120 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1121 | // reference type (`Primitive::kPrimNot`). |
| 1122 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1123 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1124 | instruction_, |
| 1125 | instruction_->GetDexPc(), |
| 1126 | this); |
| 1127 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1128 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1129 | |
| 1130 | RestoreLiveRegisters(codegen, locations); |
| 1131 | __ B(GetExitLabel()); |
| 1132 | } |
| 1133 | |
| 1134 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1135 | |
| 1136 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1137 | const Location out_; |
| 1138 | const Location root_; |
| 1139 | |
| 1140 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1141 | }; |
| 1142 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1143 | #undef __ |
| 1144 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1145 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1146 | Location next_location; |
| 1147 | if (type == Primitive::kPrimVoid) { |
| 1148 | LOG(FATAL) << "Unreachable type " << type; |
| 1149 | } |
| 1150 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1151 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1152 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 1153 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1154 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1155 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1156 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1157 | } else { |
| 1158 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1159 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1160 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1161 | } |
| 1162 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1163 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1164 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1165 | return next_location; |
| 1166 | } |
| 1167 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1168 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1169 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1172 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1173 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1174 | const CompilerOptions& compiler_options, |
| 1175 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1176 | : CodeGenerator(graph, |
| 1177 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1178 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1179 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1180 | callee_saved_core_registers.GetList(), |
| 1181 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1182 | compiler_options, |
| 1183 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1184 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1185 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1186 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1187 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1188 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1189 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1190 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1191 | uint32_literals_(std::less<uint32_t>(), |
| 1192 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1193 | uint64_literals_(std::less<uint64_t>(), |
| 1194 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1195 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1196 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1197 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1198 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1199 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1200 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1201 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1202 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1203 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1204 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1205 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1206 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1207 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1208 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1209 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1210 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1211 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1212 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1213 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1214 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1215 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1216 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1217 | jump_table->EmitTable(this); |
| 1218 | } |
| 1219 | } |
| 1220 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1221 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1222 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1223 | // Ensure we emit the literal pool. |
| 1224 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1225 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1226 | CodeGenerator::Finalize(allocator); |
| 1227 | } |
| 1228 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1229 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1230 | // Note: There are 6 kinds of moves: |
| 1231 | // 1. constant -> GPR/FPR (non-cycle) |
| 1232 | // 2. constant -> stack (non-cycle) |
| 1233 | // 3. GPR/FPR -> GPR/FPR |
| 1234 | // 4. GPR/FPR -> stack |
| 1235 | // 5. stack -> GPR/FPR |
| 1236 | // 6. stack -> stack (non-cycle) |
| 1237 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1238 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1239 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1240 | // dependency. |
| 1241 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1242 | } |
| 1243 | |
| 1244 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1245 | vixl_temps_.Close(); |
| 1246 | } |
| 1247 | |
| 1248 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 1249 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 1250 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 1251 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 1252 | Location scratch = GetScratchLocation(kind); |
| 1253 | if (!scratch.Equals(Location::NoLocation())) { |
| 1254 | return scratch; |
| 1255 | } |
| 1256 | // Allocate from VIXL temp registers. |
| 1257 | if (kind == Location::kRegister) { |
| 1258 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1259 | } else { |
| 1260 | DCHECK(kind == Location::kFpuRegister); |
| 1261 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1262 | } |
| 1263 | AddScratchLocation(scratch); |
| 1264 | return scratch; |
| 1265 | } |
| 1266 | |
| 1267 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1268 | if (loc.IsRegister()) { |
| 1269 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1270 | } else { |
| 1271 | DCHECK(loc.IsFpuRegister()); |
| 1272 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1273 | } |
| 1274 | RemoveScratchLocation(loc); |
| 1275 | } |
| 1276 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1277 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1278 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1279 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1282 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1283 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1284 | __ Bind(&frame_entry_label_); |
| 1285 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1286 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1287 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1288 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1289 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1290 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1291 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1292 | { |
| 1293 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1294 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1295 | kInstructionSize, |
| 1296 | CodeBufferCheckScope::kExactSize); |
| 1297 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1298 | RecordPcInfo(nullptr, 0); |
| 1299 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1300 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1301 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1302 | if (!HasEmptyFrame()) { |
| 1303 | int frame_size = GetFrameSize(); |
| 1304 | // Stack layout: |
| 1305 | // sp[frame_size - 8] : lr. |
| 1306 | // ... : other preserved core registers. |
| 1307 | // ... : other preserved fp registers. |
| 1308 | // ... : reserved frame space. |
| 1309 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1310 | |
| 1311 | // Save the current method if we need it. Note that we do not |
| 1312 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1313 | // in the SSA graph. |
| 1314 | if (RequiresCurrentMethod()) { |
| 1315 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1316 | } else { |
| 1317 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1318 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1319 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1320 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1321 | frame_size - GetCoreSpillSize()); |
| 1322 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1323 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1324 | |
| 1325 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1326 | // Initialize should_deoptimize flag to 0. |
| 1327 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1328 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1329 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1330 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1334 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1335 | if (!HasEmptyFrame()) { |
| 1336 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1337 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1338 | frame_size - FrameEntrySpillSize()); |
| 1339 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1340 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1341 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1342 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1343 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1344 | __ Ret(); |
| 1345 | GetAssembler()->cfi().RestoreState(); |
| 1346 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1349 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1350 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1351 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1352 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1353 | } |
| 1354 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1355 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1356 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1357 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1358 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1359 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1360 | } |
| 1361 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1362 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1363 | __ Bind(GetLabelOf(block)); |
| 1364 | } |
| 1365 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1366 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1367 | DCHECK(location.IsRegister()); |
| 1368 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1369 | } |
| 1370 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1371 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1372 | if (location.IsRegister()) { |
| 1373 | locations->AddTemp(location); |
| 1374 | } else { |
| 1375 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1376 | } |
| 1377 | } |
| 1378 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1379 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1380 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1381 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1382 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1383 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1384 | if (value_can_be_null) { |
| 1385 | __ Cbz(value, &done); |
| 1386 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1387 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1388 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1389 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1390 | if (value_can_be_null) { |
| 1391 | __ Bind(&done); |
| 1392 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1395 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1396 | // Blocked core registers: |
| 1397 | // lr : Runtime reserved. |
| 1398 | // tr : Runtime reserved. |
| 1399 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1400 | // ip1 : VIXL core temp. |
| 1401 | // ip0 : VIXL core temp. |
| 1402 | // |
| 1403 | // Blocked fp registers: |
| 1404 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1405 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1406 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1407 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1408 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1409 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1410 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1411 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1412 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1413 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1414 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1415 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1416 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1417 | // Stubs do not save callee-save floating point registers. If the graph |
| 1418 | // is debuggable, we need to deal with these registers differently. For |
| 1419 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1420 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1421 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1422 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1423 | } |
| 1424 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1427 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1428 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1429 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1430 | return kArm64WordSize; |
| 1431 | } |
| 1432 | |
| 1433 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1434 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1435 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1436 | return kArm64WordSize; |
| 1437 | } |
| 1438 | |
| 1439 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1440 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1441 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1442 | return kArm64WordSize; |
| 1443 | } |
| 1444 | |
| 1445 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1446 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1447 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1448 | return kArm64WordSize; |
| 1449 | } |
| 1450 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1451 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1452 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1456 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1457 | } |
| 1458 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1459 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1460 | if (constant->IsIntConstant()) { |
| 1461 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1462 | } else if (constant->IsLongConstant()) { |
| 1463 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1464 | } else if (constant->IsNullConstant()) { |
| 1465 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1466 | } else if (constant->IsFloatConstant()) { |
| 1467 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1468 | } else { |
| 1469 | DCHECK(constant->IsDoubleConstant()); |
| 1470 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1471 | } |
| 1472 | } |
| 1473 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1474 | |
| 1475 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1476 | DCHECK(constant.IsConstant()); |
| 1477 | HConstant* cst = constant.GetConstant(); |
| 1478 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1479 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1480 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1481 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1482 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1483 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1484 | } |
| 1485 | |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1486 | // Allocate a scratch register from the VIXL pool, querying first into |
| 1487 | // the floating-point register pool, and then the the core register |
| 1488 | // pool. This is essentially a reimplementation of |
| 1489 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1490 | // using a different allocation strategy. |
| 1491 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1492 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1493 | int size_in_bits) { |
| 1494 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1495 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1496 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1497 | } |
| 1498 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1499 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1500 | Location source, |
| 1501 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1502 | if (source.Equals(destination)) { |
| 1503 | return; |
| 1504 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1505 | |
| 1506 | // A valid move can always be inferred from the destination and source |
| 1507 | // locations. When moving from and to a register, the argument type can be |
| 1508 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1509 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1510 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1511 | |
| 1512 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1513 | if (unspecified_type) { |
| 1514 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1515 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1516 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1517 | || src_cst->IsFloatConstant() |
| 1518 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1519 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1520 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1521 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1522 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1523 | // type is appropriate. Else the source is a register, and since the |
| 1524 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1525 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1526 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1527 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1528 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1529 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1530 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1531 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1532 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1533 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1534 | __ Ldr(dst, StackOperandFrom(source)); |
| 1535 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1536 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1537 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1538 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1539 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1540 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1541 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1542 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1543 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1544 | ? Primitive::kPrimLong |
| 1545 | : Primitive::kPrimInt; |
| 1546 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1547 | } |
| 1548 | } else { |
| 1549 | DCHECK(source.IsFpuRegister()); |
| 1550 | if (destination.IsRegister()) { |
| 1551 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1552 | ? Primitive::kPrimDouble |
| 1553 | : Primitive::kPrimFloat; |
| 1554 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1555 | } else { |
| 1556 | DCHECK(destination.IsFpuRegister()); |
| 1557 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1558 | } |
| 1559 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1560 | } else { // The destination is not a register. It must be a stack slot. |
| 1561 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1562 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1563 | if (unspecified_type) { |
| 1564 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1565 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1566 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1567 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1568 | } |
| 1569 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1570 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1571 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1572 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1573 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1574 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1575 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1576 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1577 | HConstant* src_cst = source.GetConstant(); |
| 1578 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1579 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1580 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1581 | ? Register(xzr) |
| 1582 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1583 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1584 | if (src_cst->IsIntConstant()) { |
| 1585 | temp = temps.AcquireW(); |
| 1586 | } else if (src_cst->IsLongConstant()) { |
| 1587 | temp = temps.AcquireX(); |
| 1588 | } else if (src_cst->IsFloatConstant()) { |
| 1589 | temp = temps.AcquireS(); |
| 1590 | } else { |
| 1591 | DCHECK(src_cst->IsDoubleConstant()); |
| 1592 | temp = temps.AcquireD(); |
| 1593 | } |
| 1594 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1595 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1596 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1597 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1598 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1599 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1600 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1601 | // Use any scratch register (a core or a floating-point one) |
| 1602 | // from VIXL scratch register pools as a temporary. |
| 1603 | // |
| 1604 | // We used to only use the FP scratch register pool, but in some |
| 1605 | // rare cases the only register from this pool (D31) would |
| 1606 | // already be used (e.g. within a ParallelMove instruction, when |
| 1607 | // a move is blocked by a another move requiring a scratch FP |
| 1608 | // register, which would reserve D31). To prevent this issue, we |
| 1609 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1610 | // |
| 1611 | // Also, we start by asking for a FP scratch register first, as the |
| 1612 | // demand of scratch core registers is higher. This is why we |
| 1613 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1614 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1615 | // allocates core scratch registers first. |
| 1616 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1617 | GetVIXLAssembler(), |
| 1618 | &temps, |
| 1619 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1620 | __ Ldr(temp, StackOperandFrom(source)); |
| 1621 | __ Str(temp, StackOperandFrom(destination)); |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1627 | CPURegister dst, |
| 1628 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1629 | switch (type) { |
| 1630 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1631 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1632 | break; |
| 1633 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1634 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1635 | break; |
| 1636 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1637 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1638 | break; |
| 1639 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1640 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1641 | break; |
| 1642 | case Primitive::kPrimInt: |
| 1643 | case Primitive::kPrimNot: |
| 1644 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1645 | case Primitive::kPrimFloat: |
| 1646 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1647 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1648 | __ Ldr(dst, src); |
| 1649 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1650 | case Primitive::kPrimVoid: |
| 1651 | LOG(FATAL) << "Unreachable type " << type; |
| 1652 | } |
| 1653 | } |
| 1654 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1655 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1656 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1657 | const MemOperand& src, |
| 1658 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1659 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1660 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1661 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1662 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1663 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1664 | DCHECK(!src.IsPreIndex()); |
| 1665 | DCHECK(!src.IsPostIndex()); |
| 1666 | |
| 1667 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1668 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1669 | { |
| 1670 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1671 | MemOperand base = MemOperand(temp_base); |
| 1672 | switch (type) { |
| 1673 | case Primitive::kPrimBoolean: |
| 1674 | { |
| 1675 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1676 | __ ldarb(Register(dst), base); |
| 1677 | if (needs_null_check) { |
| 1678 | MaybeRecordImplicitNullCheck(instruction); |
| 1679 | } |
| 1680 | } |
| 1681 | break; |
| 1682 | case Primitive::kPrimByte: |
| 1683 | { |
| 1684 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1685 | __ ldarb(Register(dst), base); |
| 1686 | if (needs_null_check) { |
| 1687 | MaybeRecordImplicitNullCheck(instruction); |
| 1688 | } |
| 1689 | } |
| 1690 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1691 | break; |
| 1692 | case Primitive::kPrimChar: |
| 1693 | { |
| 1694 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1695 | __ ldarh(Register(dst), base); |
| 1696 | if (needs_null_check) { |
| 1697 | MaybeRecordImplicitNullCheck(instruction); |
| 1698 | } |
| 1699 | } |
| 1700 | break; |
| 1701 | case Primitive::kPrimShort: |
| 1702 | { |
| 1703 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1704 | __ ldarh(Register(dst), base); |
| 1705 | if (needs_null_check) { |
| 1706 | MaybeRecordImplicitNullCheck(instruction); |
| 1707 | } |
| 1708 | } |
| 1709 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1710 | break; |
| 1711 | case Primitive::kPrimInt: |
| 1712 | case Primitive::kPrimNot: |
| 1713 | case Primitive::kPrimLong: |
| 1714 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 1715 | { |
| 1716 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1717 | __ ldar(Register(dst), base); |
| 1718 | if (needs_null_check) { |
| 1719 | MaybeRecordImplicitNullCheck(instruction); |
| 1720 | } |
| 1721 | } |
| 1722 | break; |
| 1723 | case Primitive::kPrimFloat: |
| 1724 | case Primitive::kPrimDouble: { |
| 1725 | DCHECK(dst.IsFPRegister()); |
| 1726 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1727 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1728 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1729 | { |
| 1730 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1731 | __ ldar(temp, base); |
| 1732 | if (needs_null_check) { |
| 1733 | MaybeRecordImplicitNullCheck(instruction); |
| 1734 | } |
| 1735 | } |
| 1736 | __ Fmov(FPRegister(dst), temp); |
| 1737 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1738 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1739 | case Primitive::kPrimVoid: |
| 1740 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1741 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1745 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1746 | CPURegister src, |
| 1747 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1748 | switch (type) { |
| 1749 | case Primitive::kPrimBoolean: |
| 1750 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1751 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1752 | break; |
| 1753 | case Primitive::kPrimChar: |
| 1754 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1755 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1756 | break; |
| 1757 | case Primitive::kPrimInt: |
| 1758 | case Primitive::kPrimNot: |
| 1759 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1760 | case Primitive::kPrimFloat: |
| 1761 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1762 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1763 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1764 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1765 | case Primitive::kPrimVoid: |
| 1766 | LOG(FATAL) << "Unreachable type " << type; |
| 1767 | } |
| 1768 | } |
| 1769 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1770 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 1771 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1772 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1773 | const MemOperand& dst, |
| 1774 | bool needs_null_check) { |
| 1775 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1776 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1777 | Register temp_base = temps.AcquireX(); |
| 1778 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1779 | DCHECK(!dst.IsPreIndex()); |
| 1780 | DCHECK(!dst.IsPostIndex()); |
| 1781 | |
| 1782 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1783 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1784 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1785 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1786 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1787 | switch (type) { |
| 1788 | case Primitive::kPrimBoolean: |
| 1789 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1790 | { |
| 1791 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1792 | __ stlrb(Register(src), base); |
| 1793 | if (needs_null_check) { |
| 1794 | MaybeRecordImplicitNullCheck(instruction); |
| 1795 | } |
| 1796 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1797 | break; |
| 1798 | case Primitive::kPrimChar: |
| 1799 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1800 | { |
| 1801 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1802 | __ stlrh(Register(src), base); |
| 1803 | if (needs_null_check) { |
| 1804 | MaybeRecordImplicitNullCheck(instruction); |
| 1805 | } |
| 1806 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | case Primitive::kPrimInt: |
| 1809 | case Primitive::kPrimNot: |
| 1810 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1811 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1812 | { |
| 1813 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1814 | __ stlr(Register(src), base); |
| 1815 | if (needs_null_check) { |
| 1816 | MaybeRecordImplicitNullCheck(instruction); |
| 1817 | } |
| 1818 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | case Primitive::kPrimFloat: |
| 1821 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1822 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1823 | Register temp_src; |
| 1824 | if (src.IsZero()) { |
| 1825 | // The zero register is used to avoid synthesizing zero constants. |
| 1826 | temp_src = Register(src); |
| 1827 | } else { |
| 1828 | DCHECK(src.IsFPRegister()); |
| 1829 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1830 | __ Fmov(temp_src, FPRegister(src)); |
| 1831 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1832 | { |
| 1833 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1834 | __ stlr(temp_src, base); |
| 1835 | if (needs_null_check) { |
| 1836 | MaybeRecordImplicitNullCheck(instruction); |
| 1837 | } |
| 1838 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1839 | break; |
| 1840 | } |
| 1841 | case Primitive::kPrimVoid: |
| 1842 | LOG(FATAL) << "Unreachable type " << type; |
| 1843 | } |
| 1844 | } |
| 1845 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1846 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1847 | HInstruction* instruction, |
| 1848 | uint32_t dex_pc, |
| 1849 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1850 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1851 | |
| 1852 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 1853 | { |
| 1854 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1855 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1856 | __ blr(lr); |
| 1857 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1858 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1859 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1860 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1863 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1864 | HInstruction* instruction, |
| 1865 | SlowPathCode* slow_path) { |
| 1866 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1867 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1868 | __ Blr(lr); |
| 1869 | } |
| 1870 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1871 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1872 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1873 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1874 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1875 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1876 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1877 | // 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] | 1878 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1879 | __ Add(temp, class_reg, status_offset); |
| 1880 | __ Ldar(temp, HeapOperand(temp)); |
| 1881 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1882 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1883 | __ Bind(slow_path->GetExitLabel()); |
| 1884 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1885 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1886 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1887 | BarrierType type = BarrierAll; |
| 1888 | |
| 1889 | switch (kind) { |
| 1890 | case MemBarrierKind::kAnyAny: |
| 1891 | case MemBarrierKind::kAnyStore: { |
| 1892 | type = BarrierAll; |
| 1893 | break; |
| 1894 | } |
| 1895 | case MemBarrierKind::kLoadAny: { |
| 1896 | type = BarrierReads; |
| 1897 | break; |
| 1898 | } |
| 1899 | case MemBarrierKind::kStoreStore: { |
| 1900 | type = BarrierWrites; |
| 1901 | break; |
| 1902 | } |
| 1903 | default: |
| 1904 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1905 | } |
| 1906 | __ Dmb(InnerShareable, type); |
| 1907 | } |
| 1908 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1909 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1910 | HBasicBlock* successor) { |
| 1911 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1912 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1913 | if (slow_path == nullptr) { |
| 1914 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1915 | instruction->SetSlowPath(slow_path); |
| 1916 | codegen_->AddSlowPath(slow_path); |
| 1917 | if (successor != nullptr) { |
| 1918 | DCHECK(successor->IsLoopHeader()); |
| 1919 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1920 | } |
| 1921 | } else { |
| 1922 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1923 | } |
| 1924 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1925 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1926 | Register temp = temps.AcquireW(); |
| 1927 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1928 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1929 | if (successor == nullptr) { |
| 1930 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1931 | __ Bind(slow_path->GetReturnLabel()); |
| 1932 | } else { |
| 1933 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1934 | __ B(slow_path->GetEntryLabel()); |
| 1935 | // slow_path will return to GetLabelOf(successor). |
| 1936 | } |
| 1937 | } |
| 1938 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1939 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1940 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1941 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1942 | assembler_(codegen->GetAssembler()), |
| 1943 | codegen_(codegen) {} |
| 1944 | |
| 1945 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1946 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1947 | |
| 1948 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1949 | |
| 1950 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1951 | // Using a base helps identify when we hit such breakpoints. |
| 1952 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1953 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1954 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1955 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1956 | }; |
| 1957 | |
| 1958 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1959 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1960 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1961 | } \ |
| 1962 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1963 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1964 | locations->SetOut(Location::Any()); \ |
| 1965 | } |
| 1966 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1967 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1968 | |
| 1969 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1970 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1971 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1972 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1973 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1974 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1975 | Primitive::Type type = instr->GetResultType(); |
| 1976 | switch (type) { |
| 1977 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1978 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1979 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1980 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1981 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1982 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1983 | |
| 1984 | case Primitive::kPrimFloat: |
| 1985 | case Primitive::kPrimDouble: |
| 1986 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1987 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1988 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1989 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1990 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1991 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1992 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1996 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1997 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1998 | |
| 1999 | bool object_field_get_with_read_barrier = |
| 2000 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2001 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2002 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2003 | object_field_get_with_read_barrier ? |
| 2004 | LocationSummary::kCallOnSlowPath : |
| 2005 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2006 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2007 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2008 | // We need a temporary register for the read barrier marking slow |
| 2009 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
| 2010 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2011 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2012 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2013 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2014 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2015 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2016 | // The output overlaps for an object field get when read barriers |
| 2017 | // are enabled: we do not want the load to overwrite the object's |
| 2018 | // location, as we need it to emit the read barrier. |
| 2019 | locations->SetOut( |
| 2020 | Location::RequiresRegister(), |
| 2021 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2026 | const FieldInfo& field_info) { |
| 2027 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2028 | LocationSummary* locations = instruction->GetLocations(); |
| 2029 | Location base_loc = locations->InAt(0); |
| 2030 | Location out = locations->Out(); |
| 2031 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2032 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2033 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2034 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2035 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2036 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2037 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2038 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2039 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2040 | // Note that potential implicit null checks are handled in this |
| 2041 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2042 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2043 | instruction, |
| 2044 | out, |
| 2045 | base, |
| 2046 | offset, |
| 2047 | temp, |
| 2048 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2049 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2050 | } else { |
| 2051 | // General case. |
| 2052 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2053 | // Note that a potential implicit null check is handled in this |
| 2054 | // CodeGeneratorARM64::LoadAcquire call. |
| 2055 | // NB: LoadAcquire will record the pc info if needed. |
| 2056 | codegen_->LoadAcquire( |
| 2057 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2058 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2059 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2060 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2061 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2062 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2063 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2064 | if (field_type == Primitive::kPrimNot) { |
| 2065 | // If read barriers are enabled, emit read barriers other than |
| 2066 | // Baker's using a slow path (and also unpoison the loaded |
| 2067 | // reference, if heap poisoning is enabled). |
| 2068 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2069 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2070 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2074 | LocationSummary* locations = |
| 2075 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2076 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2077 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2078 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2079 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2080 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2081 | } else { |
| 2082 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2087 | const FieldInfo& field_info, |
| 2088 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2089 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2090 | |
| 2091 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2092 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2093 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2094 | Offset offset = field_info.GetFieldOffset(); |
| 2095 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2096 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2097 | { |
| 2098 | // We use a block to end the scratch scope before the write barrier, thus |
| 2099 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2100 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2101 | |
| 2102 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2103 | DCHECK(value.IsW()); |
| 2104 | Register temp = temps.AcquireW(); |
| 2105 | __ Mov(temp, value.W()); |
| 2106 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2107 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2108 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2109 | |
| 2110 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2111 | codegen_->StoreRelease( |
| 2112 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2113 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2114 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2115 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2116 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2117 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2118 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2122 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2123 | } |
| 2124 | } |
| 2125 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2126 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2127 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2128 | |
| 2129 | switch (type) { |
| 2130 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2131 | case Primitive::kPrimLong: { |
| 2132 | Register dst = OutputRegister(instr); |
| 2133 | Register lhs = InputRegisterAt(instr, 0); |
| 2134 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2135 | if (instr->IsAdd()) { |
| 2136 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2137 | } else if (instr->IsAnd()) { |
| 2138 | __ And(dst, lhs, rhs); |
| 2139 | } else if (instr->IsOr()) { |
| 2140 | __ Orr(dst, lhs, rhs); |
| 2141 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2142 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2143 | } else if (instr->IsRor()) { |
| 2144 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2145 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2146 | __ Ror(dst, lhs, shift); |
| 2147 | } else { |
| 2148 | // Ensure shift distance is in the same size register as the result. If |
| 2149 | // we are rotating a long and the shift comes in a w register originally, |
| 2150 | // we don't need to sxtw for use as an x since the shift distances are |
| 2151 | // all & reg_bits - 1. |
| 2152 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2153 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2154 | } else { |
| 2155 | DCHECK(instr->IsXor()); |
| 2156 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2157 | } |
| 2158 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2159 | } |
| 2160 | case Primitive::kPrimFloat: |
| 2161 | case Primitive::kPrimDouble: { |
| 2162 | FPRegister dst = OutputFPRegister(instr); |
| 2163 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2164 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2165 | if (instr->IsAdd()) { |
| 2166 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2167 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2168 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2169 | } else { |
| 2170 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2171 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2172 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2173 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2174 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2175 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2176 | } |
| 2177 | } |
| 2178 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2179 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2180 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2181 | |
| 2182 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2183 | Primitive::Type type = instr->GetResultType(); |
| 2184 | switch (type) { |
| 2185 | case Primitive::kPrimInt: |
| 2186 | case Primitive::kPrimLong: { |
| 2187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2188 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2189 | locations->SetOut(Location::RequiresRegister()); |
| 2190 | break; |
| 2191 | } |
| 2192 | default: |
| 2193 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2198 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2199 | |
| 2200 | Primitive::Type type = instr->GetType(); |
| 2201 | switch (type) { |
| 2202 | case Primitive::kPrimInt: |
| 2203 | case Primitive::kPrimLong: { |
| 2204 | Register dst = OutputRegister(instr); |
| 2205 | Register lhs = InputRegisterAt(instr, 0); |
| 2206 | Operand rhs = InputOperandAt(instr, 1); |
| 2207 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2208 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2209 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2210 | if (instr->IsShl()) { |
| 2211 | __ Lsl(dst, lhs, shift_value); |
| 2212 | } else if (instr->IsShr()) { |
| 2213 | __ Asr(dst, lhs, shift_value); |
| 2214 | } else { |
| 2215 | __ Lsr(dst, lhs, shift_value); |
| 2216 | } |
| 2217 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2218 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2219 | |
| 2220 | if (instr->IsShl()) { |
| 2221 | __ Lsl(dst, lhs, rhs_reg); |
| 2222 | } else if (instr->IsShr()) { |
| 2223 | __ Asr(dst, lhs, rhs_reg); |
| 2224 | } else { |
| 2225 | __ Lsr(dst, lhs, rhs_reg); |
| 2226 | } |
| 2227 | } |
| 2228 | break; |
| 2229 | } |
| 2230 | default: |
| 2231 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2232 | } |
| 2233 | } |
| 2234 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2235 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2236 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2240 | HandleBinaryOp(instruction); |
| 2241 | } |
| 2242 | |
| 2243 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2244 | HandleBinaryOp(instruction); |
| 2245 | } |
| 2246 | |
| 2247 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2248 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2249 | } |
| 2250 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2251 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2252 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2253 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2255 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2256 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2257 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2258 | } |
| 2259 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2260 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2261 | Register dst = OutputRegister(instr); |
| 2262 | Register lhs = InputRegisterAt(instr, 0); |
| 2263 | Register rhs = InputRegisterAt(instr, 1); |
| 2264 | |
| 2265 | switch (instr->GetOpKind()) { |
| 2266 | case HInstruction::kAnd: |
| 2267 | __ Bic(dst, lhs, rhs); |
| 2268 | break; |
| 2269 | case HInstruction::kOr: |
| 2270 | __ Orn(dst, lhs, rhs); |
| 2271 | break; |
| 2272 | case HInstruction::kXor: |
| 2273 | __ Eon(dst, lhs, rhs); |
| 2274 | break; |
| 2275 | default: |
| 2276 | LOG(FATAL) << "Unreachable"; |
| 2277 | } |
| 2278 | } |
| 2279 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2280 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2281 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2282 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2283 | instruction->GetType() == Primitive::kPrimLong); |
| 2284 | LocationSummary* locations = |
| 2285 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2286 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2287 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2288 | } else { |
| 2289 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2290 | } |
| 2291 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2292 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2293 | } |
| 2294 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2295 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2296 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2297 | Primitive::Type type = instruction->GetType(); |
| 2298 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2299 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2300 | Register out = OutputRegister(instruction); |
| 2301 | Register left; |
| 2302 | if (kind != HInstruction::kNeg) { |
| 2303 | left = InputRegisterAt(instruction, 0); |
| 2304 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2305 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2306 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2307 | // conversion) can have a different type from the current instruction's type, |
| 2308 | // so we manually indicate the type. |
| 2309 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2310 | Operand right_operand(0); |
| 2311 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2312 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2313 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2314 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2315 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2316 | right_operand = Operand(right_reg, |
| 2317 | helpers::ShiftFromOpKind(op_kind), |
| 2318 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | // Logical binary operations do not support extension operations in the |
| 2322 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2323 | // the extension as a separate instruction. |
| 2324 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2325 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2326 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2327 | kind != HInstruction::kNeg)); |
| 2328 | switch (kind) { |
| 2329 | case HInstruction::kAdd: |
| 2330 | __ Add(out, left, right_operand); |
| 2331 | break; |
| 2332 | case HInstruction::kAnd: |
| 2333 | __ And(out, left, right_operand); |
| 2334 | break; |
| 2335 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2336 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2337 | __ Neg(out, right_operand); |
| 2338 | break; |
| 2339 | case HInstruction::kOr: |
| 2340 | __ Orr(out, left, right_operand); |
| 2341 | break; |
| 2342 | case HInstruction::kSub: |
| 2343 | __ Sub(out, left, right_operand); |
| 2344 | break; |
| 2345 | case HInstruction::kXor: |
| 2346 | __ Eor(out, left, right_operand); |
| 2347 | break; |
| 2348 | default: |
| 2349 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2350 | UNREACHABLE(); |
| 2351 | } |
| 2352 | } |
| 2353 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2354 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2355 | LocationSummary* locations = |
| 2356 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2357 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2358 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 2359 | locations->SetOut(Location::RequiresRegister()); |
| 2360 | } |
| 2361 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2362 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2363 | __ Add(OutputRegister(instruction), |
| 2364 | InputRegisterAt(instruction, 0), |
| 2365 | Operand(InputOperandAt(instruction, 1))); |
| 2366 | } |
| 2367 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2368 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2369 | LocationSummary* locations = |
| 2370 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2371 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2372 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2373 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2374 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2375 | // Don't allocate register for Mneg instruction. |
| 2376 | } else { |
| 2377 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2378 | Location::RequiresRegister()); |
| 2379 | } |
| 2380 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2381 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2383 | } |
| 2384 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2385 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2386 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2387 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2388 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2389 | |
| 2390 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2391 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2392 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2393 | if (instr->GetType() == Primitive::kPrimLong && |
| 2394 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2395 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2396 | vixl::aarch64::Instruction* prev = |
| 2397 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2398 | if (prev->IsLoadOrStore()) { |
| 2399 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2400 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2401 | __ nop(); |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2406 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2407 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2408 | } else { |
| 2409 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2410 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2411 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2412 | __ Mneg(res, mul_left, mul_right); |
| 2413 | } else { |
| 2414 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2415 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2416 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2420 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2421 | bool object_array_get_with_read_barrier = |
| 2422 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2423 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2424 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2425 | object_array_get_with_read_barrier ? |
| 2426 | LocationSummary::kCallOnSlowPath : |
| 2427 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2428 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2429 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2430 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2431 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2432 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2433 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2434 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2435 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2436 | // The output overlaps in the case of an object array get with |
| 2437 | // read barriers enabled: we do not want the move to overwrite the |
| 2438 | // array's location, as we need it to emit the read barrier. |
| 2439 | locations->SetOut( |
| 2440 | Location::RequiresRegister(), |
| 2441 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2442 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2446 | Primitive::Type type = instruction->GetType(); |
| 2447 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2448 | LocationSummary* locations = instruction->GetLocations(); |
| 2449 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2450 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2451 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2452 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2453 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2454 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2455 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2456 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2457 | // The read barrier instrumentation of object ArrayGet instructions |
| 2458 | // does not support the HIntermediateAddress instruction. |
| 2459 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2460 | instruction->GetArray()->IsIntermediateAddress() && |
| 2461 | kEmitCompilerReadBarrier)); |
| 2462 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2463 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2464 | // Object ArrayGet with Baker's read barrier case. |
| 2465 | Register temp = temps.AcquireW(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2466 | // Note that a potential implicit null check is handled in the |
| 2467 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2468 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2469 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2470 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2471 | // General case. |
| 2472 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2473 | Register length; |
| 2474 | if (maybe_compressed_char_at) { |
| 2475 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2476 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2477 | { |
| 2478 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2479 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2480 | |
| 2481 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2482 | DCHECK_LT(count_offset, offset); |
| 2483 | int64_t adjusted_offset = |
| 2484 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2485 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2486 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2487 | } else { |
| 2488 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2489 | } |
| 2490 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2491 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2492 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2493 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2494 | if (maybe_compressed_char_at) { |
| 2495 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2496 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2497 | "Expecting 0=compressed, 1=uncompressed"); |
| 2498 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2499 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2500 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2501 | __ B(&done); |
| 2502 | __ Bind(&uncompressed_load); |
| 2503 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2504 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2505 | __ Bind(&done); |
| 2506 | } else { |
| 2507 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2508 | source = HeapOperand(obj, offset); |
| 2509 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2510 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2511 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2512 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2513 | // We do not need to compute the intermediate address from the array: the |
| 2514 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2515 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2516 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2517 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2518 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2519 | } |
| 2520 | temp = obj; |
| 2521 | } else { |
| 2522 | __ Add(temp, obj, offset); |
| 2523 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2524 | if (maybe_compressed_char_at) { |
| 2525 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2526 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2527 | "Expecting 0=compressed, 1=uncompressed"); |
| 2528 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2529 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2530 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2531 | __ B(&done); |
| 2532 | __ Bind(&uncompressed_load); |
| 2533 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2534 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2535 | __ Bind(&done); |
| 2536 | } else { |
| 2537 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2538 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2539 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2540 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2541 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2542 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2543 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2544 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2545 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2546 | |
| 2547 | if (type == Primitive::kPrimNot) { |
| 2548 | static_assert( |
| 2549 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2550 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2551 | Location obj_loc = locations->InAt(0); |
| 2552 | if (index.IsConstant()) { |
| 2553 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2554 | } else { |
| 2555 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2556 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2557 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2558 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2561 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2562 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2563 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2564 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2568 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2569 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2570 | { |
| 2571 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2572 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2573 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2574 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2575 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2576 | // Mask out compression flag from String's array length. |
| 2577 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2578 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2579 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2580 | } |
| 2581 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2582 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2583 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2584 | |
| 2585 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2586 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2587 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2588 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2589 | LocationSummary::kCallOnSlowPath : |
| 2590 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2591 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2592 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2593 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2594 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2595 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2596 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2597 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2598 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2603 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2604 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2605 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2606 | bool needs_write_barrier = |
| 2607 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2608 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2609 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2610 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2611 | CPURegister source = value; |
| 2612 | Location index = locations->InAt(1); |
| 2613 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2614 | MemOperand destination = HeapOperand(array); |
| 2615 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2616 | |
| 2617 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2618 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2619 | if (index.IsConstant()) { |
| 2620 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2621 | destination = HeapOperand(array, offset); |
| 2622 | } else { |
| 2623 | UseScratchRegisterScope temps(masm); |
| 2624 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2625 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2626 | // We do not need to compute the intermediate address from the array: the |
| 2627 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2628 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2629 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2630 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2631 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2632 | } |
| 2633 | temp = array; |
| 2634 | } else { |
| 2635 | __ Add(temp, array, offset); |
| 2636 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2637 | destination = HeapOperand(temp, |
| 2638 | XRegisterFrom(index), |
| 2639 | LSL, |
| 2640 | Primitive::ComponentSizeShift(value_type)); |
| 2641 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2642 | { |
| 2643 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2644 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2645 | codegen_->Store(value_type, value, destination); |
| 2646 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2647 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2648 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2649 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2650 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2651 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2652 | { |
| 2653 | // We use a block to end the scratch scope before the write barrier, thus |
| 2654 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2655 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2656 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2657 | if (index.IsConstant()) { |
| 2658 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2659 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2660 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2661 | destination = HeapOperand(temp, |
| 2662 | XRegisterFrom(index), |
| 2663 | LSL, |
| 2664 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2665 | } |
| 2666 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2667 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2668 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2669 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2670 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2671 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2672 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2673 | codegen_->AddSlowPath(slow_path); |
| 2674 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2675 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2676 | __ Cbnz(Register(value), &non_zero); |
| 2677 | if (!index.IsConstant()) { |
| 2678 | __ Add(temp, array, offset); |
| 2679 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2680 | { |
| 2681 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 2682 | // emitted. |
| 2683 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2684 | __ Str(wzr, destination); |
| 2685 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2686 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2687 | __ B(&done); |
| 2688 | __ Bind(&non_zero); |
| 2689 | } |
| 2690 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2691 | // Note that when Baker read barriers are enabled, the type |
| 2692 | // checks are performed without read barriers. This is fine, |
| 2693 | // even in the case where a class object is in the from-space |
| 2694 | // after the flip, as a comparison involving such a type would |
| 2695 | // not produce a false positive; it may of course produce a |
| 2696 | // false negative, in which case we would take the ArraySet |
| 2697 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2698 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2699 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2700 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2701 | { |
| 2702 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2703 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2704 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2705 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2706 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2707 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2708 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2709 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2710 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2711 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2712 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2713 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2714 | // nor `temp2`, as we are comparing two poisoned references. |
| 2715 | __ Cmp(temp, temp2); |
| 2716 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2717 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2718 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2719 | vixl::aarch64::Label do_put; |
| 2720 | __ B(eq, &do_put); |
| 2721 | // If heap poisoning is enabled, the `temp` reference has |
| 2722 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2723 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2724 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2725 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2726 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2727 | // If heap poisoning is enabled, no need to unpoison |
| 2728 | // `temp`, as we are comparing against null below. |
| 2729 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2730 | __ Bind(&do_put); |
| 2731 | } else { |
| 2732 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2737 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2738 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2739 | __ Mov(temp2, value.W()); |
| 2740 | GetAssembler()->PoisonHeapReference(temp2); |
| 2741 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | if (!index.IsConstant()) { |
| 2745 | __ Add(temp, array, offset); |
| 2746 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2747 | { |
| 2748 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2749 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2750 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2751 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2752 | if (!may_need_runtime_call_for_type_check) { |
| 2753 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2754 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2755 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2756 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2757 | |
| 2758 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2759 | |
| 2760 | if (done.IsLinked()) { |
| 2761 | __ Bind(&done); |
| 2762 | } |
| 2763 | |
| 2764 | if (slow_path != nullptr) { |
| 2765 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2766 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2770 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2771 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2772 | InvokeRuntimeCallingConvention calling_convention; |
| 2773 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2774 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2775 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2776 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2777 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2781 | BoundsCheckSlowPathARM64* slow_path = |
| 2782 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2783 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2784 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2785 | __ B(slow_path->GetEntryLabel(), hs); |
| 2786 | } |
| 2787 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2788 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2789 | LocationSummary* locations = |
| 2790 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2791 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2792 | if (check->HasUses()) { |
| 2793 | locations->SetOut(Location::SameAsFirstInput()); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2798 | // We assume the class is not null. |
| 2799 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2800 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2801 | codegen_->AddSlowPath(slow_path); |
| 2802 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2803 | } |
| 2804 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2805 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2806 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2807 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2808 | } |
| 2809 | |
| 2810 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2811 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2812 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2813 | if (rhs_loc.IsConstant()) { |
| 2814 | // 0.0 is the only immediate that can be encoded directly in |
| 2815 | // an FCMP instruction. |
| 2816 | // |
| 2817 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2818 | // specify that in a floating-point comparison, positive zero |
| 2819 | // and negative zero are considered equal, so we can use the |
| 2820 | // literal 0.0 for both cases here. |
| 2821 | // |
| 2822 | // Note however that some methods (Float.equal, Float.compare, |
| 2823 | // Float.compareTo, Double.equal, Double.compare, |
| 2824 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2825 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2826 | // -0.0. So if we ever translate calls to these methods into a |
| 2827 | // HCompare instruction, we must handle the -0.0 case with |
| 2828 | // care here. |
| 2829 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2830 | __ Fcmp(lhs_reg, 0.0); |
| 2831 | } else { |
| 2832 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2833 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2836 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2837 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2838 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2839 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2840 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2841 | case Primitive::kPrimBoolean: |
| 2842 | case Primitive::kPrimByte: |
| 2843 | case Primitive::kPrimShort: |
| 2844 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2845 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2846 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2847 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2848 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2849 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2850 | break; |
| 2851 | } |
| 2852 | case Primitive::kPrimFloat: |
| 2853 | case Primitive::kPrimDouble: { |
| 2854 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2855 | locations->SetInAt(1, |
| 2856 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2857 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2858 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2859 | locations->SetOut(Location::RequiresRegister()); |
| 2860 | break; |
| 2861 | } |
| 2862 | default: |
| 2863 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2868 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2869 | |
| 2870 | // 0 if: left == right |
| 2871 | // 1 if: left > right |
| 2872 | // -1 if: left < right |
| 2873 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2874 | case Primitive::kPrimBoolean: |
| 2875 | case Primitive::kPrimByte: |
| 2876 | case Primitive::kPrimShort: |
| 2877 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2878 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2879 | case Primitive::kPrimLong: { |
| 2880 | Register result = OutputRegister(compare); |
| 2881 | Register left = InputRegisterAt(compare, 0); |
| 2882 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2883 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2884 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2885 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2886 | break; |
| 2887 | } |
| 2888 | case Primitive::kPrimFloat: |
| 2889 | case Primitive::kPrimDouble: { |
| 2890 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2891 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2892 | __ Cset(result, ne); |
| 2893 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2894 | break; |
| 2895 | } |
| 2896 | default: |
| 2897 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2898 | } |
| 2899 | } |
| 2900 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2901 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2902 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2903 | |
| 2904 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2905 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2906 | locations->SetInAt(1, |
| 2907 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2908 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2909 | : Location::RequiresFpuRegister()); |
| 2910 | } else { |
| 2911 | // Integer cases. |
| 2912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2913 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2914 | } |
| 2915 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2916 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2917 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2918 | } |
| 2919 | } |
| 2920 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2921 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2922 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2923 | return; |
| 2924 | } |
| 2925 | |
| 2926 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2927 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2928 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2929 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2930 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2931 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2932 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2933 | } else { |
| 2934 | // Integer cases. |
| 2935 | Register lhs = InputRegisterAt(instruction, 0); |
| 2936 | Operand rhs = InputOperandAt(instruction, 1); |
| 2937 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2938 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2939 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2943 | M(Equal) \ |
| 2944 | M(NotEqual) \ |
| 2945 | M(LessThan) \ |
| 2946 | M(LessThanOrEqual) \ |
| 2947 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2948 | M(GreaterThanOrEqual) \ |
| 2949 | M(Below) \ |
| 2950 | M(BelowOrEqual) \ |
| 2951 | M(Above) \ |
| 2952 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2953 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2954 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2955 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2956 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2957 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2958 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2959 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2960 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2961 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2962 | |
| 2963 | LocationSummary* locations = instruction->GetLocations(); |
| 2964 | Location second = locations->InAt(1); |
| 2965 | DCHECK(second.IsConstant()); |
| 2966 | |
| 2967 | Register out = OutputRegister(instruction); |
| 2968 | Register dividend = InputRegisterAt(instruction, 0); |
| 2969 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2970 | DCHECK(imm == 1 || imm == -1); |
| 2971 | |
| 2972 | if (instruction->IsRem()) { |
| 2973 | __ Mov(out, 0); |
| 2974 | } else { |
| 2975 | if (imm == 1) { |
| 2976 | __ Mov(out, dividend); |
| 2977 | } else { |
| 2978 | __ Neg(out, dividend); |
| 2979 | } |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2984 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2985 | |
| 2986 | LocationSummary* locations = instruction->GetLocations(); |
| 2987 | Location second = locations->InAt(1); |
| 2988 | DCHECK(second.IsConstant()); |
| 2989 | |
| 2990 | Register out = OutputRegister(instruction); |
| 2991 | Register dividend = InputRegisterAt(instruction, 0); |
| 2992 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2993 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2994 | int ctz_imm = CTZ(abs_imm); |
| 2995 | |
| 2996 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2997 | Register temp = temps.AcquireSameSizeAs(out); |
| 2998 | |
| 2999 | if (instruction->IsDiv()) { |
| 3000 | __ Add(temp, dividend, abs_imm - 1); |
| 3001 | __ Cmp(dividend, 0); |
| 3002 | __ Csel(out, temp, dividend, lt); |
| 3003 | if (imm > 0) { |
| 3004 | __ Asr(out, out, ctz_imm); |
| 3005 | } else { |
| 3006 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3007 | } |
| 3008 | } else { |
| 3009 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3010 | __ Asr(temp, dividend, bits - 1); |
| 3011 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3012 | __ Add(out, dividend, temp); |
| 3013 | __ And(out, out, abs_imm - 1); |
| 3014 | __ Sub(out, out, temp); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3019 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3020 | |
| 3021 | LocationSummary* locations = instruction->GetLocations(); |
| 3022 | Location second = locations->InAt(1); |
| 3023 | DCHECK(second.IsConstant()); |
| 3024 | |
| 3025 | Register out = OutputRegister(instruction); |
| 3026 | Register dividend = InputRegisterAt(instruction, 0); |
| 3027 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3028 | |
| 3029 | Primitive::Type type = instruction->GetResultType(); |
| 3030 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3031 | |
| 3032 | int64_t magic; |
| 3033 | int shift; |
| 3034 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3035 | |
| 3036 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3037 | Register temp = temps.AcquireSameSizeAs(out); |
| 3038 | |
| 3039 | // temp = get_high(dividend * magic) |
| 3040 | __ Mov(temp, magic); |
| 3041 | if (type == Primitive::kPrimLong) { |
| 3042 | __ Smulh(temp, dividend, temp); |
| 3043 | } else { |
| 3044 | __ Smull(temp.X(), dividend, temp); |
| 3045 | __ Lsr(temp.X(), temp.X(), 32); |
| 3046 | } |
| 3047 | |
| 3048 | if (imm > 0 && magic < 0) { |
| 3049 | __ Add(temp, temp, dividend); |
| 3050 | } else if (imm < 0 && magic > 0) { |
| 3051 | __ Sub(temp, temp, dividend); |
| 3052 | } |
| 3053 | |
| 3054 | if (shift != 0) { |
| 3055 | __ Asr(temp, temp, shift); |
| 3056 | } |
| 3057 | |
| 3058 | if (instruction->IsDiv()) { |
| 3059 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3060 | } else { |
| 3061 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3062 | // TODO: Strength reduction for msub. |
| 3063 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3064 | __ Mov(temp_imm, imm); |
| 3065 | __ Msub(out, temp, temp_imm, dividend); |
| 3066 | } |
| 3067 | } |
| 3068 | |
| 3069 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3070 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3071 | Primitive::Type type = instruction->GetResultType(); |
| 3072 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3073 | |
| 3074 | LocationSummary* locations = instruction->GetLocations(); |
| 3075 | Register out = OutputRegister(instruction); |
| 3076 | Location second = locations->InAt(1); |
| 3077 | |
| 3078 | if (second.IsConstant()) { |
| 3079 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3080 | |
| 3081 | if (imm == 0) { |
| 3082 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3083 | } else if (imm == 1 || imm == -1) { |
| 3084 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3085 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3086 | DivRemByPowerOfTwo(instruction); |
| 3087 | } else { |
| 3088 | DCHECK(imm <= -2 || imm >= 2); |
| 3089 | GenerateDivRemWithAnyConstant(instruction); |
| 3090 | } |
| 3091 | } else { |
| 3092 | Register dividend = InputRegisterAt(instruction, 0); |
| 3093 | Register divisor = InputRegisterAt(instruction, 1); |
| 3094 | if (instruction->IsDiv()) { |
| 3095 | __ Sdiv(out, dividend, divisor); |
| 3096 | } else { |
| 3097 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3098 | Register temp = temps.AcquireSameSizeAs(out); |
| 3099 | __ Sdiv(temp, dividend, divisor); |
| 3100 | __ Msub(out, temp, divisor, dividend); |
| 3101 | } |
| 3102 | } |
| 3103 | } |
| 3104 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3105 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3106 | LocationSummary* locations = |
| 3107 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3108 | switch (div->GetResultType()) { |
| 3109 | case Primitive::kPrimInt: |
| 3110 | case Primitive::kPrimLong: |
| 3111 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3112 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3113 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3114 | break; |
| 3115 | |
| 3116 | case Primitive::kPrimFloat: |
| 3117 | case Primitive::kPrimDouble: |
| 3118 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3119 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3120 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3121 | break; |
| 3122 | |
| 3123 | default: |
| 3124 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3129 | Primitive::Type type = div->GetResultType(); |
| 3130 | switch (type) { |
| 3131 | case Primitive::kPrimInt: |
| 3132 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3133 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3134 | break; |
| 3135 | |
| 3136 | case Primitive::kPrimFloat: |
| 3137 | case Primitive::kPrimDouble: |
| 3138 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3139 | break; |
| 3140 | |
| 3141 | default: |
| 3142 | LOG(FATAL) << "Unexpected div type " << type; |
| 3143 | } |
| 3144 | } |
| 3145 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3146 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3147 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3148 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3152 | SlowPathCodeARM64* slow_path = |
| 3153 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3154 | codegen_->AddSlowPath(slow_path); |
| 3155 | Location value = instruction->GetLocations()->InAt(0); |
| 3156 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3157 | Primitive::Type type = instruction->GetType(); |
| 3158 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3159 | if (!Primitive::IsIntegralType(type)) { |
| 3160 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3161 | return; |
| 3162 | } |
| 3163 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3164 | if (value.IsConstant()) { |
| 3165 | int64_t divisor = Int64ConstantFrom(value); |
| 3166 | if (divisor == 0) { |
| 3167 | __ B(slow_path->GetEntryLabel()); |
| 3168 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3169 | // A division by a non-null constant is valid. We don't need to perform |
| 3170 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3171 | } |
| 3172 | } else { |
| 3173 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3174 | } |
| 3175 | } |
| 3176 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3177 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3178 | LocationSummary* locations = |
| 3179 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3180 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3181 | } |
| 3182 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3183 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3184 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3185 | // Will be generated at use site. |
| 3186 | } |
| 3187 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3188 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3189 | exit->SetLocations(nullptr); |
| 3190 | } |
| 3191 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3192 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3193 | } |
| 3194 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3195 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3196 | LocationSummary* locations = |
| 3197 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3198 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3199 | } |
| 3200 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3201 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3202 | // Will be generated at use site. |
| 3203 | } |
| 3204 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3205 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3206 | DCHECK(!successor->IsExitBlock()); |
| 3207 | HBasicBlock* block = got->GetBlock(); |
| 3208 | HInstruction* previous = got->GetPrevious(); |
| 3209 | HLoopInformation* info = block->GetLoopInformation(); |
| 3210 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3211 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3212 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3213 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3214 | return; |
| 3215 | } |
| 3216 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3217 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3218 | } |
| 3219 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3220 | __ B(codegen_->GetLabelOf(successor)); |
| 3221 | } |
| 3222 | } |
| 3223 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3224 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3225 | got->SetLocations(nullptr); |
| 3226 | } |
| 3227 | |
| 3228 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3229 | HandleGoto(got, got->GetSuccessor()); |
| 3230 | } |
| 3231 | |
| 3232 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3233 | try_boundary->SetLocations(nullptr); |
| 3234 | } |
| 3235 | |
| 3236 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3237 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3238 | if (!successor->IsExitBlock()) { |
| 3239 | HandleGoto(try_boundary, successor); |
| 3240 | } |
| 3241 | } |
| 3242 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3243 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3244 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3245 | vixl::aarch64::Label* true_target, |
| 3246 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3247 | // FP branching requires both targets to be explicit. If either of the targets |
| 3248 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3249 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3250 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3251 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3252 | if (true_target == nullptr && false_target == nullptr) { |
| 3253 | // Nothing to do. The code always falls through. |
| 3254 | return; |
| 3255 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3256 | // Constant condition, statically compared against "true" (integer value 1). |
| 3257 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3258 | if (true_target != nullptr) { |
| 3259 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3260 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3261 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3262 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3263 | if (false_target != nullptr) { |
| 3264 | __ B(false_target); |
| 3265 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3266 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3267 | return; |
| 3268 | } |
| 3269 | |
| 3270 | // The following code generates these patterns: |
| 3271 | // (1) true_target == nullptr && false_target != nullptr |
| 3272 | // - opposite condition true => branch to false_target |
| 3273 | // (2) true_target != nullptr && false_target == nullptr |
| 3274 | // - condition true => branch to true_target |
| 3275 | // (3) true_target != nullptr && false_target != nullptr |
| 3276 | // - condition true => branch to true_target |
| 3277 | // - branch to false_target |
| 3278 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3279 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3280 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3281 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3282 | if (true_target == nullptr) { |
| 3283 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3284 | } else { |
| 3285 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3286 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3287 | } else { |
| 3288 | // The condition instruction has not been materialized, use its inputs as |
| 3289 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3290 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3291 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3292 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3293 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3294 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3295 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3296 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3297 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3298 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3299 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3300 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3301 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3302 | // Integer cases. |
| 3303 | Register lhs = InputRegisterAt(condition, 0); |
| 3304 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3305 | |
| 3306 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3307 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3308 | if (true_target == nullptr) { |
| 3309 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3310 | non_fallthrough_target = false_target; |
| 3311 | } else { |
| 3312 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3313 | non_fallthrough_target = true_target; |
| 3314 | } |
| 3315 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3316 | 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] | 3317 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3318 | switch (arm64_cond) { |
| 3319 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3320 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3321 | break; |
| 3322 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3323 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3324 | break; |
| 3325 | case lt: |
| 3326 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3327 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3328 | break; |
| 3329 | case ge: |
| 3330 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3331 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3332 | break; |
| 3333 | default: |
| 3334 | // Without the `static_cast` the compiler throws an error for |
| 3335 | // `-Werror=sign-promo`. |
| 3336 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3337 | } |
| 3338 | } else { |
| 3339 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3340 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3341 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3342 | } |
| 3343 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3344 | |
| 3345 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3346 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3347 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3348 | __ B(false_target); |
| 3349 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3350 | |
| 3351 | if (fallthrough_target.IsLinked()) { |
| 3352 | __ Bind(&fallthrough_target); |
| 3353 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3354 | } |
| 3355 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3356 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3357 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3358 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3364 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3365 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3366 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3367 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3368 | true_target = nullptr; |
| 3369 | } |
| 3370 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3371 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3372 | false_target = nullptr; |
| 3373 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3374 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3378 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3379 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3380 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3381 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3387 | SlowPathCodeARM64* slow_path = |
| 3388 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3389 | GenerateTestAndBranch(deoptimize, |
| 3390 | /* condition_input_index */ 0, |
| 3391 | slow_path->GetEntryLabel(), |
| 3392 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3395 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3396 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3397 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3398 | locations->SetOut(Location::RequiresRegister()); |
| 3399 | } |
| 3400 | |
| 3401 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3402 | __ Ldr(OutputRegister(flag), |
| 3403 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3404 | } |
| 3405 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3406 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3407 | return condition->IsCondition() && |
| 3408 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3409 | } |
| 3410 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3411 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3412 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3413 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3414 | : ARM64Condition(cond); |
| 3415 | } |
| 3416 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3417 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3418 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3419 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3420 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3421 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3422 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3423 | } else { |
| 3424 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3425 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3426 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3427 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3428 | // Ask VIXL whether we should synthesize constants in registers. |
| 3429 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3430 | Operand true_op = is_true_value_constant ? |
| 3431 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3432 | Operand false_op = is_false_value_constant ? |
| 3433 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3434 | bool true_value_in_register = false; |
| 3435 | bool false_value_in_register = false; |
| 3436 | MacroAssembler::GetCselSynthesisInformation( |
| 3437 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3438 | true_value_in_register |= !is_true_value_constant; |
| 3439 | false_value_in_register |= !is_false_value_constant; |
| 3440 | |
| 3441 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3442 | : Location::ConstantLocation(cst_true_value)); |
| 3443 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3444 | : Location::ConstantLocation(cst_false_value)); |
| 3445 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3446 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3447 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3448 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3449 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3450 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3454 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3455 | Condition csel_cond; |
| 3456 | |
| 3457 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3458 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3459 | // Use the condition flags set by the previous instruction. |
| 3460 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3461 | } else { |
| 3462 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3463 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3464 | } |
| 3465 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3466 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3467 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3468 | } else { |
| 3469 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3470 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3471 | } |
| 3472 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3473 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3474 | __ Fcsel(OutputFPRegister(select), |
| 3475 | InputFPRegisterAt(select, 1), |
| 3476 | InputFPRegisterAt(select, 0), |
| 3477 | csel_cond); |
| 3478 | } else { |
| 3479 | __ Csel(OutputRegister(select), |
| 3480 | InputOperandAt(select, 1), |
| 3481 | InputOperandAt(select, 0), |
| 3482 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3483 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3486 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3487 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3488 | } |
| 3489 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3490 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3491 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | void CodeGeneratorARM64::GenerateNop() { |
| 3495 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3496 | } |
| 3497 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3498 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3499 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3503 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3507 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3511 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3512 | } |
| 3513 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3514 | // Temp is used for read barrier. |
| 3515 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3516 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3517 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3518 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3519 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3520 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3521 | return 1; |
| 3522 | } |
| 3523 | return 0; |
| 3524 | } |
| 3525 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3526 | // 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] | 3527 | // interface pointer, one for loading the current interface. |
| 3528 | // The other checks have one temp for loading the object's class. |
| 3529 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3530 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3531 | return 3; |
| 3532 | } |
| 3533 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3534 | } |
| 3535 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3536 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3537 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3538 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3539 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3540 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3541 | case TypeCheckKind::kExactCheck: |
| 3542 | case TypeCheckKind::kAbstractClassCheck: |
| 3543 | case TypeCheckKind::kClassHierarchyCheck: |
| 3544 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3545 | call_kind = |
| 3546 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3547 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3548 | break; |
| 3549 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3550 | case TypeCheckKind::kUnresolvedCheck: |
| 3551 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3552 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3553 | break; |
| 3554 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3555 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3556 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3557 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3558 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3559 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3561 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3562 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3563 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3564 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3565 | // Add temps if necessary for read barriers. |
| 3566 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3570 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3571 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3572 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3573 | Register obj = InputRegisterAt(instruction, 0); |
| 3574 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3575 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3576 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3577 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3578 | DCHECK_LE(num_temps, 1u); |
| 3579 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3580 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3581 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3582 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3583 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3584 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3585 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3586 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3587 | |
| 3588 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3589 | // Avoid null check if we know `obj` is not null. |
| 3590 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3591 | __ Cbz(obj, &zero); |
| 3592 | } |
| 3593 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3594 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3595 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3596 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3597 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3598 | out_loc, |
| 3599 | obj_loc, |
| 3600 | class_offset, |
| 3601 | maybe_temp_loc, |
| 3602 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3603 | __ Cmp(out, cls); |
| 3604 | __ Cset(out, eq); |
| 3605 | if (zero.IsLinked()) { |
| 3606 | __ B(&done); |
| 3607 | } |
| 3608 | break; |
| 3609 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3610 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3611 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3612 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3613 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3614 | out_loc, |
| 3615 | obj_loc, |
| 3616 | class_offset, |
| 3617 | maybe_temp_loc, |
| 3618 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3619 | // If the class is abstract, we eagerly fetch the super class of the |
| 3620 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3621 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3622 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3623 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3624 | GenerateReferenceLoadOneRegister(instruction, |
| 3625 | out_loc, |
| 3626 | super_offset, |
| 3627 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3628 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3629 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3630 | __ Cbz(out, &done); |
| 3631 | __ Cmp(out, cls); |
| 3632 | __ B(ne, &loop); |
| 3633 | __ Mov(out, 1); |
| 3634 | if (zero.IsLinked()) { |
| 3635 | __ B(&done); |
| 3636 | } |
| 3637 | break; |
| 3638 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3639 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3640 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3641 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3642 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3643 | out_loc, |
| 3644 | obj_loc, |
| 3645 | class_offset, |
| 3646 | maybe_temp_loc, |
| 3647 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3648 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3649 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3650 | __ Bind(&loop); |
| 3651 | __ Cmp(out, cls); |
| 3652 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3653 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3654 | GenerateReferenceLoadOneRegister(instruction, |
| 3655 | out_loc, |
| 3656 | super_offset, |
| 3657 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3658 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3659 | __ Cbnz(out, &loop); |
| 3660 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3661 | __ B(&done); |
| 3662 | __ Bind(&success); |
| 3663 | __ Mov(out, 1); |
| 3664 | if (zero.IsLinked()) { |
| 3665 | __ B(&done); |
| 3666 | } |
| 3667 | break; |
| 3668 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3669 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3670 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3671 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3672 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3673 | out_loc, |
| 3674 | obj_loc, |
| 3675 | class_offset, |
| 3676 | maybe_temp_loc, |
| 3677 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3678 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3679 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3680 | __ Cmp(out, cls); |
| 3681 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3682 | // 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] | 3683 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3684 | GenerateReferenceLoadOneRegister(instruction, |
| 3685 | out_loc, |
| 3686 | component_offset, |
| 3687 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3688 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3689 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3690 | __ Cbz(out, &done); |
| 3691 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3692 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3693 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3694 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3695 | __ Mov(out, 1); |
| 3696 | __ B(&done); |
| 3697 | break; |
| 3698 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3699 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3700 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3701 | // No read barrier since the slow path will retry upon failure. |
| 3702 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3703 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3704 | out_loc, |
| 3705 | obj_loc, |
| 3706 | class_offset, |
| 3707 | maybe_temp_loc, |
| 3708 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3709 | __ Cmp(out, cls); |
| 3710 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3711 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3712 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3713 | codegen_->AddSlowPath(slow_path); |
| 3714 | __ B(ne, slow_path->GetEntryLabel()); |
| 3715 | __ Mov(out, 1); |
| 3716 | if (zero.IsLinked()) { |
| 3717 | __ B(&done); |
| 3718 | } |
| 3719 | break; |
| 3720 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3721 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3722 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3723 | case TypeCheckKind::kInterfaceCheck: { |
| 3724 | // Note that we indeed only call on slow path, but we always go |
| 3725 | // into the slow path for the unresolved and interface check |
| 3726 | // cases. |
| 3727 | // |
| 3728 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3729 | // entry point without resorting to a type checking slow path |
| 3730 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3731 | // require to assign fixed registers for the inputs of this |
| 3732 | // HInstanceOf instruction (following the runtime calling |
| 3733 | // convention), which might be cluttered by the potential first |
| 3734 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3735 | // |
| 3736 | // TODO: Introduce a new runtime entry point taking the object |
| 3737 | // to test (instead of its class) as argument, and let it deal |
| 3738 | // with the read barrier issues. This will let us refactor this |
| 3739 | // case of the `switch` code as it was previously (with a direct |
| 3740 | // call to the runtime not using a type checking slow path). |
| 3741 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3742 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3743 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3744 | /* is_fatal */ false); |
| 3745 | codegen_->AddSlowPath(slow_path); |
| 3746 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3747 | if (zero.IsLinked()) { |
| 3748 | __ B(&done); |
| 3749 | } |
| 3750 | break; |
| 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | if (zero.IsLinked()) { |
| 3755 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3756 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | if (done.IsLinked()) { |
| 3760 | __ Bind(&done); |
| 3761 | } |
| 3762 | |
| 3763 | if (slow_path != nullptr) { |
| 3764 | __ Bind(slow_path->GetExitLabel()); |
| 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3769 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3770 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3771 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3772 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3773 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3774 | case TypeCheckKind::kExactCheck: |
| 3775 | case TypeCheckKind::kAbstractClassCheck: |
| 3776 | case TypeCheckKind::kClassHierarchyCheck: |
| 3777 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3778 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3779 | LocationSummary::kCallOnSlowPath : |
| 3780 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3783 | case TypeCheckKind::kUnresolvedCheck: |
| 3784 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3785 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3786 | break; |
| 3787 | } |
| 3788 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3789 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3790 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3791 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3792 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 3793 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3797 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3798 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3799 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3800 | Register obj = InputRegisterAt(instruction, 0); |
| 3801 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3802 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3803 | DCHECK_GE(num_temps, 1u); |
| 3804 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3805 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3806 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 3807 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3808 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3809 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3810 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3811 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3812 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3813 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3814 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3815 | const uint32_t object_array_data_offset = |
| 3816 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3817 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3818 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3819 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3820 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3821 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3822 | if (!kEmitCompilerReadBarrier) { |
| 3823 | is_type_check_slow_path_fatal = |
| 3824 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3825 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3826 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3827 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3828 | !instruction->CanThrowIntoCatchBlock(); |
| 3829 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3830 | SlowPathCodeARM64* type_check_slow_path = |
| 3831 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3832 | is_type_check_slow_path_fatal); |
| 3833 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3834 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3835 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3836 | // Avoid null check if we know obj is not null. |
| 3837 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3838 | __ Cbz(obj, &done); |
| 3839 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3840 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3841 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3842 | case TypeCheckKind::kExactCheck: |
| 3843 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3844 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3845 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3846 | temp_loc, |
| 3847 | obj_loc, |
| 3848 | class_offset, |
| 3849 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3850 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3851 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3852 | __ Cmp(temp, cls); |
| 3853 | // Jump to slow path for throwing the exception or doing a |
| 3854 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3855 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3856 | break; |
| 3857 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3858 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3859 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3860 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3861 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3862 | temp_loc, |
| 3863 | obj_loc, |
| 3864 | class_offset, |
| 3865 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3866 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3867 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3868 | // If the class is abstract, we eagerly fetch the super class of the |
| 3869 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3870 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3871 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3872 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3873 | GenerateReferenceLoadOneRegister(instruction, |
| 3874 | temp_loc, |
| 3875 | super_offset, |
| 3876 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3877 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3878 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3879 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3880 | // exception. |
| 3881 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3882 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3883 | __ Cmp(temp, cls); |
| 3884 | __ B(ne, &loop); |
| 3885 | break; |
| 3886 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3887 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3888 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3889 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3890 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3891 | temp_loc, |
| 3892 | obj_loc, |
| 3893 | class_offset, |
| 3894 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3895 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3896 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3897 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3898 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3899 | __ Bind(&loop); |
| 3900 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3901 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3902 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3903 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3904 | GenerateReferenceLoadOneRegister(instruction, |
| 3905 | temp_loc, |
| 3906 | super_offset, |
| 3907 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3908 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3909 | |
| 3910 | // If the class reference currently in `temp` is not null, jump |
| 3911 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3912 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3913 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3914 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3915 | break; |
| 3916 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3917 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3918 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3919 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3920 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3921 | temp_loc, |
| 3922 | obj_loc, |
| 3923 | class_offset, |
| 3924 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3925 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3926 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3927 | // Do an exact check. |
| 3928 | __ Cmp(temp, cls); |
| 3929 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3930 | |
| 3931 | // 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] | 3932 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3933 | GenerateReferenceLoadOneRegister(instruction, |
| 3934 | temp_loc, |
| 3935 | component_offset, |
| 3936 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3937 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3938 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3939 | // If the component type is null, jump to the slow path to throw the exception. |
| 3940 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3941 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 3942 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3943 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3944 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3945 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | break; |
| 3947 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3948 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3949 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3950 | // 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] | 3951 | // |
| 3952 | // We cannot directly call the CheckCast runtime entry point |
| 3953 | // without resorting to a type checking slow path here (i.e. by |
| 3954 | // calling InvokeRuntime directly), as it would require to |
| 3955 | // assign fixed registers for the inputs of this HInstanceOf |
| 3956 | // instruction (following the runtime calling convention), which |
| 3957 | // might be cluttered by the potential first read barrier |
| 3958 | // emission at the beginning of this method. |
| 3959 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3960 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3961 | case TypeCheckKind::kInterfaceCheck: { |
| 3962 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3963 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3964 | temp_loc, |
| 3965 | obj_loc, |
| 3966 | class_offset, |
| 3967 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3968 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3969 | |
| 3970 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 3971 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3972 | temp_loc, |
| 3973 | temp_loc, |
| 3974 | iftable_offset, |
| 3975 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3976 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3977 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3978 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3979 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3980 | vixl::aarch64::Label start_loop; |
| 3981 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 3982 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3983 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 3984 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3985 | // Go to next interface. |
| 3986 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 3987 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 3988 | // Compare the classes and continue the loop if they do not match. |
| 3989 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 3990 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3991 | break; |
| 3992 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3993 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3994 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3995 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3996 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3997 | } |
| 3998 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3999 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4000 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4001 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4002 | } |
| 4003 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4004 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4005 | // Will be generated at use site. |
| 4006 | } |
| 4007 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4008 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4009 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4010 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4011 | } |
| 4012 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4013 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4014 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4015 | } |
| 4016 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4017 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4018 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4019 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4020 | // the method_idx. |
| 4021 | HandleInvoke(invoke); |
| 4022 | } |
| 4023 | |
| 4024 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4025 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4026 | } |
| 4027 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4028 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4029 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4030 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4031 | } |
| 4032 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4033 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4034 | HandleInvoke(invoke); |
| 4035 | } |
| 4036 | |
| 4037 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4038 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4039 | LocationSummary* locations = invoke->GetLocations(); |
| 4040 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4041 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4042 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4043 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4044 | |
| 4045 | // The register ip1 is required to be used for the hidden argument in |
| 4046 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4047 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4048 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4049 | scratch_scope.Exclude(ip1); |
| 4050 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4051 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4052 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4053 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4054 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4055 | { |
| 4056 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4057 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4058 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4059 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4060 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4061 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4062 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4063 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4064 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4065 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4066 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4067 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4068 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4069 | // emit a read barrier for the previous class reference load. |
| 4070 | // However this is not required in practice, as this is an |
| 4071 | // intermediate/temporary reference and because the current |
| 4072 | // concurrent copying collector keeps the from-space memory |
| 4073 | // intact/accessible until the end of the marking phase (the |
| 4074 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4075 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4076 | __ Ldr(temp, |
| 4077 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4078 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4079 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4080 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4081 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4082 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4083 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4084 | |
| 4085 | { |
| 4086 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4087 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4088 | |
| 4089 | // lr(); |
| 4090 | __ blr(lr); |
| 4091 | DCHECK(!codegen_->IsLeafMethod()); |
| 4092 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4093 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | db7b44a | 2017-02-28 17:04:50 +0000 | [diff] [blame] | 4097 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4098 | if (intrinsic.TryDispatch(invoke)) { |
| 4099 | return; |
| 4100 | } |
| 4101 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4102 | HandleInvoke(invoke); |
| 4103 | } |
| 4104 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4105 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4106 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4107 | // art::PrepareForRegisterAllocation. |
| 4108 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4109 | |
Nicolas Geoffray | db7b44a | 2017-02-28 17:04:50 +0000 | [diff] [blame] | 4110 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4111 | if (intrinsic.TryDispatch(invoke)) { |
| 4112 | return; |
| 4113 | } |
| 4114 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4115 | HandleInvoke(invoke); |
| 4116 | } |
| 4117 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4118 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4119 | if (invoke->GetLocations()->Intrinsified()) { |
| 4120 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4121 | intrinsic.Dispatch(invoke); |
| 4122 | return true; |
| 4123 | } |
| 4124 | return false; |
| 4125 | } |
| 4126 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4127 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4128 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4129 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4130 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4131 | return desired_dispatch_info; |
| 4132 | } |
| 4133 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 4134 | Location CodeGeneratorARM64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4135 | Location temp) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4136 | // 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] | 4137 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4138 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4139 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4140 | uint32_t offset = |
| 4141 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4142 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4143 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4144 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4145 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4146 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4147 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4148 | break; |
| 4149 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4150 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4151 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4152 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4153 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4154 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4155 | const DexFile& dex_file = invoke->GetDexFileForPcRelativeDexCache(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4156 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4157 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4158 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4159 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4160 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4161 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4162 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4163 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4164 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4165 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4166 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4167 | Register reg = XRegisterFrom(temp); |
| 4168 | Register method_reg; |
| 4169 | if (current_method.IsRegister()) { |
| 4170 | method_reg = XRegisterFrom(current_method); |
| 4171 | } else { |
| 4172 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4173 | DCHECK(!current_method.IsValid()); |
| 4174 | method_reg = reg; |
| 4175 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 4176 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 4177 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4178 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4179 | __ Ldr(reg.X(), |
| 4180 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4181 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4182 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4183 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4184 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4185 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 4186 | break; |
| 4187 | } |
| 4188 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 4189 | return callee_method; |
| 4190 | } |
| 4191 | |
| 4192 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4193 | // All registers are assumed to be correctly set up. |
| 4194 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4195 | |
| 4196 | switch (invoke->GetCodePtrLocation()) { |
| 4197 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4198 | __ Bl(&frame_entry_label_); |
| 4199 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4200 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4201 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4202 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4203 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4204 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4205 | { |
| 4206 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4207 | // BLR must be the last instruction emitted in this function. |
| 4208 | // Recording the pc will occur right after returning from this function. |
| 4209 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4210 | kInstructionSize, |
| 4211 | CodeBufferCheckScope::kExactSize); |
| 4212 | // lr() |
| 4213 | __ blr(lr); |
| 4214 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4215 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4216 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4217 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4218 | DCHECK(!IsLeafMethod()); |
| 4219 | } |
| 4220 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4221 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4222 | // Use the calling convention instead of the location of the receiver, as |
| 4223 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4224 | // slow path, the arguments have been moved to the right place, so here we are |
| 4225 | // guaranteed that the receiver is the first register of the calling convention. |
| 4226 | InvokeDexCallingConvention calling_convention; |
| 4227 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4228 | Register temp = XRegisterFrom(temp_in); |
| 4229 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4230 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4231 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4232 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4233 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4234 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4235 | |
| 4236 | { |
| 4237 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4238 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4239 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4240 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4241 | MaybeRecordImplicitNullCheck(invoke); |
| 4242 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4243 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4244 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4245 | // intermediate/temporary reference and because the current |
| 4246 | // concurrent copying collector keeps the from-space memory |
| 4247 | // intact/accessible until the end of the marking phase (the |
| 4248 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4249 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4250 | // temp = temp->GetMethodAt(method_offset); |
| 4251 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4252 | // lr = temp->GetEntryPoint(); |
| 4253 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4254 | { |
| 4255 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4256 | // BLR should be the last instruction emitted in this function. |
| 4257 | // Recording the pc will occur right after returning from this function. |
| 4258 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4259 | // lr(); |
| 4260 | __ blr(lr); |
| 4261 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4264 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4265 | HandleInvoke(invoke); |
| 4266 | } |
| 4267 | |
| 4268 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4269 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4270 | } |
| 4271 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4272 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4273 | const DexFile& dex_file, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4274 | dex::StringIndex string_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4275 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4276 | return |
| 4277 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4280 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4281 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4282 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4283 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4284 | 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] | 4285 | } |
| 4286 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4287 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4288 | const DexFile& dex_file, |
| 4289 | dex::TypeIndex type_index, |
| 4290 | vixl::aarch64::Label* adrp_label) { |
| 4291 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4292 | } |
| 4293 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4294 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4295 | const DexFile& dex_file, |
| 4296 | uint32_t element_offset, |
| 4297 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4298 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4299 | } |
| 4300 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4301 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4302 | const DexFile& dex_file, |
| 4303 | uint32_t offset_or_index, |
| 4304 | vixl::aarch64::Label* adrp_label, |
| 4305 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4306 | // Add a patch entry and return the label. |
| 4307 | patches->emplace_back(dex_file, offset_or_index); |
| 4308 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4309 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4310 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4311 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4312 | return label; |
| 4313 | } |
| 4314 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4315 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4316 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4317 | return boot_image_string_patches_.GetOrCreate( |
| 4318 | StringReference(&dex_file, string_index), |
| 4319 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4320 | } |
| 4321 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4322 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4323 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4324 | return boot_image_type_patches_.GetOrCreate( |
| 4325 | TypeReference(&dex_file, type_index), |
| 4326 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4327 | } |
| 4328 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4329 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4330 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4331 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 4332 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 4333 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 4334 | } |
| 4335 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4336 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4337 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4338 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4339 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4340 | return jit_string_patches_.GetOrCreate( |
| 4341 | StringReference(&dex_file, string_index), |
| 4342 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4343 | } |
| 4344 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4345 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4346 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4347 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4348 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4349 | return jit_class_patches_.GetOrCreate( |
| 4350 | TypeReference(&dex_file, type_index), |
| 4351 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4352 | } |
| 4353 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4354 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4355 | vixl::aarch64::Register reg) { |
| 4356 | DCHECK(reg.IsX()); |
| 4357 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4358 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4359 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4363 | vixl::aarch64::Register out, |
| 4364 | vixl::aarch64::Register base) { |
| 4365 | DCHECK(out.IsX()); |
| 4366 | DCHECK(base.IsX()); |
| 4367 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4368 | __ Bind(fixup_label); |
| 4369 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4370 | } |
| 4371 | |
| 4372 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4373 | vixl::aarch64::Register out, |
| 4374 | vixl::aarch64::Register base) { |
| 4375 | DCHECK(base.IsX()); |
| 4376 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4377 | __ Bind(fixup_label); |
| 4378 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4379 | } |
| 4380 | |
| 4381 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4382 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4383 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4384 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4385 | for (const PcRelativePatchInfo& info : infos) { |
| 4386 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4387 | &info.target_dex_file, |
| 4388 | info.pc_insn_label->GetLocation(), |
| 4389 | info.offset_or_index)); |
| 4390 | } |
| 4391 | } |
| 4392 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4393 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4394 | DCHECK(linker_patches->empty()); |
| 4395 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4396 | pc_relative_dex_cache_patches_.size() + |
| 4397 | boot_image_string_patches_.size() + |
| 4398 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4399 | boot_image_type_patches_.size() + |
| 4400 | pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4401 | type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4402 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4403 | linker_patches->reserve(size); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4404 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4405 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4406 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4407 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4408 | info.offset_or_index)); |
| 4409 | } |
| 4410 | for (const auto& entry : boot_image_string_patches_) { |
| 4411 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4412 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4413 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4414 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4415 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4416 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4417 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4418 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4419 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4420 | linker_patches); |
| 4421 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4422 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4423 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4424 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4425 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4426 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4427 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4428 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4429 | for (const auto& entry : boot_image_type_patches_) { |
| 4430 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4431 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4432 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4433 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4434 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4435 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4436 | for (const auto& entry : boot_image_address_patches_) { |
| 4437 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4438 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4439 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4440 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4441 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4444 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4445 | Uint32ToLiteralMap* map) { |
| 4446 | return map->GetOrCreate( |
| 4447 | value, |
| 4448 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4449 | } |
| 4450 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4451 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4452 | return uint64_literals_.GetOrCreate( |
| 4453 | value, |
| 4454 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4455 | } |
| 4456 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4457 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4458 | MethodReference target_method, |
| 4459 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4460 | return map->GetOrCreate( |
| 4461 | target_method, |
| 4462 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4463 | } |
| 4464 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4465 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4466 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4467 | // art::PrepareForRegisterAllocation. |
| 4468 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4469 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4470 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4471 | return; |
| 4472 | } |
| 4473 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4474 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4475 | // are no pools emitted. |
| 4476 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4477 | LocationSummary* locations = invoke->GetLocations(); |
| 4478 | codegen_->GenerateStaticOrDirectCall( |
| 4479 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4480 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4484 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4485 | return; |
| 4486 | } |
| 4487 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4488 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4489 | // are no pools emitted. |
| 4490 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4491 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4492 | DCHECK(!codegen_->IsLeafMethod()); |
| 4493 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4494 | } |
| 4495 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4496 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4497 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4498 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4499 | case HLoadClass::LoadKind::kInvalid: |
| 4500 | LOG(FATAL) << "UNREACHABLE"; |
| 4501 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4502 | case HLoadClass::LoadKind::kReferrersClass: |
| 4503 | break; |
| 4504 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4505 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4506 | break; |
| 4507 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4508 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4509 | break; |
| 4510 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4511 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4512 | case HLoadClass::LoadKind::kBssEntry: |
| 4513 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4514 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4515 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4516 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4517 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4518 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4519 | break; |
| 4520 | } |
| 4521 | return desired_class_load_kind; |
| 4522 | } |
| 4523 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4524 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4525 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4526 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4527 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4528 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4529 | cls, |
| 4530 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4531 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4532 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4533 | return; |
| 4534 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4535 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4536 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4537 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4538 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4539 | ? LocationSummary::kCallOnSlowPath |
| 4540 | : LocationSummary::kNoCall; |
| 4541 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4542 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4543 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4544 | } |
| 4545 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4546 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4548 | } |
| 4549 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4550 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4551 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4552 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 4553 | // Note that IP0 may be clobbered by saving/restoring the live register (only one thanks |
| 4554 | // to the custom calling convention) or by marking, so we shall use IP1. |
| 4555 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4556 | InvokeRuntimeCallingConvention calling_convention; |
| 4557 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4558 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4559 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4560 | Primitive::kPrimNot).GetCode()); |
| 4561 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4562 | } else { |
| 4563 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4564 | } |
| 4565 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4566 | } |
| 4567 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4568 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4569 | // move. |
| 4570 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4571 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4572 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4573 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4574 | return; |
| 4575 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4576 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4577 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4578 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4579 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4580 | Register bss_entry_temp; |
| 4581 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4582 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4583 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4584 | ? kWithoutReadBarrier |
| 4585 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4586 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4587 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4588 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4589 | DCHECK(!cls->CanCallRuntime()); |
| 4590 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4591 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4592 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4593 | GenerateGcRootFieldLoad(cls, |
| 4594 | out_loc, |
| 4595 | current_method, |
| 4596 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4597 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4598 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4599 | break; |
| 4600 | } |
| 4601 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4602 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4603 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4604 | cls->GetTypeIndex())); |
| 4605 | break; |
| 4606 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4607 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4608 | // Add ADRP with its PC-relative type patch. |
| 4609 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4610 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4611 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4612 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4613 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4614 | vixl::aarch64::Label* add_label = |
| 4615 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4616 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4617 | break; |
| 4618 | } |
| 4619 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4620 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4621 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4622 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4623 | DCHECK_NE(address, 0u); |
| 4624 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4625 | break; |
| 4626 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4627 | case HLoadClass::LoadKind::kBssEntry: { |
| 4628 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4629 | const DexFile& dex_file = cls->GetDexFile(); |
| 4630 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4631 | // We can go to slow path even with non-zero reference and in that case marking |
| 4632 | // can clobber IP0, so we need to use IP1 which shall be preserved. |
| 4633 | bss_entry_temp = ip1; |
| 4634 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4635 | temps.Exclude(bss_entry_temp); |
| 4636 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4637 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4638 | // Add LDR with its PC-relative Class patch. |
| 4639 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4640 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4641 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4642 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4643 | out_loc, |
| 4644 | bss_entry_temp, |
| 4645 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4646 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4647 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4648 | generate_null_check = true; |
| 4649 | break; |
| 4650 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4651 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4652 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4653 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4654 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4655 | GenerateGcRootFieldLoad(cls, |
| 4656 | out_loc, |
| 4657 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4658 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4659 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4660 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4661 | break; |
| 4662 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4663 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4664 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4665 | LOG(FATAL) << "UNREACHABLE"; |
| 4666 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4667 | } |
| 4668 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4669 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4670 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4671 | DCHECK(cls->CanCallRuntime()); |
| 4672 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4673 | 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] | 4674 | codegen_->AddSlowPath(slow_path); |
| 4675 | if (generate_null_check) { |
| 4676 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4677 | } |
| 4678 | if (cls->MustGenerateClinitCheck()) { |
| 4679 | GenerateClassInitializationCheck(slow_path, out); |
| 4680 | } else { |
| 4681 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | } |
| 4685 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4686 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4687 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4688 | } |
| 4689 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4690 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4691 | LocationSummary* locations = |
| 4692 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4693 | locations->SetOut(Location::RequiresRegister()); |
| 4694 | } |
| 4695 | |
| 4696 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4697 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4698 | } |
| 4699 | |
| 4700 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4701 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4702 | } |
| 4703 | |
| 4704 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4705 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4708 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4709 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4710 | switch (desired_string_load_kind) { |
| 4711 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4712 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4713 | break; |
| 4714 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4715 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4716 | break; |
| 4717 | case HLoadString::LoadKind::kBootImageAddress: |
| 4718 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4719 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4720 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4721 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4722 | case HLoadString::LoadKind::kJitTableAddress: |
| 4723 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4724 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4725 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4726 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4727 | } |
| 4728 | return desired_string_load_kind; |
| 4729 | } |
| 4730 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4731 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4732 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4733 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4734 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4735 | InvokeRuntimeCallingConvention calling_convention; |
| 4736 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4737 | } else { |
| 4738 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4739 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4740 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4741 | // Rely on the pResolveString and marking to save everything we need. |
| 4742 | // Note that IP0 may be clobbered by saving/restoring the live register (only one thanks |
| 4743 | // 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] | 4744 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4745 | InvokeRuntimeCallingConvention calling_convention; |
| 4746 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4747 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4748 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4749 | Primitive::kPrimNot).GetCode()); |
| 4750 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4751 | } else { |
| 4752 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4753 | } |
| 4754 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4755 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4758 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4759 | // move. |
| 4760 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4761 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4762 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4763 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4764 | switch (load->GetLoadKind()) { |
| 4765 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4766 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4767 | load->GetStringIndex())); |
| 4768 | return; // No dex cache slow path. |
| 4769 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4770 | // Add ADRP with its PC-relative String patch. |
| 4771 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4772 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4773 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4774 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4775 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4776 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4777 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4778 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4779 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4780 | return; // No dex cache slow path. |
| 4781 | } |
| 4782 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4783 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4784 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 4785 | DCHECK_NE(address, 0u); |
| 4786 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4787 | return; // No dex cache slow path. |
| 4788 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4789 | case HLoadString::LoadKind::kBssEntry: { |
| 4790 | // Add ADRP with its PC-relative String .bss entry patch. |
| 4791 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4792 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4793 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4794 | // We could use IP0 as the marking shall not clobber IP0 if the reference is null and |
| 4795 | // that's when we need the slow path. But let's not rely on such details and use IP1. |
| 4796 | Register temp = ip1; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4797 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4798 | temps.Exclude(temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4799 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4800 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4801 | // Add LDR with its PC-relative String patch. |
| 4802 | vixl::aarch64::Label* ldr_label = |
| 4803 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4804 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4805 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4806 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4807 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4808 | /* offset placeholder */ 0u, |
| 4809 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4810 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4811 | SlowPathCodeARM64* slow_path = |
| 4812 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4813 | codegen_->AddSlowPath(slow_path); |
| 4814 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 4815 | __ Bind(slow_path->GetExitLabel()); |
| 4816 | return; |
| 4817 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4818 | case HLoadString::LoadKind::kJitTableAddress: { |
| 4819 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4820 | load->GetStringIndex(), |
| 4821 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4822 | GenerateGcRootFieldLoad(load, |
| 4823 | out_loc, |
| 4824 | out.X(), |
| 4825 | /* offset */ 0, |
| 4826 | /* fixup_label */ nullptr, |
| 4827 | kCompilerReadBarrierOption); |
| 4828 | return; |
| 4829 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4830 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4831 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4832 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4833 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4834 | // 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] | 4835 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4836 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4837 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4838 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 4839 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4840 | } |
| 4841 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4842 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4843 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4844 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4845 | } |
| 4846 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4847 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4848 | // Will be generated at use site. |
| 4849 | } |
| 4850 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4851 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4852 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4853 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4854 | InvokeRuntimeCallingConvention calling_convention; |
| 4855 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4856 | } |
| 4857 | |
| 4858 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4859 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4860 | instruction, |
| 4861 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4862 | if (instruction->IsEnter()) { |
| 4863 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4864 | } else { |
| 4865 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4866 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4869 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4870 | LocationSummary* locations = |
| 4871 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4872 | switch (mul->GetResultType()) { |
| 4873 | case Primitive::kPrimInt: |
| 4874 | case Primitive::kPrimLong: |
| 4875 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4876 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4877 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4878 | break; |
| 4879 | |
| 4880 | case Primitive::kPrimFloat: |
| 4881 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4882 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4883 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4884 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4885 | break; |
| 4886 | |
| 4887 | default: |
| 4888 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4889 | } |
| 4890 | } |
| 4891 | |
| 4892 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4893 | switch (mul->GetResultType()) { |
| 4894 | case Primitive::kPrimInt: |
| 4895 | case Primitive::kPrimLong: |
| 4896 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4897 | break; |
| 4898 | |
| 4899 | case Primitive::kPrimFloat: |
| 4900 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4901 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4902 | break; |
| 4903 | |
| 4904 | default: |
| 4905 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4906 | } |
| 4907 | } |
| 4908 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4909 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4910 | LocationSummary* locations = |
| 4911 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4912 | switch (neg->GetResultType()) { |
| 4913 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4914 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4915 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4916 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4917 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4918 | |
| 4919 | case Primitive::kPrimFloat: |
| 4920 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4921 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4922 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4923 | break; |
| 4924 | |
| 4925 | default: |
| 4926 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4931 | switch (neg->GetResultType()) { |
| 4932 | case Primitive::kPrimInt: |
| 4933 | case Primitive::kPrimLong: |
| 4934 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4935 | break; |
| 4936 | |
| 4937 | case Primitive::kPrimFloat: |
| 4938 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4939 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4940 | break; |
| 4941 | |
| 4942 | default: |
| 4943 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4948 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4949 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4950 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4951 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4952 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4953 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4957 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4958 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4959 | QuickEntrypointEnum entrypoint = |
| 4960 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4961 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4962 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4965 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4966 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4967 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4968 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4969 | if (instruction->IsStringAlloc()) { |
| 4970 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4971 | } else { |
| 4972 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4973 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4974 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4975 | } |
| 4976 | |
| 4977 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4978 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4979 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4980 | if (instruction->IsStringAlloc()) { |
| 4981 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4982 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4983 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4984 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4985 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4986 | |
| 4987 | { |
| 4988 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4989 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4990 | kInstructionSize, |
| 4991 | CodeBufferCheckScope::kExactSize); |
| 4992 | __ blr(lr); |
| 4993 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4994 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4995 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4996 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4997 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4998 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5002 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5003 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5004 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5008 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5009 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5010 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5011 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5012 | break; |
| 5013 | |
| 5014 | default: |
| 5015 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5016 | } |
| 5017 | } |
| 5018 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5019 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5020 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5021 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5022 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5023 | } |
| 5024 | |
| 5025 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5026 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5027 | } |
| 5028 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5029 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5030 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5031 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5032 | } |
| 5033 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5034 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5035 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5036 | return; |
| 5037 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5038 | { |
| 5039 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5040 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5041 | Location obj = instruction->GetLocations()->InAt(0); |
| 5042 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5043 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5044 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5047 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5048 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5049 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5050 | |
| 5051 | LocationSummary* locations = instruction->GetLocations(); |
| 5052 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5053 | |
| 5054 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5055 | } |
| 5056 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5057 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5058 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5061 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5062 | HandleBinaryOp(instruction); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5066 | HandleBinaryOp(instruction); |
| 5067 | } |
| 5068 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5069 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5070 | LOG(FATAL) << "Unreachable"; |
| 5071 | } |
| 5072 | |
| 5073 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5074 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5075 | } |
| 5076 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5077 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5078 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5079 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5080 | if (location.IsStackSlot()) { |
| 5081 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5082 | } else if (location.IsDoubleStackSlot()) { |
| 5083 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5084 | } |
| 5085 | locations->SetOut(location); |
| 5086 | } |
| 5087 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5088 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5089 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5090 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5094 | LocationSummary* locations = |
| 5095 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5096 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5100 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5101 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5105 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5106 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5107 | locations->SetInAt(i, Location::Any()); |
| 5108 | } |
| 5109 | locations->SetOut(Location::Any()); |
| 5110 | } |
| 5111 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5112 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5113 | LOG(FATAL) << "Unreachable"; |
| 5114 | } |
| 5115 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5116 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5117 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5118 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5119 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5120 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5121 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5122 | |
| 5123 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5124 | case Primitive::kPrimInt: |
| 5125 | case Primitive::kPrimLong: |
| 5126 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5127 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5128 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5129 | break; |
| 5130 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5131 | case Primitive::kPrimFloat: |
| 5132 | case Primitive::kPrimDouble: { |
| 5133 | InvokeRuntimeCallingConvention calling_convention; |
| 5134 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5135 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5136 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5137 | |
| 5138 | break; |
| 5139 | } |
| 5140 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5141 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5142 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5143 | } |
| 5144 | } |
| 5145 | |
| 5146 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5147 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5148 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5149 | switch (type) { |
| 5150 | case Primitive::kPrimInt: |
| 5151 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5152 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5153 | break; |
| 5154 | } |
| 5155 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5156 | case Primitive::kPrimFloat: |
| 5157 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5158 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5159 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5160 | if (type == Primitive::kPrimFloat) { |
| 5161 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5162 | } else { |
| 5163 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5164 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5165 | break; |
| 5166 | } |
| 5167 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5168 | default: |
| 5169 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5170 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5171 | } |
| 5172 | } |
| 5173 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5174 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5175 | memory_barrier->SetLocations(nullptr); |
| 5176 | } |
| 5177 | |
| 5178 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5179 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5180 | } |
| 5181 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5182 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5183 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5184 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5185 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5186 | } |
| 5187 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5188 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5189 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5193 | instruction->SetLocations(nullptr); |
| 5194 | } |
| 5195 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5196 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5197 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5200 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5201 | HandleBinaryOp(ror); |
| 5202 | } |
| 5203 | |
| 5204 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5205 | HandleBinaryOp(ror); |
| 5206 | } |
| 5207 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5208 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5209 | HandleShift(shl); |
| 5210 | } |
| 5211 | |
| 5212 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5213 | HandleShift(shl); |
| 5214 | } |
| 5215 | |
| 5216 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5217 | HandleShift(shr); |
| 5218 | } |
| 5219 | |
| 5220 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5221 | HandleShift(shr); |
| 5222 | } |
| 5223 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5224 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5225 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5229 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5230 | } |
| 5231 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5232 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5233 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5237 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
| 5240 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5241 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5242 | } |
| 5243 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5244 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5245 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5246 | } |
| 5247 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5248 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5249 | HUnresolvedInstanceFieldGet* instruction) { |
| 5250 | FieldAccessCallingConventionARM64 calling_convention; |
| 5251 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5252 | instruction, instruction->GetFieldType(), calling_convention); |
| 5253 | } |
| 5254 | |
| 5255 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5256 | HUnresolvedInstanceFieldGet* instruction) { |
| 5257 | FieldAccessCallingConventionARM64 calling_convention; |
| 5258 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5259 | instruction->GetFieldType(), |
| 5260 | instruction->GetFieldIndex(), |
| 5261 | instruction->GetDexPc(), |
| 5262 | calling_convention); |
| 5263 | } |
| 5264 | |
| 5265 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5266 | HUnresolvedInstanceFieldSet* instruction) { |
| 5267 | FieldAccessCallingConventionARM64 calling_convention; |
| 5268 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5269 | instruction, instruction->GetFieldType(), calling_convention); |
| 5270 | } |
| 5271 | |
| 5272 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5273 | HUnresolvedInstanceFieldSet* instruction) { |
| 5274 | FieldAccessCallingConventionARM64 calling_convention; |
| 5275 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5276 | instruction->GetFieldType(), |
| 5277 | instruction->GetFieldIndex(), |
| 5278 | instruction->GetDexPc(), |
| 5279 | calling_convention); |
| 5280 | } |
| 5281 | |
| 5282 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5283 | HUnresolvedStaticFieldGet* instruction) { |
| 5284 | FieldAccessCallingConventionARM64 calling_convention; |
| 5285 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5286 | instruction, instruction->GetFieldType(), calling_convention); |
| 5287 | } |
| 5288 | |
| 5289 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5290 | HUnresolvedStaticFieldGet* instruction) { |
| 5291 | FieldAccessCallingConventionARM64 calling_convention; |
| 5292 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5293 | instruction->GetFieldType(), |
| 5294 | instruction->GetFieldIndex(), |
| 5295 | instruction->GetDexPc(), |
| 5296 | calling_convention); |
| 5297 | } |
| 5298 | |
| 5299 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5300 | HUnresolvedStaticFieldSet* instruction) { |
| 5301 | FieldAccessCallingConventionARM64 calling_convention; |
| 5302 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5303 | instruction, instruction->GetFieldType(), calling_convention); |
| 5304 | } |
| 5305 | |
| 5306 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5307 | HUnresolvedStaticFieldSet* instruction) { |
| 5308 | FieldAccessCallingConventionARM64 calling_convention; |
| 5309 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5310 | instruction->GetFieldType(), |
| 5311 | instruction->GetFieldIndex(), |
| 5312 | instruction->GetDexPc(), |
| 5313 | calling_convention); |
| 5314 | } |
| 5315 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5316 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5317 | LocationSummary* locations = |
| 5318 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5319 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5323 | HBasicBlock* block = instruction->GetBlock(); |
| 5324 | if (block->GetLoopInformation() != nullptr) { |
| 5325 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5326 | // The back edge will generate the suspend check. |
| 5327 | return; |
| 5328 | } |
| 5329 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5330 | // The goto will generate the suspend check. |
| 5331 | return; |
| 5332 | } |
| 5333 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5334 | } |
| 5335 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5336 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5337 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5338 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5339 | InvokeRuntimeCallingConvention calling_convention; |
| 5340 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5341 | } |
| 5342 | |
| 5343 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5344 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5345 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5349 | LocationSummary* locations = |
| 5350 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5351 | Primitive::Type input_type = conversion->GetInputType(); |
| 5352 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5353 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5354 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5355 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5356 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5357 | } |
| 5358 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5359 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5361 | } else { |
| 5362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5363 | } |
| 5364 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5365 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5366 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5367 | } else { |
| 5368 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5369 | } |
| 5370 | } |
| 5371 | |
| 5372 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5373 | Primitive::Type result_type = conversion->GetResultType(); |
| 5374 | Primitive::Type input_type = conversion->GetInputType(); |
| 5375 | |
| 5376 | DCHECK_NE(input_type, result_type); |
| 5377 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5378 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5379 | int result_size = Primitive::ComponentSize(result_type); |
| 5380 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5381 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5382 | Register output = OutputRegister(conversion); |
| 5383 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5384 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5385 | // 'int' values are used directly as W registers, discarding the top |
| 5386 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5387 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5388 | // top 32 bits of the target register. We theoretically could leave those |
| 5389 | // bits unchanged, but we would have to make sure that no code uses a |
| 5390 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5391 | // zero. |
| 5392 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5393 | } else if (result_type == Primitive::kPrimChar || |
| 5394 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5395 | __ Ubfx(output, |
| 5396 | output.IsX() ? source.X() : source.W(), |
| 5397 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5398 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5399 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5400 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5401 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5402 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5403 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5404 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5405 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5406 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5407 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5408 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5409 | } else { |
| 5410 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5411 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5412 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5413 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5414 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5415 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5416 | HandleShift(ushr); |
| 5417 | } |
| 5418 | |
| 5419 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5420 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5424 | HandleBinaryOp(instruction); |
| 5425 | } |
| 5426 | |
| 5427 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5428 | HandleBinaryOp(instruction); |
| 5429 | } |
| 5430 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5431 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5432 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5433 | LOG(FATAL) << "Unreachable"; |
| 5434 | } |
| 5435 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5436 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5437 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5438 | LOG(FATAL) << "Unreachable"; |
| 5439 | } |
| 5440 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5441 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5442 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5443 | LocationSummary* locations = |
| 5444 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5445 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5449 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5450 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5451 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5452 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5453 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5454 | // 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] | 5455 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5456 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5457 | // make sure we don't emit it if the target may run out of range. |
| 5458 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5459 | // ranges and emit the tables only as required. |
| 5460 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5461 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5462 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5463 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5464 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5465 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5466 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5467 | Register temp = temps.AcquireW(); |
| 5468 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5469 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5470 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5471 | // Jump to successors[0] if value == lower_bound. |
| 5472 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5473 | int32_t last_index = 0; |
| 5474 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5475 | __ Subs(temp, temp, Operand(2)); |
| 5476 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5477 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5478 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5479 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5480 | } |
| 5481 | if (num_entries - last_index == 2) { |
| 5482 | // The last missing case_value. |
| 5483 | __ Cmp(temp, Operand(1)); |
| 5484 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | // And the default for any other value. |
| 5488 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5489 | __ B(codegen_->GetLabelOf(default_block)); |
| 5490 | } |
| 5491 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5492 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5493 | |
| 5494 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5495 | |
| 5496 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5497 | // registers, we are free to block one. |
| 5498 | Register temp_w = temps.AcquireW(); |
| 5499 | Register index; |
| 5500 | // Remove the bias. |
| 5501 | if (lower_bound != 0) { |
| 5502 | index = temp_w; |
| 5503 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5504 | } else { |
| 5505 | index = value_reg; |
| 5506 | } |
| 5507 | |
| 5508 | // Jump to default block if index is out of the range. |
| 5509 | __ Cmp(index, Operand(num_entries)); |
| 5510 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5511 | |
| 5512 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5513 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5514 | // register pressure. |
| 5515 | Register table_base = temps.AcquireX(); |
| 5516 | // Load jump offset from the table. |
| 5517 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5518 | Register jump_offset = temp_w; |
| 5519 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5520 | |
| 5521 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5522 | Register target_address = table_base; |
| 5523 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5524 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5525 | } |
| 5526 | } |
| 5527 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5528 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5529 | HInstruction* instruction, |
| 5530 | Location out, |
| 5531 | uint32_t offset, |
| 5532 | Location maybe_temp, |
| 5533 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5534 | Primitive::Type type = Primitive::kPrimNot; |
| 5535 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5536 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5537 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5538 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5539 | if (kUseBakerReadBarrier) { |
| 5540 | // Load with fast path based Baker's read barrier. |
| 5541 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5542 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5543 | out, |
| 5544 | out_reg, |
| 5545 | offset, |
| 5546 | temp_reg, |
| 5547 | /* needs_null_check */ false, |
| 5548 | /* use_load_acquire */ false); |
| 5549 | } else { |
| 5550 | // Load with slow path based read barrier. |
| 5551 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5552 | // in the following move operation, as we will need it for the |
| 5553 | // read barrier below. |
| 5554 | __ Mov(temp_reg, out_reg); |
| 5555 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5556 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5557 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5558 | } |
| 5559 | } else { |
| 5560 | // Plain load with no read barrier. |
| 5561 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5562 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5563 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5564 | } |
| 5565 | } |
| 5566 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5567 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5568 | HInstruction* instruction, |
| 5569 | Location out, |
| 5570 | Location obj, |
| 5571 | uint32_t offset, |
| 5572 | Location maybe_temp, |
| 5573 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5574 | Primitive::Type type = Primitive::kPrimNot; |
| 5575 | Register out_reg = RegisterFrom(out, type); |
| 5576 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5577 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5578 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5579 | if (kUseBakerReadBarrier) { |
| 5580 | // Load with fast path based Baker's read barrier. |
| 5581 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5582 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5583 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5584 | out, |
| 5585 | obj_reg, |
| 5586 | offset, |
| 5587 | temp_reg, |
| 5588 | /* needs_null_check */ false, |
| 5589 | /* use_load_acquire */ false); |
| 5590 | } else { |
| 5591 | // Load with slow path based read barrier. |
| 5592 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5593 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5594 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5595 | } |
| 5596 | } else { |
| 5597 | // Plain load with no read barrier. |
| 5598 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5599 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5600 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5601 | } |
| 5602 | } |
| 5603 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5604 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5605 | HInstruction* instruction, |
| 5606 | Location root, |
| 5607 | Register obj, |
| 5608 | uint32_t offset, |
| 5609 | vixl::aarch64::Label* fixup_label, |
| 5610 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5611 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5612 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5613 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5614 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5615 | if (kUseBakerReadBarrier) { |
| 5616 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5617 | // Baker's read barrier are used: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5618 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5619 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5620 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5621 | // if (temp != null) { |
| 5622 | // root = temp(root) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5623 | // } |
| 5624 | |
| 5625 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5626 | if (fixup_label == nullptr) { |
| 5627 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5628 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5629 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5630 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5631 | static_assert( |
| 5632 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5633 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5634 | "have different sizes."); |
| 5635 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5636 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5637 | "have different sizes."); |
| 5638 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5639 | Register temp = lr; |
| 5640 | |
| 5641 | // Slow path marking the GC root `root`. The entrypoint will alrady be loaded in temp. |
| 5642 | SlowPathCodeARM64* slow_path = |
| 5643 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, |
| 5644 | root, |
| 5645 | LocationFrom(temp)); |
| 5646 | codegen_->AddSlowPath(slow_path); |
| 5647 | const int32_t entry_point_offset = |
| 5648 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 5649 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5650 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5651 | // threads are suspended or running a checkpoint. |
| 5652 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5653 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 5654 | // checking GetIsGcMarking. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5655 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5656 | __ Bind(slow_path->GetExitLabel()); |
| 5657 | } else { |
| 5658 | // GC root loaded through a slow path for read barriers other |
| 5659 | // than Baker's. |
| 5660 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5661 | if (fixup_label == nullptr) { |
| 5662 | __ Add(root_reg.X(), obj.X(), offset); |
| 5663 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5664 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5665 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5666 | // /* mirror::Object* */ root = root->Read() |
| 5667 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5668 | } |
| 5669 | } else { |
| 5670 | // Plain GC root load with no read barrier. |
| 5671 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5672 | if (fixup_label == nullptr) { |
| 5673 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5674 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5675 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5676 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5677 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5678 | // do not have to unpoison `root_reg` here. |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5683 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5684 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5685 | uint32_t offset, |
| 5686 | Register temp, |
| 5687 | bool needs_null_check, |
| 5688 | bool use_load_acquire) { |
| 5689 | DCHECK(kEmitCompilerReadBarrier); |
| 5690 | DCHECK(kUseBakerReadBarrier); |
| 5691 | |
| 5692 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5693 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5694 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5695 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5696 | ref, |
| 5697 | obj, |
| 5698 | offset, |
| 5699 | no_index, |
| 5700 | no_scale_factor, |
| 5701 | temp, |
| 5702 | needs_null_check, |
| 5703 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5707 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5708 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5709 | uint32_t data_offset, |
| 5710 | Location index, |
| 5711 | Register temp, |
| 5712 | bool needs_null_check) { |
| 5713 | DCHECK(kEmitCompilerReadBarrier); |
| 5714 | DCHECK(kUseBakerReadBarrier); |
| 5715 | |
| 5716 | // Array cells are never volatile variables, therefore array loads |
| 5717 | // never use Load-Acquire instructions on ARM64. |
| 5718 | const bool use_load_acquire = false; |
| 5719 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5720 | static_assert( |
| 5721 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5722 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5723 | // /* HeapReference<Object> */ ref = |
| 5724 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5725 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5726 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5727 | ref, |
| 5728 | obj, |
| 5729 | data_offset, |
| 5730 | index, |
| 5731 | scale_factor, |
| 5732 | temp, |
| 5733 | needs_null_check, |
| 5734 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5738 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5739 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5740 | uint32_t offset, |
| 5741 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5742 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5743 | Register temp, |
| 5744 | bool needs_null_check, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5745 | bool use_load_acquire, |
| 5746 | bool always_update_field) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5747 | DCHECK(kEmitCompilerReadBarrier); |
| 5748 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5749 | // If we are emitting an array load, we should not be using a |
| 5750 | // Load Acquire instruction. In other words: |
| 5751 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5752 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5753 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5754 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5755 | UseScratchRegisterScope temps(masm); |
| 5756 | |
| 5757 | // In slow path based read barriers, the read barrier call is |
| 5758 | // inserted after the original load. However, in fast path based |
| 5759 | // Baker's read barriers, we need to perform the load of |
| 5760 | // mirror::Object::monitor_ *before* the original reference load. |
| 5761 | // This load-load ordering is required by the read barrier. |
| 5762 | // The fast path/slow path (for Baker's algorithm) should look like: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5763 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5764 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5765 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5766 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5767 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5768 | // if (is_gray) { |
| 5769 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5770 | // } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5771 | // |
| 5772 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5773 | // slightly more complex as it performs additional checks that we do |
| 5774 | // not do here for performance reasons. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5775 | |
| 5776 | Primitive::Type type = Primitive::kPrimNot; |
| 5777 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5778 | DCHECK(obj.IsW()); |
| 5779 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5780 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5781 | { |
| 5782 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5783 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5784 | // /* int32_t */ monitor = obj->monitor_ |
| 5785 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5786 | if (needs_null_check) { |
| 5787 | MaybeRecordImplicitNullCheck(instruction); |
| 5788 | } |
| 5789 | } |
| 5790 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5791 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5792 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5793 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5794 | // Introduce a dependency on the lock_word including rb_state, |
| 5795 | // to prevent load-load reordering, and without using |
| 5796 | // a memory barrier (which would be more expensive). |
| 5797 | // `obj` is unchanged by this operation, but its value now depends |
| 5798 | // on `temp`. |
| 5799 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
| 5800 | |
| 5801 | // The actual reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5802 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5803 | // Load types involving an "index": ArrayGet, |
| 5804 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5805 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5806 | if (use_load_acquire) { |
| 5807 | // UnsafeGetObjectVolatile intrinsic case. |
| 5808 | // Register `index` is not an index in an object array, but an |
| 5809 | // offset to an object reference field within object `obj`. |
| 5810 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5811 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5812 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5813 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5814 | DCHECK_EQ(offset, 0u); |
| 5815 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5816 | DCHECK_EQ(needs_null_check, 0u); |
| 5817 | // /* HeapReference<Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5818 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5819 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5820 | } else { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5821 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5822 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5823 | if (index.IsConstant()) { |
| 5824 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5825 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5826 | } else { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5827 | Register temp3 = temps.AcquireW(); |
| 5828 | __ Add(temp3, obj, offset); |
| 5829 | Load(type, ref_reg, HeapOperand(temp3, XRegisterFrom(index), LSL, scale_factor)); |
| 5830 | temps.Release(temp3); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5831 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5832 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5833 | } else { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5834 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5835 | MemOperand field = HeapOperand(obj, offset); |
| 5836 | if (use_load_acquire) { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5837 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5838 | } else { |
| 5839 | Load(type, ref_reg, field); |
| 5840 | } |
| 5841 | } |
| 5842 | |
| 5843 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5844 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 5845 | |
| 5846 | // Slow path marking the object `ref` when it is gray. |
| 5847 | SlowPathCodeARM64* slow_path; |
| 5848 | if (always_update_field) { |
| 5849 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 only supports |
| 5850 | // address of the form `obj + field_offset`, where `obj` is a |
| 5851 | // register and `field_offset` is a register. Thus `offset` and |
| 5852 | // `scale_factor` above are expected to be null in this code path. |
| 5853 | DCHECK_EQ(offset, 0u); |
| 5854 | DCHECK_EQ(scale_factor, 0u); /* "times 1" */ |
| 5855 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM64( |
| 5856 | instruction, ref, obj, /* field_offset */ index, temp); |
| 5857 | } else { |
| 5858 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
| 5859 | } |
| 5860 | AddSlowPath(slow_path); |
| 5861 | |
| 5862 | // if (rb_state == ReadBarrier::GrayState()) |
| 5863 | // ref = ReadBarrier::Mark(ref); |
| 5864 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 5865 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5866 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5867 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
| 5868 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5872 | Location out, |
| 5873 | Location ref, |
| 5874 | Location obj, |
| 5875 | uint32_t offset, |
| 5876 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5877 | DCHECK(kEmitCompilerReadBarrier); |
| 5878 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5879 | // Insert a slow path based read barrier *after* the reference load. |
| 5880 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5881 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5882 | // reference will be carried out by the runtime within the slow |
| 5883 | // path. |
| 5884 | // |
| 5885 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5886 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5887 | // not used by the artReadBarrierSlow entry point. |
| 5888 | // |
| 5889 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5890 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5891 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5892 | AddSlowPath(slow_path); |
| 5893 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5894 | __ B(slow_path->GetEntryLabel()); |
| 5895 | __ Bind(slow_path->GetExitLabel()); |
| 5896 | } |
| 5897 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5898 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5899 | Location out, |
| 5900 | Location ref, |
| 5901 | Location obj, |
| 5902 | uint32_t offset, |
| 5903 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5904 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5905 | // Baker's read barriers shall be handled by the fast path |
| 5906 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5907 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5908 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5909 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5910 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5911 | } else if (kPoisonHeapReferences) { |
| 5912 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5913 | } |
| 5914 | } |
| 5915 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5916 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5917 | Location out, |
| 5918 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5919 | DCHECK(kEmitCompilerReadBarrier); |
| 5920 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5921 | // Insert a slow path based read barrier *after* the GC root load. |
| 5922 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5923 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5924 | // not need to do anything special for this here. |
| 5925 | SlowPathCodeARM64* slow_path = |
| 5926 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5927 | AddSlowPath(slow_path); |
| 5928 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5929 | __ B(slow_path->GetEntryLabel()); |
| 5930 | __ Bind(slow_path->GetExitLabel()); |
| 5931 | } |
| 5932 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5933 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5934 | LocationSummary* locations = |
| 5935 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5936 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5937 | locations->SetOut(Location::RequiresRegister()); |
| 5938 | } |
| 5939 | |
| 5940 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5941 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5942 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5943 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5944 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5945 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5946 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5947 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5948 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5949 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5950 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5951 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5952 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5953 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5954 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5955 | } |
| 5956 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5957 | static void PatchJitRootUse(uint8_t* code, |
| 5958 | const uint8_t* roots_data, |
| 5959 | vixl::aarch64::Literal<uint32_t>* literal, |
| 5960 | uint64_t index_in_table) { |
| 5961 | uint32_t literal_offset = literal->GetOffset(); |
| 5962 | uintptr_t address = |
| 5963 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 5964 | uint8_t* data = code + literal_offset; |
| 5965 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 5966 | } |
| 5967 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5968 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 5969 | for (const auto& entry : jit_string_patches_) { |
| 5970 | const auto& it = jit_string_roots_.find(entry.first); |
| 5971 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5972 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 5973 | } |
| 5974 | for (const auto& entry : jit_class_patches_) { |
| 5975 | const auto& it = jit_class_roots_.find(entry.first); |
| 5976 | DCHECK(it != jit_class_roots_.end()); |
| 5977 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5978 | } |
| 5979 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5980 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5981 | #undef __ |
| 5982 | #undef QUICK_ENTRY_POINT |
| 5983 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5984 | } // namespace arm64 |
| 5985 | } // namespace art |