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) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 37 | |
| 38 | #ifdef __ |
| 39 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 40 | #endif |
| 41 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 42 | namespace art { |
| 43 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | namespace arm64 { |
| 48 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 49 | using helpers::ARM64EncodableConstantOrRegister; |
| 50 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 51 | using helpers::CPURegisterFrom; |
| 52 | using helpers::DRegisterFrom; |
| 53 | using helpers::FPRegisterFrom; |
| 54 | using helpers::HeapOperand; |
| 55 | using helpers::HeapOperandFrom; |
| 56 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 57 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 58 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 59 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 61 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 62 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 63 | using helpers::LocationFrom; |
| 64 | using helpers::OperandFromMemOperand; |
| 65 | using helpers::OutputCPURegister; |
| 66 | using helpers::OutputFPRegister; |
| 67 | using helpers::OutputRegister; |
| 68 | using helpers::RegisterFrom; |
| 69 | using helpers::StackOperandFrom; |
| 70 | using helpers::VIXLRegCodeFromART; |
| 71 | using helpers::WRegisterFrom; |
| 72 | using helpers::XRegisterFrom; |
| 73 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 74 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 75 | // 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] | 76 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 77 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 78 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 79 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 80 | inline Condition ARM64Condition(IfCondition cond) { |
| 81 | switch (cond) { |
| 82 | case kCondEQ: return eq; |
| 83 | case kCondNE: return ne; |
| 84 | case kCondLT: return lt; |
| 85 | case kCondLE: return le; |
| 86 | case kCondGT: return gt; |
| 87 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 88 | case kCondB: return lo; |
| 89 | case kCondBE: return ls; |
| 90 | case kCondA: return hi; |
| 91 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 92 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 93 | LOG(FATAL) << "Unreachable"; |
| 94 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 97 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 98 | // The ARM64 condition codes can express all the necessary branches, see the |
| 99 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 100 | // There is no dex instruction or HIR that would need the missing conditions |
| 101 | // "equal or unordered" or "not equal". |
| 102 | switch (cond) { |
| 103 | case kCondEQ: return eq; |
| 104 | case kCondNE: return ne /* unordered */; |
| 105 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 106 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 107 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 108 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 109 | default: |
| 110 | LOG(FATAL) << "UNREACHABLE"; |
| 111 | UNREACHABLE(); |
| 112 | } |
| 113 | } |
| 114 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 115 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 116 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 117 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 118 | // but we use the exact registers for clarity. |
| 119 | if (return_type == Primitive::kPrimFloat) { |
| 120 | return LocationFrom(s0); |
| 121 | } else if (return_type == Primitive::kPrimDouble) { |
| 122 | return LocationFrom(d0); |
| 123 | } else if (return_type == Primitive::kPrimLong) { |
| 124 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 125 | } else if (return_type == Primitive::kPrimVoid) { |
| 126 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 127 | } else { |
| 128 | return LocationFrom(w0); |
| 129 | } |
| 130 | } |
| 131 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 132 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 133 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 136 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 137 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 138 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 139 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 140 | // Calculate memory accessing operand for save/restore live registers. |
| 141 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 142 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 143 | int64_t spill_offset, |
| 144 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 145 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 146 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 147 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 148 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 149 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 150 | codegen->GetNumberOfFloatingPointRegisters())); |
| 151 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 152 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
| 153 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 154 | |
| 155 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 156 | UseScratchRegisterScope temps(masm); |
| 157 | |
| 158 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 159 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 160 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 161 | int64_t reg_size = kXRegSizeInBytes; |
| 162 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 163 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 164 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 165 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 166 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 167 | // to compute the base address(float point registers spill base address). |
| 168 | Register new_base = temps.AcquireSameSizeAs(base); |
| 169 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 170 | base = new_base; |
| 171 | spill_offset = -core_spill_size; |
| 172 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 173 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 174 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 175 | } |
| 176 | |
| 177 | if (is_save) { |
| 178 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 179 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 180 | } else { |
| 181 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 182 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 187 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 188 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 189 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 190 | // If the register holds an object, update the stack mask. |
| 191 | if (locations->RegisterContainsObject(i)) { |
| 192 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 193 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_core_stack_offsets_[i] = stack_offset; |
| 197 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | } |
| 199 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 200 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 201 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 202 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 203 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 204 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 205 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 206 | } |
| 207 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 208 | SaveRestoreLiveRegistersHelper(codegen, |
| 209 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 210 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 211 | } |
| 212 | |
| 213 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 214 | SaveRestoreLiveRegistersHelper(codegen, |
| 215 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 216 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 217 | } |
| 218 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 219 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 220 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 221 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 222 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 223 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 224 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 225 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 226 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 227 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 228 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 229 | // Live registers will be restored in the catch block if caught. |
| 230 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 231 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 232 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 233 | // move resolver. |
| 234 | InvokeRuntimeCallingConvention calling_convention; |
| 235 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 236 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 237 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 238 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 239 | ? kQuickThrowStringBounds |
| 240 | : kQuickThrowArrayBounds; |
| 241 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 242 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 243 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 246 | bool IsFatal() const OVERRIDE { return true; } |
| 247 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 248 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 249 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 252 | }; |
| 253 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 254 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 255 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 256 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 257 | |
| 258 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 259 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 260 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 261 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 262 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 265 | bool IsFatal() const OVERRIDE { return true; } |
| 266 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 267 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 268 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 270 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 271 | }; |
| 272 | |
| 273 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 274 | public: |
| 275 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 276 | HInstruction* at, |
| 277 | uint32_t dex_pc, |
| 278 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 279 | : SlowPathCodeARM64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 280 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 281 | } |
| 282 | |
| 283 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 284 | LocationSummary* locations = at_->GetLocations(); |
| 285 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 286 | |
| 287 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 288 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 289 | |
| 290 | InvokeRuntimeCallingConvention calling_convention; |
| 291 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 292 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 293 | : kQuickInitializeType; |
| 294 | arm64_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 295 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 296 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 297 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 298 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 299 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | |
| 301 | // Move the class to the desired location. |
| 302 | Location out = locations->Out(); |
| 303 | if (out.IsValid()) { |
| 304 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 305 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 306 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 309 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | __ B(GetExitLabel()); |
| 311 | } |
| 312 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 313 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 314 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 315 | private: |
| 316 | // The class this slow path will load. |
| 317 | HLoadClass* const cls_; |
| 318 | |
| 319 | // The instruction where this slow path is happening. |
| 320 | // (Might be the load class or an initialization check). |
| 321 | HInstruction* const at_; |
| 322 | |
| 323 | // The dex PC of `at_`. |
| 324 | const uint32_t dex_pc_; |
| 325 | |
| 326 | // Whether to initialize the class. |
| 327 | const bool do_clinit_; |
| 328 | |
| 329 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 330 | }; |
| 331 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 332 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 333 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 334 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 335 | : SlowPathCodeARM64(instruction), |
| 336 | temp_(temp), |
| 337 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 338 | |
| 339 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 340 | LocationSummary* locations = instruction_->GetLocations(); |
| 341 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 342 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 343 | |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 344 | // temp_ is a scratch register. Make sure it's not used for saving/restoring registers. |
| 345 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 346 | temps.Exclude(temp_); |
| 347 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 348 | __ Bind(GetEntryLabel()); |
| 349 | SaveLiveRegisters(codegen, locations); |
| 350 | |
| 351 | InvokeRuntimeCallingConvention calling_convention; |
| 352 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 353 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
| 354 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 355 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 356 | Primitive::Type type = instruction_->GetType(); |
| 357 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 358 | |
| 359 | RestoreLiveRegisters(codegen, locations); |
| 360 | |
| 361 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 362 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 363 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 364 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 365 | } else { |
| 366 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 367 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 368 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 369 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 370 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 371 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 372 | { |
| 373 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 374 | __ Bind(strp_label); |
| 375 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 376 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | __ B(GetExitLabel()); |
| 380 | } |
| 381 | |
| 382 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 383 | |
| 384 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 385 | const Register temp_; |
| 386 | vixl::aarch64::Label* adrp_label_; |
| 387 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 388 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 389 | }; |
| 390 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 391 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 392 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 394 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 395 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 396 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 397 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 398 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 399 | // Live registers will be restored in the catch block if caught. |
| 400 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 401 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 402 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 403 | instruction_, |
| 404 | instruction_->GetDexPc(), |
| 405 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 406 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 409 | bool IsFatal() const OVERRIDE { return true; } |
| 410 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 411 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 412 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 413 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 414 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 415 | }; |
| 416 | |
| 417 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 418 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 419 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 420 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 421 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 422 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 423 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 425 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 426 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 427 | if (successor_ == nullptr) { |
| 428 | __ B(GetReturnLabel()); |
| 429 | } else { |
| 430 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 431 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 434 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 435 | DCHECK(successor_ == nullptr); |
| 436 | return &return_label_; |
| 437 | } |
| 438 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 439 | HBasicBlock* GetSuccessor() const { |
| 440 | return successor_; |
| 441 | } |
| 442 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 443 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 444 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 445 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 446 | // If not null, the block to branch to after the suspend check. |
| 447 | HBasicBlock* const successor_; |
| 448 | |
| 449 | // 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] | 450 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 451 | |
| 452 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 453 | }; |
| 454 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 455 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 456 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 457 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 458 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 459 | |
| 460 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 461 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 462 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 463 | DCHECK(instruction_->IsCheckCast() |
| 464 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 465 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 466 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 467 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 468 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 469 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 470 | if (!is_fatal_) { |
| 471 | SaveLiveRegisters(codegen, locations); |
| 472 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 473 | |
| 474 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 475 | // move resolver. |
| 476 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 477 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 478 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 479 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 480 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 481 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 482 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 483 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 484 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 485 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 486 | Primitive::Type ret_type = instruction_->GetType(); |
| 487 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 488 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 489 | } else { |
| 490 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 491 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 492 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 495 | if (!is_fatal_) { |
| 496 | RestoreLiveRegisters(codegen, locations); |
| 497 | __ B(GetExitLabel()); |
| 498 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 501 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 502 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 503 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 504 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 505 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 506 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 507 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 508 | }; |
| 509 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 510 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 511 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 512 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 513 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 514 | |
| 515 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 516 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 517 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 518 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 519 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 522 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 523 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 524 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 526 | }; |
| 527 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 528 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 529 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 530 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 531 | |
| 532 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 533 | LocationSummary* locations = instruction_->GetLocations(); |
| 534 | __ Bind(GetEntryLabel()); |
| 535 | SaveLiveRegisters(codegen, locations); |
| 536 | |
| 537 | InvokeRuntimeCallingConvention calling_convention; |
| 538 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 539 | parallel_move.AddMove( |
| 540 | locations->InAt(0), |
| 541 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 542 | Primitive::kPrimNot, |
| 543 | nullptr); |
| 544 | parallel_move.AddMove( |
| 545 | locations->InAt(1), |
| 546 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 547 | Primitive::kPrimInt, |
| 548 | nullptr); |
| 549 | parallel_move.AddMove( |
| 550 | locations->InAt(2), |
| 551 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 552 | Primitive::kPrimNot, |
| 553 | nullptr); |
| 554 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 555 | |
| 556 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 557 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 558 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 559 | RestoreLiveRegisters(codegen, locations); |
| 560 | __ B(GetExitLabel()); |
| 561 | } |
| 562 | |
| 563 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 564 | |
| 565 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 566 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 567 | }; |
| 568 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 569 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 570 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 571 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 572 | |
| 573 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 574 | // underlying code buffer and we have generated the jump table with right size. |
| 575 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 576 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 577 | |
| 578 | __ Bind(&table_start_); |
| 579 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 580 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 581 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 582 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 583 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 584 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 585 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 586 | Literal<int32_t> literal(jump_offset); |
| 587 | __ place(&literal); |
| 588 | } |
| 589 | } |
| 590 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 591 | // Slow path marking an object reference `ref` during a read |
| 592 | // barrier. The field `obj.field` in the object `obj` holding this |
| 593 | // reference does not get updated by this slow path after marking (see |
| 594 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 below for that). |
| 595 | // |
| 596 | // This means that after the execution of this slow path, `ref` will |
| 597 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 598 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 599 | // probably still be a from-space reference (unless it gets updated by |
| 600 | // another thread, or if another thread installed another object |
| 601 | // reference (different from `ref`) in `obj.field`). |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 602 | // If entrypoint is a valid location it is assumed to already be holding the entrypoint. The case |
| 603 | // where the entrypoint is passed in is for the GcRoot read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 604 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 605 | public: |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 606 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 607 | Location ref, |
| 608 | Location entrypoint = Location::NoLocation()) |
| 609 | : SlowPathCodeARM64(instruction), |
| 610 | ref_(ref), |
| 611 | entrypoint_(entrypoint) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 612 | DCHECK(kEmitCompilerReadBarrier); |
| 613 | } |
| 614 | |
| 615 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 616 | |
| 617 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 618 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 619 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 620 | DCHECK(ref_.IsRegister()) << ref_; |
| 621 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 622 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 623 | instruction_->IsStaticFieldGet() || |
| 624 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 625 | instruction_->IsArraySet() || |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 626 | instruction_->IsLoadClass() || |
| 627 | instruction_->IsLoadString() || |
| 628 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 629 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 630 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 631 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 632 | << "Unexpected instruction in read barrier marking slow path: " |
| 633 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 634 | // The read barrier instrumentation of object ArrayGet |
| 635 | // instructions does not support the HIntermediateAddress |
| 636 | // instruction. |
| 637 | DCHECK(!(instruction_->IsArrayGet() && |
| 638 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 639 | |
| 640 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 641 | // No need to save live registers; it's taken care of by the |
| 642 | // entrypoint. Also, there is no need to update the stack mask, |
| 643 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 644 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 645 | DCHECK_NE(ref_.reg(), LR); |
| 646 | DCHECK_NE(ref_.reg(), WSP); |
| 647 | DCHECK_NE(ref_.reg(), WZR); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 648 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 649 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 650 | DCHECK_NE(ref_.reg(), IP0); |
| 651 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 652 | // "Compact" slow path, saving two moves. |
| 653 | // |
| 654 | // Instead of using the standard runtime calling convention (input |
| 655 | // and output in W0): |
| 656 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 657 | // W0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 658 | // W0 <- ReadBarrierMark(W0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 659 | // ref <- W0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 660 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 661 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 662 | // of a dedicated entrypoint: |
| 663 | // |
| 664 | // rX <- ReadBarrierMarkRegX(rX) |
| 665 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 666 | if (entrypoint_.IsValid()) { |
| 667 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 668 | __ Blr(XRegisterFrom(entrypoint_)); |
| 669 | } else { |
| 670 | // Entrypoint is not already loaded, load from the thread. |
| 671 | int32_t entry_point_offset = |
| 672 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 673 | // This runtime call does not require a stack map. |
| 674 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 675 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 676 | __ B(GetExitLabel()); |
| 677 | } |
| 678 | |
| 679 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 680 | // The location (register) of the marked object reference. |
| 681 | const Location ref_; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 682 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 683 | // The location of the entrypoint if it is already loaded. |
| 684 | const Location entrypoint_; |
| 685 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 686 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 687 | }; |
| 688 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 689 | // Slow path marking an object reference `ref` during a read barrier, |
| 690 | // and if needed, atomically updating the field `obj.field` in the |
| 691 | // object `obj` holding this reference after marking (contrary to |
| 692 | // ReadBarrierMarkSlowPathARM64 above, which never tries to update |
| 693 | // `obj.field`). |
| 694 | // |
| 695 | // This means that after the execution of this slow path, both `ref` |
| 696 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 697 | // hold the same to-space reference (unless another thread installed |
| 698 | // another object reference (different from `ref`) in `obj.field`). |
| 699 | class ReadBarrierMarkAndUpdateFieldSlowPathARM64 : public SlowPathCodeARM64 { |
| 700 | public: |
| 701 | ReadBarrierMarkAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 702 | Location ref, |
| 703 | Register obj, |
| 704 | Location field_offset, |
| 705 | Register temp) |
| 706 | : SlowPathCodeARM64(instruction), |
| 707 | ref_(ref), |
| 708 | obj_(obj), |
| 709 | field_offset_(field_offset), |
| 710 | temp_(temp) { |
| 711 | DCHECK(kEmitCompilerReadBarrier); |
| 712 | } |
| 713 | |
| 714 | const char* GetDescription() const OVERRIDE { |
| 715 | return "ReadBarrierMarkAndUpdateFieldSlowPathARM64"; |
| 716 | } |
| 717 | |
| 718 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 719 | LocationSummary* locations = instruction_->GetLocations(); |
| 720 | Register ref_reg = WRegisterFrom(ref_); |
| 721 | DCHECK(locations->CanCall()); |
| 722 | DCHECK(ref_.IsRegister()) << ref_; |
| 723 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 724 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 725 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 726 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 727 | << instruction_->DebugName(); |
| 728 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 729 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 730 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 731 | |
| 732 | __ Bind(GetEntryLabel()); |
| 733 | |
| 734 | // Save the old reference. |
| 735 | // Note that we cannot use IP to save the old reference, as IP is |
| 736 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 737 | // need the old reference after the call to that entry point. |
| 738 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 739 | __ Mov(temp_.W(), ref_reg); |
| 740 | |
| 741 | // No need to save live registers; it's taken care of by the |
| 742 | // entrypoint. Also, there is no need to update the stack mask, |
| 743 | // as this runtime call will not trigger a garbage collection. |
| 744 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 745 | DCHECK_NE(ref_.reg(), LR); |
| 746 | DCHECK_NE(ref_.reg(), WSP); |
| 747 | DCHECK_NE(ref_.reg(), WZR); |
| 748 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 749 | // as a temporary, it cannot be the entry point's input/output. |
| 750 | DCHECK_NE(ref_.reg(), IP0); |
| 751 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 752 | // "Compact" slow path, saving two moves. |
| 753 | // |
| 754 | // Instead of using the standard runtime calling convention (input |
| 755 | // and output in W0): |
| 756 | // |
| 757 | // W0 <- ref |
| 758 | // W0 <- ReadBarrierMark(W0) |
| 759 | // ref <- W0 |
| 760 | // |
| 761 | // we just use rX (the register containing `ref`) as input and output |
| 762 | // of a dedicated entrypoint: |
| 763 | // |
| 764 | // rX <- ReadBarrierMarkRegX(rX) |
| 765 | // |
| 766 | int32_t entry_point_offset = |
| 767 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 768 | // This runtime call does not require a stack map. |
| 769 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 770 | |
| 771 | // If the new reference is different from the old reference, |
| 772 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 773 | // |
| 774 | // Note that this field could also hold a different object, if |
| 775 | // another thread had concurrently changed it. In that case, the |
| 776 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 777 | // (CAS) operation below would abort the CAS, leaving the field |
| 778 | // as-is. |
| 779 | vixl::aarch64::Label done; |
| 780 | __ Cmp(temp_.W(), ref_reg); |
| 781 | __ B(eq, &done); |
| 782 | |
| 783 | // Update the the holder's field atomically. This may fail if |
| 784 | // mutator updates before us, but it's OK. This is achieved |
| 785 | // using a strong compare-and-set (CAS) operation with relaxed |
| 786 | // memory synchronization ordering, where the expected value is |
| 787 | // the old reference and the desired value is the new reference. |
| 788 | |
| 789 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 790 | UseScratchRegisterScope temps(masm); |
| 791 | |
| 792 | // Convenience aliases. |
| 793 | Register base = obj_.W(); |
| 794 | Register offset = XRegisterFrom(field_offset_); |
| 795 | Register expected = temp_.W(); |
| 796 | Register value = ref_reg; |
| 797 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 798 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 799 | |
| 800 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 801 | |
| 802 | if (kPoisonHeapReferences) { |
| 803 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 804 | if (value.Is(expected)) { |
| 805 | // Do not poison `value`, as it is the same register as |
| 806 | // `expected`, which has just been poisoned. |
| 807 | } else { |
| 808 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | // do { |
| 813 | // tmp_value = [tmp_ptr] - expected; |
| 814 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 815 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 816 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 817 | __ Bind(&loop_head); |
| 818 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 819 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 820 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 821 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 822 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 823 | __ B(&exit_loop); |
| 824 | __ Bind(&comparison_failed); |
| 825 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 826 | __ Bind(&exit_loop); |
| 827 | |
| 828 | if (kPoisonHeapReferences) { |
| 829 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 830 | if (value.Is(expected)) { |
| 831 | // Do not unpoison `value`, as it is the same register as |
| 832 | // `expected`, which has just been unpoisoned. |
| 833 | } else { |
| 834 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | __ Bind(&done); |
| 839 | __ B(GetExitLabel()); |
| 840 | } |
| 841 | |
| 842 | private: |
| 843 | // The location (register) of the marked object reference. |
| 844 | const Location ref_; |
| 845 | // The register containing the object holding the marked object reference field. |
| 846 | const Register obj_; |
| 847 | // The location of the offset of the marked reference field within `obj_`. |
| 848 | Location field_offset_; |
| 849 | |
| 850 | const Register temp_; |
| 851 | |
| 852 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM64); |
| 853 | }; |
| 854 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 855 | // Slow path generating a read barrier for a heap reference. |
| 856 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 857 | public: |
| 858 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 859 | Location out, |
| 860 | Location ref, |
| 861 | Location obj, |
| 862 | uint32_t offset, |
| 863 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 864 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 865 | out_(out), |
| 866 | ref_(ref), |
| 867 | obj_(obj), |
| 868 | offset_(offset), |
| 869 | index_(index) { |
| 870 | DCHECK(kEmitCompilerReadBarrier); |
| 871 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 872 | // has been overwritten by (or after) the heap object reference load |
| 873 | // to be instrumented, e.g.: |
| 874 | // |
| 875 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 876 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 877 | // |
| 878 | // In that case, we have lost the information about the original |
| 879 | // object, and the emitted read barrier cannot work properly. |
| 880 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 881 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 882 | } |
| 883 | |
| 884 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 885 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 886 | LocationSummary* locations = instruction_->GetLocations(); |
| 887 | Primitive::Type type = Primitive::kPrimNot; |
| 888 | DCHECK(locations->CanCall()); |
| 889 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 890 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 891 | instruction_->IsStaticFieldGet() || |
| 892 | instruction_->IsArrayGet() || |
| 893 | instruction_->IsInstanceOf() || |
| 894 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 895 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 896 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 897 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 898 | // The read barrier instrumentation of object ArrayGet |
| 899 | // instructions does not support the HIntermediateAddress |
| 900 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 901 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 902 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 903 | |
| 904 | __ Bind(GetEntryLabel()); |
| 905 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 906 | SaveLiveRegisters(codegen, locations); |
| 907 | |
| 908 | // We may have to change the index's value, but as `index_` is a |
| 909 | // constant member (like other "inputs" of this slow path), |
| 910 | // introduce a copy of it, `index`. |
| 911 | Location index = index_; |
| 912 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 913 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 914 | if (instruction_->IsArrayGet()) { |
| 915 | // Compute the actual memory offset and store it in `index`. |
| 916 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 917 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 918 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 919 | // We are about to change the value of `index_reg` (see the |
| 920 | // calls to vixl::MacroAssembler::Lsl and |
| 921 | // vixl::MacroAssembler::Mov below), but it has |
| 922 | // not been saved by the previous call to |
| 923 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 924 | // callee-save register -- |
| 925 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 926 | // callee-save registers, as it has been designed with the |
| 927 | // assumption that callee-save registers are supposed to be |
| 928 | // handled by the called function. So, as a callee-save |
| 929 | // register, `index_reg` _would_ eventually be saved onto |
| 930 | // the stack, but it would be too late: we would have |
| 931 | // changed its value earlier. Therefore, we manually save |
| 932 | // it here into another freely available register, |
| 933 | // `free_reg`, chosen of course among the caller-save |
| 934 | // registers (as a callee-save `free_reg` register would |
| 935 | // exhibit the same problem). |
| 936 | // |
| 937 | // Note we could have requested a temporary register from |
| 938 | // the register allocator instead; but we prefer not to, as |
| 939 | // this is a slow path, and we know we can find a |
| 940 | // caller-save register that is available. |
| 941 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 942 | __ Mov(free_reg.W(), index_reg); |
| 943 | index_reg = free_reg; |
| 944 | index = LocationFrom(index_reg); |
| 945 | } else { |
| 946 | // The initial register stored in `index_` has already been |
| 947 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 948 | // (as it is not a callee-save register), so we can freely |
| 949 | // use it. |
| 950 | } |
| 951 | // Shifting the index value contained in `index_reg` by the scale |
| 952 | // factor (2) cannot overflow in practice, as the runtime is |
| 953 | // unable to allocate object arrays with a size larger than |
| 954 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 955 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 956 | static_assert( |
| 957 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 958 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 959 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 960 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 961 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 962 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 963 | // (as in the case of ArrayGet), as it is actually an offset |
| 964 | // to an object field within an object. |
| 965 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 966 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 967 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 968 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 969 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 970 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 971 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | |
| 975 | // We're moving two or three locations to locations that could |
| 976 | // overlap, so we need a parallel move resolver. |
| 977 | InvokeRuntimeCallingConvention calling_convention; |
| 978 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 979 | parallel_move.AddMove(ref_, |
| 980 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 981 | type, |
| 982 | nullptr); |
| 983 | parallel_move.AddMove(obj_, |
| 984 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 985 | type, |
| 986 | nullptr); |
| 987 | if (index.IsValid()) { |
| 988 | parallel_move.AddMove(index, |
| 989 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 990 | Primitive::kPrimInt, |
| 991 | nullptr); |
| 992 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 993 | } else { |
| 994 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 995 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 996 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 997 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 998 | instruction_, |
| 999 | instruction_->GetDexPc(), |
| 1000 | this); |
| 1001 | CheckEntrypointTypes< |
| 1002 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1003 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1004 | |
| 1005 | RestoreLiveRegisters(codegen, locations); |
| 1006 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1007 | __ B(GetExitLabel()); |
| 1008 | } |
| 1009 | |
| 1010 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1011 | |
| 1012 | private: |
| 1013 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1014 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1015 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1016 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1017 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1018 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1019 | } |
| 1020 | } |
| 1021 | // We shall never fail to find a free caller-save register, as |
| 1022 | // there are more than two core caller-save registers on ARM64 |
| 1023 | // (meaning it is possible to find one which is different from |
| 1024 | // `ref` and `obj`). |
| 1025 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1026 | LOG(FATAL) << "Could not find a free register"; |
| 1027 | UNREACHABLE(); |
| 1028 | } |
| 1029 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1030 | const Location out_; |
| 1031 | const Location ref_; |
| 1032 | const Location obj_; |
| 1033 | const uint32_t offset_; |
| 1034 | // An additional location containing an index to an array. |
| 1035 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1036 | // UnsafeGetObjectVolatile intrinsics. |
| 1037 | const Location index_; |
| 1038 | |
| 1039 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1040 | }; |
| 1041 | |
| 1042 | // Slow path generating a read barrier for a GC root. |
| 1043 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1044 | public: |
| 1045 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1046 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1047 | DCHECK(kEmitCompilerReadBarrier); |
| 1048 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1049 | |
| 1050 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1051 | LocationSummary* locations = instruction_->GetLocations(); |
| 1052 | Primitive::Type type = Primitive::kPrimNot; |
| 1053 | DCHECK(locations->CanCall()); |
| 1054 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1055 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1056 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1057 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1058 | |
| 1059 | __ Bind(GetEntryLabel()); |
| 1060 | SaveLiveRegisters(codegen, locations); |
| 1061 | |
| 1062 | InvokeRuntimeCallingConvention calling_convention; |
| 1063 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1064 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1065 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1066 | // thus we need a 64-bit move here, and we cannot use |
| 1067 | // |
| 1068 | // arm64_codegen->MoveLocation( |
| 1069 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1070 | // root_, |
| 1071 | // type); |
| 1072 | // |
| 1073 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1074 | // reference type (`Primitive::kPrimNot`). |
| 1075 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1076 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1077 | instruction_, |
| 1078 | instruction_->GetDexPc(), |
| 1079 | this); |
| 1080 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1081 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1082 | |
| 1083 | RestoreLiveRegisters(codegen, locations); |
| 1084 | __ B(GetExitLabel()); |
| 1085 | } |
| 1086 | |
| 1087 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1088 | |
| 1089 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1090 | const Location out_; |
| 1091 | const Location root_; |
| 1092 | |
| 1093 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1094 | }; |
| 1095 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1096 | #undef __ |
| 1097 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1098 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1099 | Location next_location; |
| 1100 | if (type == Primitive::kPrimVoid) { |
| 1101 | LOG(FATAL) << "Unreachable type " << type; |
| 1102 | } |
| 1103 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1104 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1105 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 1106 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1107 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1108 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1109 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1110 | } else { |
| 1111 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1112 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1113 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1116 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1117 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1118 | return next_location; |
| 1119 | } |
| 1120 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1121 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1122 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1125 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1126 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1127 | const CompilerOptions& compiler_options, |
| 1128 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1129 | : CodeGenerator(graph, |
| 1130 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1131 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1132 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1133 | callee_saved_core_registers.GetList(), |
| 1134 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1135 | compiler_options, |
| 1136 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1137 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1138 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1139 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1140 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1141 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1142 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1143 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1144 | uint32_literals_(std::less<uint32_t>(), |
| 1145 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1146 | uint64_literals_(std::less<uint64_t>(), |
| 1147 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1148 | method_patches_(MethodReferenceComparator(), |
| 1149 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1150 | call_patches_(MethodReferenceComparator(), |
| 1151 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1152 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1153 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1154 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1155 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1156 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1157 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1158 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1159 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1160 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 1161 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1162 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1163 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1164 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1165 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1166 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1167 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1168 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1169 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1170 | jump_table->EmitTable(this); |
| 1171 | } |
| 1172 | } |
| 1173 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1174 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1175 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1176 | // Ensure we emit the literal pool. |
| 1177 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1178 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1179 | CodeGenerator::Finalize(allocator); |
| 1180 | } |
| 1181 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1182 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1183 | // Note: There are 6 kinds of moves: |
| 1184 | // 1. constant -> GPR/FPR (non-cycle) |
| 1185 | // 2. constant -> stack (non-cycle) |
| 1186 | // 3. GPR/FPR -> GPR/FPR |
| 1187 | // 4. GPR/FPR -> stack |
| 1188 | // 5. stack -> GPR/FPR |
| 1189 | // 6. stack -> stack (non-cycle) |
| 1190 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1191 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1192 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1193 | // dependency. |
| 1194 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1195 | } |
| 1196 | |
| 1197 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1198 | vixl_temps_.Close(); |
| 1199 | } |
| 1200 | |
| 1201 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 1202 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 1203 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 1204 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 1205 | Location scratch = GetScratchLocation(kind); |
| 1206 | if (!scratch.Equals(Location::NoLocation())) { |
| 1207 | return scratch; |
| 1208 | } |
| 1209 | // Allocate from VIXL temp registers. |
| 1210 | if (kind == Location::kRegister) { |
| 1211 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1212 | } else { |
| 1213 | DCHECK(kind == Location::kFpuRegister); |
| 1214 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1215 | } |
| 1216 | AddScratchLocation(scratch); |
| 1217 | return scratch; |
| 1218 | } |
| 1219 | |
| 1220 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1221 | if (loc.IsRegister()) { |
| 1222 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1223 | } else { |
| 1224 | DCHECK(loc.IsFpuRegister()); |
| 1225 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1226 | } |
| 1227 | RemoveScratchLocation(loc); |
| 1228 | } |
| 1229 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1230 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1231 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1232 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1235 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1236 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1237 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1238 | __ Bind(&frame_entry_label_); |
| 1239 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1240 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1241 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1242 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1243 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1244 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1245 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1246 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1247 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1248 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1249 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1250 | if (!HasEmptyFrame()) { |
| 1251 | int frame_size = GetFrameSize(); |
| 1252 | // Stack layout: |
| 1253 | // sp[frame_size - 8] : lr. |
| 1254 | // ... : other preserved core registers. |
| 1255 | // ... : other preserved fp registers. |
| 1256 | // ... : reserved frame space. |
| 1257 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1258 | |
| 1259 | // Save the current method if we need it. Note that we do not |
| 1260 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1261 | // in the SSA graph. |
| 1262 | if (RequiresCurrentMethod()) { |
| 1263 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1264 | } else { |
| 1265 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1266 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1267 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1268 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1269 | frame_size - GetCoreSpillSize()); |
| 1270 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1271 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1272 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1276 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1277 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1278 | if (!HasEmptyFrame()) { |
| 1279 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1280 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1281 | frame_size - FrameEntrySpillSize()); |
| 1282 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1283 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1284 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1285 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1286 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1287 | __ Ret(); |
| 1288 | GetAssembler()->cfi().RestoreState(); |
| 1289 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1290 | } |
| 1291 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1292 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1293 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1294 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1295 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1296 | } |
| 1297 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1298 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1299 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1300 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1301 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1302 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1303 | } |
| 1304 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1305 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1306 | __ Bind(GetLabelOf(block)); |
| 1307 | } |
| 1308 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1309 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1310 | DCHECK(location.IsRegister()); |
| 1311 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1312 | } |
| 1313 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1314 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1315 | if (location.IsRegister()) { |
| 1316 | locations->AddTemp(location); |
| 1317 | } else { |
| 1318 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1319 | } |
| 1320 | } |
| 1321 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1322 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1323 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1324 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1325 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1326 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1327 | if (value_can_be_null) { |
| 1328 | __ Cbz(value, &done); |
| 1329 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1330 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1331 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1332 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1333 | if (value_can_be_null) { |
| 1334 | __ Bind(&done); |
| 1335 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1338 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1339 | // Blocked core registers: |
| 1340 | // lr : Runtime reserved. |
| 1341 | // tr : Runtime reserved. |
| 1342 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1343 | // ip1 : VIXL core temp. |
| 1344 | // ip0 : VIXL core temp. |
| 1345 | // |
| 1346 | // Blocked fp registers: |
| 1347 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1348 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1349 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1350 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1351 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1352 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1353 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1354 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1355 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1356 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1357 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1358 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1359 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1360 | // Stubs do not save callee-save floating point registers. If the graph |
| 1361 | // is debuggable, we need to deal with these registers differently. For |
| 1362 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1363 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1364 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1365 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1366 | } |
| 1367 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1368 | } |
| 1369 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1370 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1371 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1372 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1373 | return kArm64WordSize; |
| 1374 | } |
| 1375 | |
| 1376 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1377 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1378 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1379 | return kArm64WordSize; |
| 1380 | } |
| 1381 | |
| 1382 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1383 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1384 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1385 | return kArm64WordSize; |
| 1386 | } |
| 1387 | |
| 1388 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1389 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1390 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1391 | return kArm64WordSize; |
| 1392 | } |
| 1393 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1394 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1395 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1399 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1402 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1403 | if (constant->IsIntConstant()) { |
| 1404 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1405 | } else if (constant->IsLongConstant()) { |
| 1406 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1407 | } else if (constant->IsNullConstant()) { |
| 1408 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1409 | } else if (constant->IsFloatConstant()) { |
| 1410 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1411 | } else { |
| 1412 | DCHECK(constant->IsDoubleConstant()); |
| 1413 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1414 | } |
| 1415 | } |
| 1416 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1417 | |
| 1418 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1419 | DCHECK(constant.IsConstant()); |
| 1420 | HConstant* cst = constant.GetConstant(); |
| 1421 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1422 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1423 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1424 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1425 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1426 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1427 | } |
| 1428 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1429 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1430 | Location source, |
| 1431 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1432 | if (source.Equals(destination)) { |
| 1433 | return; |
| 1434 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1435 | |
| 1436 | // A valid move can always be inferred from the destination and source |
| 1437 | // locations. When moving from and to a register, the argument type can be |
| 1438 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1439 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1440 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1441 | |
| 1442 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1443 | if (unspecified_type) { |
| 1444 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1445 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1446 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1447 | || src_cst->IsFloatConstant() |
| 1448 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1449 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1450 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1451 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1452 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1453 | // type is appropriate. Else the source is a register, and since the |
| 1454 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1455 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1456 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1457 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1458 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1459 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1460 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1461 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1462 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1463 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1464 | __ Ldr(dst, StackOperandFrom(source)); |
| 1465 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1466 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1467 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1468 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1469 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1470 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1471 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1472 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1473 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1474 | ? Primitive::kPrimLong |
| 1475 | : Primitive::kPrimInt; |
| 1476 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1477 | } |
| 1478 | } else { |
| 1479 | DCHECK(source.IsFpuRegister()); |
| 1480 | if (destination.IsRegister()) { |
| 1481 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1482 | ? Primitive::kPrimDouble |
| 1483 | : Primitive::kPrimFloat; |
| 1484 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1485 | } else { |
| 1486 | DCHECK(destination.IsFpuRegister()); |
| 1487 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1488 | } |
| 1489 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1490 | } else { // The destination is not a register. It must be a stack slot. |
| 1491 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1492 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1493 | if (unspecified_type) { |
| 1494 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1495 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1496 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1497 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1498 | } |
| 1499 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1500 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1501 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1502 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1503 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1504 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1505 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1506 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1507 | HConstant* src_cst = source.GetConstant(); |
| 1508 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1509 | if (src_cst->IsZeroBitPattern()) { |
| 1510 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1511 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1512 | if (src_cst->IsIntConstant()) { |
| 1513 | temp = temps.AcquireW(); |
| 1514 | } else if (src_cst->IsLongConstant()) { |
| 1515 | temp = temps.AcquireX(); |
| 1516 | } else if (src_cst->IsFloatConstant()) { |
| 1517 | temp = temps.AcquireS(); |
| 1518 | } else { |
| 1519 | DCHECK(src_cst->IsDoubleConstant()); |
| 1520 | temp = temps.AcquireD(); |
| 1521 | } |
| 1522 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1523 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1524 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1525 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1526 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1527 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1528 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1529 | // There is generally less pressure on FP registers. |
| 1530 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1531 | __ Ldr(temp, StackOperandFrom(source)); |
| 1532 | __ Str(temp, StackOperandFrom(destination)); |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1538 | CPURegister dst, |
| 1539 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1540 | switch (type) { |
| 1541 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1542 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1545 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1546 | break; |
| 1547 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1548 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1549 | break; |
| 1550 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1551 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1552 | break; |
| 1553 | case Primitive::kPrimInt: |
| 1554 | case Primitive::kPrimNot: |
| 1555 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1556 | case Primitive::kPrimFloat: |
| 1557 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1558 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1559 | __ Ldr(dst, src); |
| 1560 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1561 | case Primitive::kPrimVoid: |
| 1562 | LOG(FATAL) << "Unreachable type " << type; |
| 1563 | } |
| 1564 | } |
| 1565 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1566 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1567 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1568 | const MemOperand& src, |
| 1569 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1570 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1571 | BlockPoolsScope block_pools(masm); |
| 1572 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1573 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1574 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1575 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1576 | DCHECK(!src.IsPreIndex()); |
| 1577 | DCHECK(!src.IsPostIndex()); |
| 1578 | |
| 1579 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1580 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1581 | MemOperand base = MemOperand(temp_base); |
| 1582 | switch (type) { |
| 1583 | case Primitive::kPrimBoolean: |
| 1584 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1585 | if (needs_null_check) { |
| 1586 | MaybeRecordImplicitNullCheck(instruction); |
| 1587 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1588 | break; |
| 1589 | case Primitive::kPrimByte: |
| 1590 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1591 | if (needs_null_check) { |
| 1592 | MaybeRecordImplicitNullCheck(instruction); |
| 1593 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1594 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1595 | break; |
| 1596 | case Primitive::kPrimChar: |
| 1597 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1598 | if (needs_null_check) { |
| 1599 | MaybeRecordImplicitNullCheck(instruction); |
| 1600 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1601 | break; |
| 1602 | case Primitive::kPrimShort: |
| 1603 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1604 | if (needs_null_check) { |
| 1605 | MaybeRecordImplicitNullCheck(instruction); |
| 1606 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1607 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1608 | break; |
| 1609 | case Primitive::kPrimInt: |
| 1610 | case Primitive::kPrimNot: |
| 1611 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1612 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1613 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1614 | if (needs_null_check) { |
| 1615 | MaybeRecordImplicitNullCheck(instruction); |
| 1616 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1617 | break; |
| 1618 | case Primitive::kPrimFloat: |
| 1619 | case Primitive::kPrimDouble: { |
| 1620 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1621 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1622 | |
| 1623 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1624 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1625 | if (needs_null_check) { |
| 1626 | MaybeRecordImplicitNullCheck(instruction); |
| 1627 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1628 | __ Fmov(FPRegister(dst), temp); |
| 1629 | break; |
| 1630 | } |
| 1631 | case Primitive::kPrimVoid: |
| 1632 | LOG(FATAL) << "Unreachable type " << type; |
| 1633 | } |
| 1634 | } |
| 1635 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1636 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1637 | CPURegister src, |
| 1638 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1639 | switch (type) { |
| 1640 | case Primitive::kPrimBoolean: |
| 1641 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1642 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1643 | break; |
| 1644 | case Primitive::kPrimChar: |
| 1645 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1646 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1647 | break; |
| 1648 | case Primitive::kPrimInt: |
| 1649 | case Primitive::kPrimNot: |
| 1650 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1651 | case Primitive::kPrimFloat: |
| 1652 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1653 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1654 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1655 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1656 | case Primitive::kPrimVoid: |
| 1657 | LOG(FATAL) << "Unreachable type " << type; |
| 1658 | } |
| 1659 | } |
| 1660 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1661 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1662 | CPURegister src, |
| 1663 | const MemOperand& dst) { |
| 1664 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1665 | Register temp_base = temps.AcquireX(); |
| 1666 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1667 | DCHECK(!dst.IsPreIndex()); |
| 1668 | DCHECK(!dst.IsPostIndex()); |
| 1669 | |
| 1670 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1671 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1672 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1673 | MemOperand base = MemOperand(temp_base); |
| 1674 | switch (type) { |
| 1675 | case Primitive::kPrimBoolean: |
| 1676 | case Primitive::kPrimByte: |
| 1677 | __ Stlrb(Register(src), base); |
| 1678 | break; |
| 1679 | case Primitive::kPrimChar: |
| 1680 | case Primitive::kPrimShort: |
| 1681 | __ Stlrh(Register(src), base); |
| 1682 | break; |
| 1683 | case Primitive::kPrimInt: |
| 1684 | case Primitive::kPrimNot: |
| 1685 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1686 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1687 | __ Stlr(Register(src), base); |
| 1688 | break; |
| 1689 | case Primitive::kPrimFloat: |
| 1690 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1691 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1692 | Register temp_src; |
| 1693 | if (src.IsZero()) { |
| 1694 | // The zero register is used to avoid synthesizing zero constants. |
| 1695 | temp_src = Register(src); |
| 1696 | } else { |
| 1697 | DCHECK(src.IsFPRegister()); |
| 1698 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1699 | __ Fmov(temp_src, FPRegister(src)); |
| 1700 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1701 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1702 | __ Stlr(temp_src, base); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1703 | break; |
| 1704 | } |
| 1705 | case Primitive::kPrimVoid: |
| 1706 | LOG(FATAL) << "Unreachable type " << type; |
| 1707 | } |
| 1708 | } |
| 1709 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1710 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1711 | HInstruction* instruction, |
| 1712 | uint32_t dex_pc, |
| 1713 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1714 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1715 | GenerateInvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1716 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1717 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1718 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1721 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1722 | HInstruction* instruction, |
| 1723 | SlowPathCode* slow_path) { |
| 1724 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1725 | GenerateInvokeRuntime(entry_point_offset); |
| 1726 | } |
| 1727 | |
| 1728 | void CodeGeneratorARM64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1729 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 1730 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1731 | __ Blr(lr); |
| 1732 | } |
| 1733 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1734 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1735 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1736 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1737 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1738 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1739 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1740 | // 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] | 1741 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1742 | __ Add(temp, class_reg, status_offset); |
| 1743 | __ Ldar(temp, HeapOperand(temp)); |
| 1744 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1745 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1746 | __ Bind(slow_path->GetExitLabel()); |
| 1747 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1748 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1749 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1750 | BarrierType type = BarrierAll; |
| 1751 | |
| 1752 | switch (kind) { |
| 1753 | case MemBarrierKind::kAnyAny: |
| 1754 | case MemBarrierKind::kAnyStore: { |
| 1755 | type = BarrierAll; |
| 1756 | break; |
| 1757 | } |
| 1758 | case MemBarrierKind::kLoadAny: { |
| 1759 | type = BarrierReads; |
| 1760 | break; |
| 1761 | } |
| 1762 | case MemBarrierKind::kStoreStore: { |
| 1763 | type = BarrierWrites; |
| 1764 | break; |
| 1765 | } |
| 1766 | default: |
| 1767 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1768 | } |
| 1769 | __ Dmb(InnerShareable, type); |
| 1770 | } |
| 1771 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1772 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1773 | HBasicBlock* successor) { |
| 1774 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1775 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1776 | if (slow_path == nullptr) { |
| 1777 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1778 | instruction->SetSlowPath(slow_path); |
| 1779 | codegen_->AddSlowPath(slow_path); |
| 1780 | if (successor != nullptr) { |
| 1781 | DCHECK(successor->IsLoopHeader()); |
| 1782 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1783 | } |
| 1784 | } else { |
| 1785 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1786 | } |
| 1787 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1788 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1789 | Register temp = temps.AcquireW(); |
| 1790 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1791 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1792 | if (successor == nullptr) { |
| 1793 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1794 | __ Bind(slow_path->GetReturnLabel()); |
| 1795 | } else { |
| 1796 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1797 | __ B(slow_path->GetEntryLabel()); |
| 1798 | // slow_path will return to GetLabelOf(successor). |
| 1799 | } |
| 1800 | } |
| 1801 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1802 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1803 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1804 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1805 | assembler_(codegen->GetAssembler()), |
| 1806 | codegen_(codegen) {} |
| 1807 | |
| 1808 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1809 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1810 | |
| 1811 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1812 | |
| 1813 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1814 | // Using a base helps identify when we hit such breakpoints. |
| 1815 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1816 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1817 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1818 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1819 | }; |
| 1820 | |
| 1821 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1822 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1823 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1824 | } \ |
| 1825 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1826 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1827 | locations->SetOut(Location::Any()); \ |
| 1828 | } |
| 1829 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1830 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1831 | |
| 1832 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1833 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1834 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1835 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1836 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1837 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1838 | Primitive::Type type = instr->GetResultType(); |
| 1839 | switch (type) { |
| 1840 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1841 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1842 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1843 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1844 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1845 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1846 | |
| 1847 | case Primitive::kPrimFloat: |
| 1848 | case Primitive::kPrimDouble: |
| 1849 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1850 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1851 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1852 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1853 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1854 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1855 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1856 | } |
| 1857 | } |
| 1858 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1859 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1860 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1861 | |
| 1862 | bool object_field_get_with_read_barrier = |
| 1863 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1864 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1865 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1866 | object_field_get_with_read_barrier ? |
| 1867 | LocationSummary::kCallOnSlowPath : |
| 1868 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1869 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1870 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1871 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1873 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1874 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1875 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1876 | // The output overlaps for an object field get when read barriers |
| 1877 | // are enabled: we do not want the load to overwrite the object's |
| 1878 | // location, as we need it to emit the read barrier. |
| 1879 | locations->SetOut( |
| 1880 | Location::RequiresRegister(), |
| 1881 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1886 | const FieldInfo& field_info) { |
| 1887 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1888 | LocationSummary* locations = instruction->GetLocations(); |
| 1889 | Location base_loc = locations->InAt(0); |
| 1890 | Location out = locations->Out(); |
| 1891 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1892 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1893 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1894 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1895 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1896 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1897 | // Object FieldGet with Baker's read barrier case. |
| 1898 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1899 | UseScratchRegisterScope temps(masm); |
| 1900 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1901 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1902 | Register temp = temps.AcquireW(); |
| 1903 | // Note that potential implicit null checks are handled in this |
| 1904 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1905 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1906 | instruction, |
| 1907 | out, |
| 1908 | base, |
| 1909 | offset, |
| 1910 | temp, |
| 1911 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1912 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1913 | } else { |
| 1914 | // General case. |
| 1915 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1916 | // Note that a potential implicit null check is handled in this |
| 1917 | // CodeGeneratorARM64::LoadAcquire call. |
| 1918 | // NB: LoadAcquire will record the pc info if needed. |
| 1919 | codegen_->LoadAcquire( |
| 1920 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1921 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1922 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1923 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1924 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1925 | if (field_type == Primitive::kPrimNot) { |
| 1926 | // If read barriers are enabled, emit read barriers other than |
| 1927 | // Baker's using a slow path (and also unpoison the loaded |
| 1928 | // reference, if heap poisoning is enabled). |
| 1929 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1930 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1931 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1935 | LocationSummary* locations = |
| 1936 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1937 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1938 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 1939 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 1940 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1941 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1942 | } else { |
| 1943 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1948 | const FieldInfo& field_info, |
| 1949 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1950 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1951 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1952 | |
| 1953 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1954 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1955 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1956 | Offset offset = field_info.GetFieldOffset(); |
| 1957 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1958 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1959 | { |
| 1960 | // We use a block to end the scratch scope before the write barrier, thus |
| 1961 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1962 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1963 | |
| 1964 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1965 | DCHECK(value.IsW()); |
| 1966 | Register temp = temps.AcquireW(); |
| 1967 | __ Mov(temp, value.W()); |
| 1968 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1969 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1970 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1971 | |
| 1972 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1973 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1975 | } else { |
| 1976 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1977 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1978 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1982 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1986 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1987 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1988 | |
| 1989 | switch (type) { |
| 1990 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1991 | case Primitive::kPrimLong: { |
| 1992 | Register dst = OutputRegister(instr); |
| 1993 | Register lhs = InputRegisterAt(instr, 0); |
| 1994 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1995 | if (instr->IsAdd()) { |
| 1996 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1997 | } else if (instr->IsAnd()) { |
| 1998 | __ And(dst, lhs, rhs); |
| 1999 | } else if (instr->IsOr()) { |
| 2000 | __ Orr(dst, lhs, rhs); |
| 2001 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2002 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2003 | } else if (instr->IsRor()) { |
| 2004 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2005 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2006 | __ Ror(dst, lhs, shift); |
| 2007 | } else { |
| 2008 | // Ensure shift distance is in the same size register as the result. If |
| 2009 | // we are rotating a long and the shift comes in a w register originally, |
| 2010 | // we don't need to sxtw for use as an x since the shift distances are |
| 2011 | // all & reg_bits - 1. |
| 2012 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2013 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2014 | } else { |
| 2015 | DCHECK(instr->IsXor()); |
| 2016 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2017 | } |
| 2018 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2019 | } |
| 2020 | case Primitive::kPrimFloat: |
| 2021 | case Primitive::kPrimDouble: { |
| 2022 | FPRegister dst = OutputFPRegister(instr); |
| 2023 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2024 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2025 | if (instr->IsAdd()) { |
| 2026 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2027 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2028 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2029 | } else { |
| 2030 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2031 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2032 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2033 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2034 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2035 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2036 | } |
| 2037 | } |
| 2038 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2039 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2040 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2041 | |
| 2042 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2043 | Primitive::Type type = instr->GetResultType(); |
| 2044 | switch (type) { |
| 2045 | case Primitive::kPrimInt: |
| 2046 | case Primitive::kPrimLong: { |
| 2047 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2048 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2049 | locations->SetOut(Location::RequiresRegister()); |
| 2050 | break; |
| 2051 | } |
| 2052 | default: |
| 2053 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2058 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2059 | |
| 2060 | Primitive::Type type = instr->GetType(); |
| 2061 | switch (type) { |
| 2062 | case Primitive::kPrimInt: |
| 2063 | case Primitive::kPrimLong: { |
| 2064 | Register dst = OutputRegister(instr); |
| 2065 | Register lhs = InputRegisterAt(instr, 0); |
| 2066 | Operand rhs = InputOperandAt(instr, 1); |
| 2067 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2068 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2069 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2070 | if (instr->IsShl()) { |
| 2071 | __ Lsl(dst, lhs, shift_value); |
| 2072 | } else if (instr->IsShr()) { |
| 2073 | __ Asr(dst, lhs, shift_value); |
| 2074 | } else { |
| 2075 | __ Lsr(dst, lhs, shift_value); |
| 2076 | } |
| 2077 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2078 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2079 | |
| 2080 | if (instr->IsShl()) { |
| 2081 | __ Lsl(dst, lhs, rhs_reg); |
| 2082 | } else if (instr->IsShr()) { |
| 2083 | __ Asr(dst, lhs, rhs_reg); |
| 2084 | } else { |
| 2085 | __ Lsr(dst, lhs, rhs_reg); |
| 2086 | } |
| 2087 | } |
| 2088 | break; |
| 2089 | } |
| 2090 | default: |
| 2091 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2092 | } |
| 2093 | } |
| 2094 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2095 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2096 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2100 | HandleBinaryOp(instruction); |
| 2101 | } |
| 2102 | |
| 2103 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2104 | HandleBinaryOp(instruction); |
| 2105 | } |
| 2106 | |
| 2107 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2108 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2109 | } |
| 2110 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2111 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2112 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2113 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2115 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2116 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2117 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2118 | } |
| 2119 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2120 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2121 | Register dst = OutputRegister(instr); |
| 2122 | Register lhs = InputRegisterAt(instr, 0); |
| 2123 | Register rhs = InputRegisterAt(instr, 1); |
| 2124 | |
| 2125 | switch (instr->GetOpKind()) { |
| 2126 | case HInstruction::kAnd: |
| 2127 | __ Bic(dst, lhs, rhs); |
| 2128 | break; |
| 2129 | case HInstruction::kOr: |
| 2130 | __ Orn(dst, lhs, rhs); |
| 2131 | break; |
| 2132 | case HInstruction::kXor: |
| 2133 | __ Eon(dst, lhs, rhs); |
| 2134 | break; |
| 2135 | default: |
| 2136 | LOG(FATAL) << "Unreachable"; |
| 2137 | } |
| 2138 | } |
| 2139 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2140 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 2141 | HArm64DataProcWithShifterOp* instruction) { |
| 2142 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2143 | instruction->GetType() == Primitive::kPrimLong); |
| 2144 | LocationSummary* locations = |
| 2145 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2146 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2147 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2148 | } else { |
| 2149 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2150 | } |
| 2151 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2152 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2153 | } |
| 2154 | |
| 2155 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 2156 | HArm64DataProcWithShifterOp* instruction) { |
| 2157 | Primitive::Type type = instruction->GetType(); |
| 2158 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2159 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2160 | Register out = OutputRegister(instruction); |
| 2161 | Register left; |
| 2162 | if (kind != HInstruction::kNeg) { |
| 2163 | left = InputRegisterAt(instruction, 0); |
| 2164 | } |
| 2165 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 2166 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2167 | // conversion) can have a different type from the current instruction's type, |
| 2168 | // so we manually indicate the type. |
| 2169 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2170 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 2171 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2172 | |
| 2173 | Operand right_operand(0); |
| 2174 | |
| 2175 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2176 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 2177 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2178 | } else { |
| 2179 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 2180 | } |
| 2181 | |
| 2182 | // Logical binary operations do not support extension operations in the |
| 2183 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2184 | // the extension as a separate instruction. |
| 2185 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2186 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2187 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2188 | kind != HInstruction::kNeg)); |
| 2189 | switch (kind) { |
| 2190 | case HInstruction::kAdd: |
| 2191 | __ Add(out, left, right_operand); |
| 2192 | break; |
| 2193 | case HInstruction::kAnd: |
| 2194 | __ And(out, left, right_operand); |
| 2195 | break; |
| 2196 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2197 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2198 | __ Neg(out, right_operand); |
| 2199 | break; |
| 2200 | case HInstruction::kOr: |
| 2201 | __ Orr(out, left, right_operand); |
| 2202 | break; |
| 2203 | case HInstruction::kSub: |
| 2204 | __ Sub(out, left, right_operand); |
| 2205 | break; |
| 2206 | case HInstruction::kXor: |
| 2207 | __ Eor(out, left, right_operand); |
| 2208 | break; |
| 2209 | default: |
| 2210 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2211 | UNREACHABLE(); |
| 2212 | } |
| 2213 | } |
| 2214 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2215 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2216 | LocationSummary* locations = |
| 2217 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2218 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2219 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 2220 | locations->SetOut(Location::RequiresRegister()); |
| 2221 | } |
| 2222 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2223 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2224 | __ Add(OutputRegister(instruction), |
| 2225 | InputRegisterAt(instruction, 0), |
| 2226 | Operand(InputOperandAt(instruction, 1))); |
| 2227 | } |
| 2228 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2229 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2230 | LocationSummary* locations = |
| 2231 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2232 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2233 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2234 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2235 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2236 | // Don't allocate register for Mneg instruction. |
| 2237 | } else { |
| 2238 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2239 | Location::RequiresRegister()); |
| 2240 | } |
| 2241 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2242 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2243 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2244 | } |
| 2245 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2246 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2247 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2248 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2249 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2250 | |
| 2251 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2252 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2253 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2254 | if (instr->GetType() == Primitive::kPrimLong && |
| 2255 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2256 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2257 | vixl::aarch64::Instruction* prev = |
| 2258 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2259 | if (prev->IsLoadOrStore()) { |
| 2260 | // Make sure we emit only exactly one nop. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2261 | vixl::aarch64::CodeBufferCheckScope scope(masm, |
| 2262 | kInstructionSize, |
| 2263 | vixl::aarch64::CodeBufferCheckScope::kCheck, |
| 2264 | vixl::aarch64::CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2265 | __ nop(); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2270 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2271 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2272 | } else { |
| 2273 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2274 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2275 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2276 | __ Mneg(res, mul_left, mul_right); |
| 2277 | } else { |
| 2278 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2279 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2280 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2284 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2285 | bool object_array_get_with_read_barrier = |
| 2286 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2287 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2288 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2289 | object_array_get_with_read_barrier ? |
| 2290 | LocationSummary::kCallOnSlowPath : |
| 2291 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2292 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2293 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2294 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2296 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2297 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2298 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2299 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2300 | // The output overlaps in the case of an object array get with |
| 2301 | // read barriers enabled: we do not want the move to overwrite the |
| 2302 | // array's location, as we need it to emit the read barrier. |
| 2303 | locations->SetOut( |
| 2304 | Location::RequiresRegister(), |
| 2305 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2306 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2310 | Primitive::Type type = instruction->GetType(); |
| 2311 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2312 | LocationSummary* locations = instruction->GetLocations(); |
| 2313 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2314 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2315 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2316 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2317 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2318 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2319 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2320 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2321 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2322 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2323 | // The read barrier instrumentation of object ArrayGet instructions |
| 2324 | // does not support the HIntermediateAddress instruction. |
| 2325 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2326 | instruction->GetArray()->IsIntermediateAddress() && |
| 2327 | kEmitCompilerReadBarrier)); |
| 2328 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2329 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2330 | // Object ArrayGet with Baker's read barrier case. |
| 2331 | Register temp = temps.AcquireW(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2332 | // Note that a potential implicit null check is handled in the |
| 2333 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2334 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2335 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2336 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2337 | // General case. |
| 2338 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2339 | Register length; |
| 2340 | if (maybe_compressed_char_at) { |
| 2341 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2342 | length = temps.AcquireW(); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2343 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2344 | DCHECK_LT(count_offset, offset); |
| 2345 | int64_t adjusted_offset = static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2346 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2347 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2348 | } else { |
| 2349 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2350 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2351 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2352 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2353 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2354 | if (maybe_compressed_char_at) { |
| 2355 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2356 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2357 | "Expecting 0=compressed, 1=uncompressed"); |
| 2358 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2359 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2360 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2361 | __ B(&done); |
| 2362 | __ Bind(&uncompressed_load); |
| 2363 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2364 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2365 | __ Bind(&done); |
| 2366 | } else { |
| 2367 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2368 | source = HeapOperand(obj, offset); |
| 2369 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2370 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2371 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2372 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2373 | // We do not need to compute the intermediate address from the array: the |
| 2374 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2375 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2376 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2377 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2378 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2379 | } |
| 2380 | temp = obj; |
| 2381 | } else { |
| 2382 | __ Add(temp, obj, offset); |
| 2383 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2384 | if (maybe_compressed_char_at) { |
| 2385 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2386 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2387 | "Expecting 0=compressed, 1=uncompressed"); |
| 2388 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2389 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2390 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2391 | __ B(&done); |
| 2392 | __ Bind(&uncompressed_load); |
| 2393 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2394 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2395 | __ Bind(&done); |
| 2396 | } else { |
| 2397 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2398 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2399 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2400 | if (!maybe_compressed_char_at) { |
| 2401 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2403 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2404 | |
| 2405 | if (type == Primitive::kPrimNot) { |
| 2406 | static_assert( |
| 2407 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2408 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2409 | Location obj_loc = locations->InAt(0); |
| 2410 | if (index.IsConstant()) { |
| 2411 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2412 | } else { |
| 2413 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2414 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2415 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2416 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2419 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2420 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2421 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2422 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2426 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2427 | vixl::aarch64::Register out = OutputRegister(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2428 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2429 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2430 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2431 | // Mask out compression flag from String's array length. |
| 2432 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2433 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2434 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2435 | } |
| 2436 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2437 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2438 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2439 | |
| 2440 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2441 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2442 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2443 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2444 | LocationSummary::kCallOnSlowPath : |
| 2445 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2446 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2447 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2448 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2449 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2450 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2451 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2452 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2453 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2458 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2459 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2460 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2461 | bool needs_write_barrier = |
| 2462 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2463 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2464 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2465 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2466 | CPURegister source = value; |
| 2467 | Location index = locations->InAt(1); |
| 2468 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2469 | MemOperand destination = HeapOperand(array); |
| 2470 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2471 | BlockPoolsScope block_pools(masm); |
| 2472 | |
| 2473 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2474 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2475 | if (index.IsConstant()) { |
| 2476 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2477 | destination = HeapOperand(array, offset); |
| 2478 | } else { |
| 2479 | UseScratchRegisterScope temps(masm); |
| 2480 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2481 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2482 | // We do not need to compute the intermediate address from the array: the |
| 2483 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2484 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2485 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2486 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2487 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2488 | } |
| 2489 | temp = array; |
| 2490 | } else { |
| 2491 | __ Add(temp, array, offset); |
| 2492 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2493 | destination = HeapOperand(temp, |
| 2494 | XRegisterFrom(index), |
| 2495 | LSL, |
| 2496 | Primitive::ComponentSizeShift(value_type)); |
| 2497 | } |
| 2498 | codegen_->Store(value_type, value, destination); |
| 2499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2500 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2501 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2502 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2503 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2504 | { |
| 2505 | // We use a block to end the scratch scope before the write barrier, thus |
| 2506 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2507 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2508 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2509 | if (index.IsConstant()) { |
| 2510 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2511 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2512 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2513 | destination = HeapOperand(temp, |
| 2514 | XRegisterFrom(index), |
| 2515 | LSL, |
| 2516 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2517 | } |
| 2518 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2519 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2520 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2521 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2522 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2523 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2524 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2525 | codegen_->AddSlowPath(slow_path); |
| 2526 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2527 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2528 | __ Cbnz(Register(value), &non_zero); |
| 2529 | if (!index.IsConstant()) { |
| 2530 | __ Add(temp, array, offset); |
| 2531 | } |
| 2532 | __ Str(wzr, destination); |
| 2533 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2534 | __ B(&done); |
| 2535 | __ Bind(&non_zero); |
| 2536 | } |
| 2537 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2538 | // Note that when Baker read barriers are enabled, the type |
| 2539 | // checks are performed without read barriers. This is fine, |
| 2540 | // even in the case where a class object is in the from-space |
| 2541 | // after the flip, as a comparison involving such a type would |
| 2542 | // not produce a false positive; it may of course produce a |
| 2543 | // false negative, in which case we would take the ArraySet |
| 2544 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2545 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2546 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2547 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2548 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2549 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2550 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2551 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2552 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2553 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2554 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2555 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2556 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2557 | // nor `temp2`, as we are comparing two poisoned references. |
| 2558 | __ Cmp(temp, temp2); |
| 2559 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2560 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2561 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2562 | vixl::aarch64::Label do_put; |
| 2563 | __ B(eq, &do_put); |
| 2564 | // If heap poisoning is enabled, the `temp` reference has |
| 2565 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2566 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2567 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2568 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2569 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2570 | // If heap poisoning is enabled, no need to unpoison |
| 2571 | // `temp`, as we are comparing against null below. |
| 2572 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2573 | __ Bind(&do_put); |
| 2574 | } else { |
| 2575 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2580 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2581 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2582 | __ Mov(temp2, value.W()); |
| 2583 | GetAssembler()->PoisonHeapReference(temp2); |
| 2584 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | if (!index.IsConstant()) { |
| 2588 | __ Add(temp, array, offset); |
| 2589 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2590 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2591 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2592 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2593 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2594 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2595 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2596 | |
| 2597 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2598 | |
| 2599 | if (done.IsLinked()) { |
| 2600 | __ Bind(&done); |
| 2601 | } |
| 2602 | |
| 2603 | if (slow_path != nullptr) { |
| 2604 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2605 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2609 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2610 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2611 | InvokeRuntimeCallingConvention calling_convention; |
| 2612 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2613 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2614 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2615 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2616 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2620 | BoundsCheckSlowPathARM64* slow_path = |
| 2621 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2622 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2623 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2624 | __ B(slow_path->GetEntryLabel(), hs); |
| 2625 | } |
| 2626 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2627 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2628 | LocationSummary* locations = |
| 2629 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2631 | if (check->HasUses()) { |
| 2632 | locations->SetOut(Location::SameAsFirstInput()); |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2637 | // We assume the class is not null. |
| 2638 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2639 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2640 | codegen_->AddSlowPath(slow_path); |
| 2641 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2642 | } |
| 2643 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2644 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2645 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2646 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2647 | } |
| 2648 | |
| 2649 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2650 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2651 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2652 | if (rhs_loc.IsConstant()) { |
| 2653 | // 0.0 is the only immediate that can be encoded directly in |
| 2654 | // an FCMP instruction. |
| 2655 | // |
| 2656 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2657 | // specify that in a floating-point comparison, positive zero |
| 2658 | // and negative zero are considered equal, so we can use the |
| 2659 | // literal 0.0 for both cases here. |
| 2660 | // |
| 2661 | // Note however that some methods (Float.equal, Float.compare, |
| 2662 | // Float.compareTo, Double.equal, Double.compare, |
| 2663 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2664 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2665 | // -0.0. So if we ever translate calls to these methods into a |
| 2666 | // HCompare instruction, we must handle the -0.0 case with |
| 2667 | // care here. |
| 2668 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2669 | __ Fcmp(lhs_reg, 0.0); |
| 2670 | } else { |
| 2671 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2672 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2675 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2676 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2677 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2678 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2679 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimBoolean: |
| 2681 | case Primitive::kPrimByte: |
| 2682 | case Primitive::kPrimShort: |
| 2683 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2684 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2685 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2686 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2687 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2688 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2689 | break; |
| 2690 | } |
| 2691 | case Primitive::kPrimFloat: |
| 2692 | case Primitive::kPrimDouble: { |
| 2693 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2694 | locations->SetInAt(1, |
| 2695 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2696 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2697 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2698 | locations->SetOut(Location::RequiresRegister()); |
| 2699 | break; |
| 2700 | } |
| 2701 | default: |
| 2702 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2707 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2708 | |
| 2709 | // 0 if: left == right |
| 2710 | // 1 if: left > right |
| 2711 | // -1 if: left < right |
| 2712 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2713 | case Primitive::kPrimBoolean: |
| 2714 | case Primitive::kPrimByte: |
| 2715 | case Primitive::kPrimShort: |
| 2716 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2717 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimLong: { |
| 2719 | Register result = OutputRegister(compare); |
| 2720 | Register left = InputRegisterAt(compare, 0); |
| 2721 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2722 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2723 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2724 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2725 | break; |
| 2726 | } |
| 2727 | case Primitive::kPrimFloat: |
| 2728 | case Primitive::kPrimDouble: { |
| 2729 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2730 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2731 | __ Cset(result, ne); |
| 2732 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2733 | break; |
| 2734 | } |
| 2735 | default: |
| 2736 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2737 | } |
| 2738 | } |
| 2739 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2740 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2741 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2742 | |
| 2743 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2744 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2745 | locations->SetInAt(1, |
| 2746 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2747 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2748 | : Location::RequiresFpuRegister()); |
| 2749 | } else { |
| 2750 | // Integer cases. |
| 2751 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2752 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2753 | } |
| 2754 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2755 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2756 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2760 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2761 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2762 | return; |
| 2763 | } |
| 2764 | |
| 2765 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2766 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2767 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2768 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2769 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2770 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2771 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2772 | } else { |
| 2773 | // Integer cases. |
| 2774 | Register lhs = InputRegisterAt(instruction, 0); |
| 2775 | Operand rhs = InputOperandAt(instruction, 1); |
| 2776 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2777 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2778 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2782 | M(Equal) \ |
| 2783 | M(NotEqual) \ |
| 2784 | M(LessThan) \ |
| 2785 | M(LessThanOrEqual) \ |
| 2786 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2787 | M(GreaterThanOrEqual) \ |
| 2788 | M(Below) \ |
| 2789 | M(BelowOrEqual) \ |
| 2790 | M(Above) \ |
| 2791 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2792 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2793 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2794 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2795 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2796 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2797 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2798 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2799 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2800 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2801 | |
| 2802 | LocationSummary* locations = instruction->GetLocations(); |
| 2803 | Location second = locations->InAt(1); |
| 2804 | DCHECK(second.IsConstant()); |
| 2805 | |
| 2806 | Register out = OutputRegister(instruction); |
| 2807 | Register dividend = InputRegisterAt(instruction, 0); |
| 2808 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2809 | DCHECK(imm == 1 || imm == -1); |
| 2810 | |
| 2811 | if (instruction->IsRem()) { |
| 2812 | __ Mov(out, 0); |
| 2813 | } else { |
| 2814 | if (imm == 1) { |
| 2815 | __ Mov(out, dividend); |
| 2816 | } else { |
| 2817 | __ Neg(out, dividend); |
| 2818 | } |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2823 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2824 | |
| 2825 | LocationSummary* locations = instruction->GetLocations(); |
| 2826 | Location second = locations->InAt(1); |
| 2827 | DCHECK(second.IsConstant()); |
| 2828 | |
| 2829 | Register out = OutputRegister(instruction); |
| 2830 | Register dividend = InputRegisterAt(instruction, 0); |
| 2831 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2832 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2833 | int ctz_imm = CTZ(abs_imm); |
| 2834 | |
| 2835 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2836 | Register temp = temps.AcquireSameSizeAs(out); |
| 2837 | |
| 2838 | if (instruction->IsDiv()) { |
| 2839 | __ Add(temp, dividend, abs_imm - 1); |
| 2840 | __ Cmp(dividend, 0); |
| 2841 | __ Csel(out, temp, dividend, lt); |
| 2842 | if (imm > 0) { |
| 2843 | __ Asr(out, out, ctz_imm); |
| 2844 | } else { |
| 2845 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2846 | } |
| 2847 | } else { |
| 2848 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2849 | __ Asr(temp, dividend, bits - 1); |
| 2850 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2851 | __ Add(out, dividend, temp); |
| 2852 | __ And(out, out, abs_imm - 1); |
| 2853 | __ Sub(out, out, temp); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2858 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2859 | |
| 2860 | LocationSummary* locations = instruction->GetLocations(); |
| 2861 | Location second = locations->InAt(1); |
| 2862 | DCHECK(second.IsConstant()); |
| 2863 | |
| 2864 | Register out = OutputRegister(instruction); |
| 2865 | Register dividend = InputRegisterAt(instruction, 0); |
| 2866 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2867 | |
| 2868 | Primitive::Type type = instruction->GetResultType(); |
| 2869 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2870 | |
| 2871 | int64_t magic; |
| 2872 | int shift; |
| 2873 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2874 | |
| 2875 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2876 | Register temp = temps.AcquireSameSizeAs(out); |
| 2877 | |
| 2878 | // temp = get_high(dividend * magic) |
| 2879 | __ Mov(temp, magic); |
| 2880 | if (type == Primitive::kPrimLong) { |
| 2881 | __ Smulh(temp, dividend, temp); |
| 2882 | } else { |
| 2883 | __ Smull(temp.X(), dividend, temp); |
| 2884 | __ Lsr(temp.X(), temp.X(), 32); |
| 2885 | } |
| 2886 | |
| 2887 | if (imm > 0 && magic < 0) { |
| 2888 | __ Add(temp, temp, dividend); |
| 2889 | } else if (imm < 0 && magic > 0) { |
| 2890 | __ Sub(temp, temp, dividend); |
| 2891 | } |
| 2892 | |
| 2893 | if (shift != 0) { |
| 2894 | __ Asr(temp, temp, shift); |
| 2895 | } |
| 2896 | |
| 2897 | if (instruction->IsDiv()) { |
| 2898 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2899 | } else { |
| 2900 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2901 | // TODO: Strength reduction for msub. |
| 2902 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2903 | __ Mov(temp_imm, imm); |
| 2904 | __ Msub(out, temp, temp_imm, dividend); |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2909 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2910 | Primitive::Type type = instruction->GetResultType(); |
| 2911 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2912 | |
| 2913 | LocationSummary* locations = instruction->GetLocations(); |
| 2914 | Register out = OutputRegister(instruction); |
| 2915 | Location second = locations->InAt(1); |
| 2916 | |
| 2917 | if (second.IsConstant()) { |
| 2918 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2919 | |
| 2920 | if (imm == 0) { |
| 2921 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2922 | } else if (imm == 1 || imm == -1) { |
| 2923 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2924 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2925 | DivRemByPowerOfTwo(instruction); |
| 2926 | } else { |
| 2927 | DCHECK(imm <= -2 || imm >= 2); |
| 2928 | GenerateDivRemWithAnyConstant(instruction); |
| 2929 | } |
| 2930 | } else { |
| 2931 | Register dividend = InputRegisterAt(instruction, 0); |
| 2932 | Register divisor = InputRegisterAt(instruction, 1); |
| 2933 | if (instruction->IsDiv()) { |
| 2934 | __ Sdiv(out, dividend, divisor); |
| 2935 | } else { |
| 2936 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2937 | Register temp = temps.AcquireSameSizeAs(out); |
| 2938 | __ Sdiv(temp, dividend, divisor); |
| 2939 | __ Msub(out, temp, divisor, dividend); |
| 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2944 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2945 | LocationSummary* locations = |
| 2946 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2947 | switch (div->GetResultType()) { |
| 2948 | case Primitive::kPrimInt: |
| 2949 | case Primitive::kPrimLong: |
| 2950 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2951 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2952 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2953 | break; |
| 2954 | |
| 2955 | case Primitive::kPrimFloat: |
| 2956 | case Primitive::kPrimDouble: |
| 2957 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2958 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2959 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2960 | break; |
| 2961 | |
| 2962 | default: |
| 2963 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2968 | Primitive::Type type = div->GetResultType(); |
| 2969 | switch (type) { |
| 2970 | case Primitive::kPrimInt: |
| 2971 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2972 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2973 | break; |
| 2974 | |
| 2975 | case Primitive::kPrimFloat: |
| 2976 | case Primitive::kPrimDouble: |
| 2977 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2978 | break; |
| 2979 | |
| 2980 | default: |
| 2981 | LOG(FATAL) << "Unexpected div type " << type; |
| 2982 | } |
| 2983 | } |
| 2984 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2985 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2986 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2987 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2991 | SlowPathCodeARM64* slow_path = |
| 2992 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2993 | codegen_->AddSlowPath(slow_path); |
| 2994 | Location value = instruction->GetLocations()->InAt(0); |
| 2995 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2996 | Primitive::Type type = instruction->GetType(); |
| 2997 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2998 | if (!Primitive::IsIntegralType(type)) { |
| 2999 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3000 | return; |
| 3001 | } |
| 3002 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3003 | if (value.IsConstant()) { |
| 3004 | int64_t divisor = Int64ConstantFrom(value); |
| 3005 | if (divisor == 0) { |
| 3006 | __ B(slow_path->GetEntryLabel()); |
| 3007 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3008 | // A division by a non-null constant is valid. We don't need to perform |
| 3009 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3010 | } |
| 3011 | } else { |
| 3012 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3013 | } |
| 3014 | } |
| 3015 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3016 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3017 | LocationSummary* locations = |
| 3018 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3019 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3020 | } |
| 3021 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3022 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3023 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3024 | // Will be generated at use site. |
| 3025 | } |
| 3026 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3027 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3028 | exit->SetLocations(nullptr); |
| 3029 | } |
| 3030 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3031 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3032 | } |
| 3033 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3034 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3035 | LocationSummary* locations = |
| 3036 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3037 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3038 | } |
| 3039 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3040 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3041 | // Will be generated at use site. |
| 3042 | } |
| 3043 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3044 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3045 | DCHECK(!successor->IsExitBlock()); |
| 3046 | HBasicBlock* block = got->GetBlock(); |
| 3047 | HInstruction* previous = got->GetPrevious(); |
| 3048 | HLoopInformation* info = block->GetLoopInformation(); |
| 3049 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3050 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3051 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3052 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3053 | return; |
| 3054 | } |
| 3055 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3056 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3057 | } |
| 3058 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3059 | __ B(codegen_->GetLabelOf(successor)); |
| 3060 | } |
| 3061 | } |
| 3062 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3063 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3064 | got->SetLocations(nullptr); |
| 3065 | } |
| 3066 | |
| 3067 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3068 | HandleGoto(got, got->GetSuccessor()); |
| 3069 | } |
| 3070 | |
| 3071 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3072 | try_boundary->SetLocations(nullptr); |
| 3073 | } |
| 3074 | |
| 3075 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3076 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3077 | if (!successor->IsExitBlock()) { |
| 3078 | HandleGoto(try_boundary, successor); |
| 3079 | } |
| 3080 | } |
| 3081 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3082 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3083 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3084 | vixl::aarch64::Label* true_target, |
| 3085 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3086 | // FP branching requires both targets to be explicit. If either of the targets |
| 3087 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3088 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3089 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3090 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3091 | if (true_target == nullptr && false_target == nullptr) { |
| 3092 | // Nothing to do. The code always falls through. |
| 3093 | return; |
| 3094 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3095 | // Constant condition, statically compared against "true" (integer value 1). |
| 3096 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3097 | if (true_target != nullptr) { |
| 3098 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3099 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3100 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3101 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3102 | if (false_target != nullptr) { |
| 3103 | __ B(false_target); |
| 3104 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3105 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3106 | return; |
| 3107 | } |
| 3108 | |
| 3109 | // The following code generates these patterns: |
| 3110 | // (1) true_target == nullptr && false_target != nullptr |
| 3111 | // - opposite condition true => branch to false_target |
| 3112 | // (2) true_target != nullptr && false_target == nullptr |
| 3113 | // - condition true => branch to true_target |
| 3114 | // (3) true_target != nullptr && false_target != nullptr |
| 3115 | // - condition true => branch to true_target |
| 3116 | // - branch to false_target |
| 3117 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3118 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3119 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3120 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3121 | if (true_target == nullptr) { |
| 3122 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3123 | } else { |
| 3124 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3125 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3126 | } else { |
| 3127 | // The condition instruction has not been materialized, use its inputs as |
| 3128 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3129 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3130 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3131 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3132 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3133 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3134 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3135 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3136 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3137 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3138 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3139 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3140 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3141 | // Integer cases. |
| 3142 | Register lhs = InputRegisterAt(condition, 0); |
| 3143 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3144 | |
| 3145 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3146 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3147 | if (true_target == nullptr) { |
| 3148 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3149 | non_fallthrough_target = false_target; |
| 3150 | } else { |
| 3151 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3152 | non_fallthrough_target = true_target; |
| 3153 | } |
| 3154 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3155 | 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] | 3156 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3157 | switch (arm64_cond) { |
| 3158 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3159 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3160 | break; |
| 3161 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3162 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3163 | break; |
| 3164 | case lt: |
| 3165 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3166 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3167 | break; |
| 3168 | case ge: |
| 3169 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3170 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | default: |
| 3173 | // Without the `static_cast` the compiler throws an error for |
| 3174 | // `-Werror=sign-promo`. |
| 3175 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3176 | } |
| 3177 | } else { |
| 3178 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3179 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3180 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3181 | } |
| 3182 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3183 | |
| 3184 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3185 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3186 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3187 | __ B(false_target); |
| 3188 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3189 | |
| 3190 | if (fallthrough_target.IsLinked()) { |
| 3191 | __ Bind(&fallthrough_target); |
| 3192 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3193 | } |
| 3194 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3195 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3196 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3197 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3198 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3203 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3204 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3205 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3206 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3207 | true_target = nullptr; |
| 3208 | } |
| 3209 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3210 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3211 | false_target = nullptr; |
| 3212 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3213 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3217 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3218 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3219 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3220 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3221 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3222 | } |
| 3223 | } |
| 3224 | |
| 3225 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3226 | SlowPathCodeARM64* slow_path = |
| 3227 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3228 | GenerateTestAndBranch(deoptimize, |
| 3229 | /* condition_input_index */ 0, |
| 3230 | slow_path->GetEntryLabel(), |
| 3231 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3234 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3235 | return condition->IsCondition() && |
| 3236 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3237 | } |
| 3238 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3239 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3240 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3241 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3242 | : ARM64Condition(cond); |
| 3243 | } |
| 3244 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3245 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3246 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3247 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3248 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3249 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3250 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3251 | } else { |
| 3252 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3253 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3254 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3255 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3256 | // Ask VIXL whether we should synthesize constants in registers. |
| 3257 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3258 | Operand true_op = is_true_value_constant ? |
| 3259 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3260 | Operand false_op = is_false_value_constant ? |
| 3261 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3262 | bool true_value_in_register = false; |
| 3263 | bool false_value_in_register = false; |
| 3264 | MacroAssembler::GetCselSynthesisInformation( |
| 3265 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3266 | true_value_in_register |= !is_true_value_constant; |
| 3267 | false_value_in_register |= !is_false_value_constant; |
| 3268 | |
| 3269 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3270 | : Location::ConstantLocation(cst_true_value)); |
| 3271 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3272 | : Location::ConstantLocation(cst_false_value)); |
| 3273 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3274 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3275 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3276 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3277 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3278 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3282 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3283 | Condition csel_cond; |
| 3284 | |
| 3285 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3286 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3287 | // Use the condition flags set by the previous instruction. |
| 3288 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3289 | } else { |
| 3290 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3291 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3292 | } |
| 3293 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3294 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3295 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3296 | } else { |
| 3297 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3298 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3299 | } |
| 3300 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3301 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3302 | __ Fcsel(OutputFPRegister(select), |
| 3303 | InputFPRegisterAt(select, 1), |
| 3304 | InputFPRegisterAt(select, 0), |
| 3305 | csel_cond); |
| 3306 | } else { |
| 3307 | __ Csel(OutputRegister(select), |
| 3308 | InputOperandAt(select, 1), |
| 3309 | InputOperandAt(select, 0), |
| 3310 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3311 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3314 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3315 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3316 | } |
| 3317 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3318 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3319 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | void CodeGeneratorARM64::GenerateNop() { |
| 3323 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3326 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3327 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3331 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3335 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3339 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3342 | // Temp is used for read barrier. |
| 3343 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3344 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3345 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3346 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3347 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3348 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3349 | return 1; |
| 3350 | } |
| 3351 | return 0; |
| 3352 | } |
| 3353 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3354 | // 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] | 3355 | // interface pointer, one for loading the current interface. |
| 3356 | // The other checks have one temp for loading the object's class. |
| 3357 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3358 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3359 | return 3; |
| 3360 | } |
| 3361 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3364 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3365 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3366 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3367 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3368 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3369 | case TypeCheckKind::kExactCheck: |
| 3370 | case TypeCheckKind::kAbstractClassCheck: |
| 3371 | case TypeCheckKind::kClassHierarchyCheck: |
| 3372 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3373 | call_kind = |
| 3374 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3375 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3376 | break; |
| 3377 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3378 | case TypeCheckKind::kUnresolvedCheck: |
| 3379 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3380 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3381 | break; |
| 3382 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3383 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3384 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3385 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3386 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3387 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3388 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3389 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3390 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3391 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3392 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3393 | // Add temps if necessary for read barriers. |
| 3394 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3398 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3399 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3400 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3401 | Register obj = InputRegisterAt(instruction, 0); |
| 3402 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3403 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3404 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3405 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3406 | DCHECK_LE(num_temps, 1u); |
| 3407 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3408 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3409 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3410 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3411 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3412 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3413 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3414 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3415 | |
| 3416 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3417 | // Avoid null check if we know `obj` is not null. |
| 3418 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3419 | __ Cbz(obj, &zero); |
| 3420 | } |
| 3421 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3422 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3423 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3424 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3425 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3426 | out_loc, |
| 3427 | obj_loc, |
| 3428 | class_offset, |
| 3429 | maybe_temp_loc, |
| 3430 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3431 | __ Cmp(out, cls); |
| 3432 | __ Cset(out, eq); |
| 3433 | if (zero.IsLinked()) { |
| 3434 | __ B(&done); |
| 3435 | } |
| 3436 | break; |
| 3437 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3438 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3439 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3440 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3441 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3442 | out_loc, |
| 3443 | obj_loc, |
| 3444 | class_offset, |
| 3445 | maybe_temp_loc, |
| 3446 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3447 | // If the class is abstract, we eagerly fetch the super class of the |
| 3448 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3449 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3450 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3451 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3452 | GenerateReferenceLoadOneRegister(instruction, |
| 3453 | out_loc, |
| 3454 | super_offset, |
| 3455 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3456 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3457 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3458 | __ Cbz(out, &done); |
| 3459 | __ Cmp(out, cls); |
| 3460 | __ B(ne, &loop); |
| 3461 | __ Mov(out, 1); |
| 3462 | if (zero.IsLinked()) { |
| 3463 | __ B(&done); |
| 3464 | } |
| 3465 | break; |
| 3466 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3467 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3468 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3469 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3470 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3471 | out_loc, |
| 3472 | obj_loc, |
| 3473 | class_offset, |
| 3474 | maybe_temp_loc, |
| 3475 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3476 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3477 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3478 | __ Bind(&loop); |
| 3479 | __ Cmp(out, cls); |
| 3480 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3481 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3482 | GenerateReferenceLoadOneRegister(instruction, |
| 3483 | out_loc, |
| 3484 | super_offset, |
| 3485 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3486 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3487 | __ Cbnz(out, &loop); |
| 3488 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3489 | __ B(&done); |
| 3490 | __ Bind(&success); |
| 3491 | __ Mov(out, 1); |
| 3492 | if (zero.IsLinked()) { |
| 3493 | __ B(&done); |
| 3494 | } |
| 3495 | break; |
| 3496 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3497 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3498 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3499 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3500 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3501 | out_loc, |
| 3502 | obj_loc, |
| 3503 | class_offset, |
| 3504 | maybe_temp_loc, |
| 3505 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3506 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3507 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3508 | __ Cmp(out, cls); |
| 3509 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3510 | // 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] | 3511 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3512 | GenerateReferenceLoadOneRegister(instruction, |
| 3513 | out_loc, |
| 3514 | component_offset, |
| 3515 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3516 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3517 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3518 | __ Cbz(out, &done); |
| 3519 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3520 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3521 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3522 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3523 | __ Mov(out, 1); |
| 3524 | __ B(&done); |
| 3525 | break; |
| 3526 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3527 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3528 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3529 | // No read barrier since the slow path will retry upon failure. |
| 3530 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3531 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3532 | out_loc, |
| 3533 | obj_loc, |
| 3534 | class_offset, |
| 3535 | maybe_temp_loc, |
| 3536 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3537 | __ Cmp(out, cls); |
| 3538 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3539 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3540 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3541 | codegen_->AddSlowPath(slow_path); |
| 3542 | __ B(ne, slow_path->GetEntryLabel()); |
| 3543 | __ Mov(out, 1); |
| 3544 | if (zero.IsLinked()) { |
| 3545 | __ B(&done); |
| 3546 | } |
| 3547 | break; |
| 3548 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3549 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3550 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3551 | case TypeCheckKind::kInterfaceCheck: { |
| 3552 | // Note that we indeed only call on slow path, but we always go |
| 3553 | // into the slow path for the unresolved and interface check |
| 3554 | // cases. |
| 3555 | // |
| 3556 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3557 | // entry point without resorting to a type checking slow path |
| 3558 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3559 | // require to assign fixed registers for the inputs of this |
| 3560 | // HInstanceOf instruction (following the runtime calling |
| 3561 | // convention), which might be cluttered by the potential first |
| 3562 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3563 | // |
| 3564 | // TODO: Introduce a new runtime entry point taking the object |
| 3565 | // to test (instead of its class) as argument, and let it deal |
| 3566 | // with the read barrier issues. This will let us refactor this |
| 3567 | // case of the `switch` code as it was previously (with a direct |
| 3568 | // call to the runtime not using a type checking slow path). |
| 3569 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3570 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3571 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3572 | /* is_fatal */ false); |
| 3573 | codegen_->AddSlowPath(slow_path); |
| 3574 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3575 | if (zero.IsLinked()) { |
| 3576 | __ B(&done); |
| 3577 | } |
| 3578 | break; |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | if (zero.IsLinked()) { |
| 3583 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3584 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | if (done.IsLinked()) { |
| 3588 | __ Bind(&done); |
| 3589 | } |
| 3590 | |
| 3591 | if (slow_path != nullptr) { |
| 3592 | __ Bind(slow_path->GetExitLabel()); |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3597 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3598 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3599 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3600 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3601 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3602 | case TypeCheckKind::kExactCheck: |
| 3603 | case TypeCheckKind::kAbstractClassCheck: |
| 3604 | case TypeCheckKind::kClassHierarchyCheck: |
| 3605 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3606 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3607 | LocationSummary::kCallOnSlowPath : |
| 3608 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3609 | break; |
| 3610 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3611 | case TypeCheckKind::kUnresolvedCheck: |
| 3612 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3613 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3614 | break; |
| 3615 | } |
| 3616 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3617 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3619 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3620 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 3621 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3625 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3626 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3627 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3628 | Register obj = InputRegisterAt(instruction, 0); |
| 3629 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3630 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3631 | DCHECK_GE(num_temps, 1u); |
| 3632 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3633 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3634 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 3635 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3636 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3637 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3638 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3639 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3640 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3641 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3642 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3643 | const uint32_t object_array_data_offset = |
| 3644 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3645 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3646 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3647 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3648 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3649 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3650 | if (!kEmitCompilerReadBarrier) { |
| 3651 | is_type_check_slow_path_fatal = |
| 3652 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3653 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3654 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3655 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3656 | !instruction->CanThrowIntoCatchBlock(); |
| 3657 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3658 | SlowPathCodeARM64* type_check_slow_path = |
| 3659 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3660 | is_type_check_slow_path_fatal); |
| 3661 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3662 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3663 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3664 | // Avoid null check if we know obj is not null. |
| 3665 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3666 | __ Cbz(obj, &done); |
| 3667 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3668 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3669 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3670 | case TypeCheckKind::kExactCheck: |
| 3671 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3672 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3673 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3674 | temp_loc, |
| 3675 | obj_loc, |
| 3676 | class_offset, |
| 3677 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3678 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3679 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3680 | __ Cmp(temp, cls); |
| 3681 | // Jump to slow path for throwing the exception or doing a |
| 3682 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3683 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3684 | break; |
| 3685 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3686 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3687 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3688 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3689 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3690 | temp_loc, |
| 3691 | obj_loc, |
| 3692 | class_offset, |
| 3693 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3694 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3695 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3696 | // If the class is abstract, we eagerly fetch the super class of the |
| 3697 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3698 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3699 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3700 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3701 | GenerateReferenceLoadOneRegister(instruction, |
| 3702 | temp_loc, |
| 3703 | super_offset, |
| 3704 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3705 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3706 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3707 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3708 | // exception. |
| 3709 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3710 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3711 | __ Cmp(temp, cls); |
| 3712 | __ B(ne, &loop); |
| 3713 | break; |
| 3714 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3715 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3716 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3717 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3718 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3719 | temp_loc, |
| 3720 | obj_loc, |
| 3721 | class_offset, |
| 3722 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3723 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3724 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3725 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3726 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3727 | __ Bind(&loop); |
| 3728 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3729 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3730 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3731 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3732 | GenerateReferenceLoadOneRegister(instruction, |
| 3733 | temp_loc, |
| 3734 | super_offset, |
| 3735 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3736 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3737 | |
| 3738 | // If the class reference currently in `temp` is not null, jump |
| 3739 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3740 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3741 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3742 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3743 | break; |
| 3744 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3745 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3746 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3747 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3748 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3749 | temp_loc, |
| 3750 | obj_loc, |
| 3751 | class_offset, |
| 3752 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3753 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3754 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3755 | // Do an exact check. |
| 3756 | __ Cmp(temp, cls); |
| 3757 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3758 | |
| 3759 | // 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] | 3760 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3761 | GenerateReferenceLoadOneRegister(instruction, |
| 3762 | temp_loc, |
| 3763 | component_offset, |
| 3764 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3765 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3766 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3767 | // If the component type is null, jump to the slow path to throw the exception. |
| 3768 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3769 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 3770 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3771 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3772 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3773 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3774 | break; |
| 3775 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3776 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3777 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3778 | // 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] | 3779 | // |
| 3780 | // We cannot directly call the CheckCast runtime entry point |
| 3781 | // without resorting to a type checking slow path here (i.e. by |
| 3782 | // calling InvokeRuntime directly), as it would require to |
| 3783 | // assign fixed registers for the inputs of this HInstanceOf |
| 3784 | // instruction (following the runtime calling convention), which |
| 3785 | // might be cluttered by the potential first read barrier |
| 3786 | // emission at the beginning of this method. |
| 3787 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3788 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3789 | case TypeCheckKind::kInterfaceCheck: { |
| 3790 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3791 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3792 | temp_loc, |
| 3793 | obj_loc, |
| 3794 | class_offset, |
| 3795 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3796 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3797 | |
| 3798 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 3799 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3800 | temp_loc, |
| 3801 | temp_loc, |
| 3802 | iftable_offset, |
| 3803 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3804 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame^] | 3805 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3806 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame^] | 3807 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3808 | vixl::aarch64::Label start_loop; |
| 3809 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 3810 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3811 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 3812 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3813 | // Go to next interface. |
| 3814 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 3815 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 3816 | // Compare the classes and continue the loop if they do not match. |
| 3817 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 3818 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3819 | break; |
| 3820 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3821 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3822 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3823 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3824 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3827 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3828 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3829 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3830 | } |
| 3831 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3832 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3833 | // Will be generated at use site. |
| 3834 | } |
| 3835 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3836 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3837 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3838 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3839 | } |
| 3840 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3841 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3842 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3845 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3846 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3847 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3848 | // the method_idx. |
| 3849 | HandleInvoke(invoke); |
| 3850 | } |
| 3851 | |
| 3852 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3853 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3854 | } |
| 3855 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3856 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3857 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3858 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3859 | } |
| 3860 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3861 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3862 | HandleInvoke(invoke); |
| 3863 | } |
| 3864 | |
| 3865 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3866 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3867 | LocationSummary* locations = invoke->GetLocations(); |
| 3868 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3869 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3870 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3871 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3872 | |
| 3873 | // The register ip1 is required to be used for the hidden argument in |
| 3874 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3875 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3876 | UseScratchRegisterScope scratch_scope(masm); |
| 3877 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3878 | scratch_scope.Exclude(ip1); |
| 3879 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3880 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3881 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3882 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3883 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3884 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3885 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3886 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3887 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3888 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3889 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3890 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3891 | // emit a read barrier for the previous class reference load. |
| 3892 | // However this is not required in practice, as this is an |
| 3893 | // intermediate/temporary reference and because the current |
| 3894 | // concurrent copying collector keeps the from-space memory |
| 3895 | // intact/accessible until the end of the marking phase (the |
| 3896 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3897 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3898 | __ Ldr(temp, |
| 3899 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3900 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3901 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3902 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3903 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3904 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3905 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3906 | // lr(); |
| 3907 | __ Blr(lr); |
| 3908 | DCHECK(!codegen_->IsLeafMethod()); |
| 3909 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3910 | } |
| 3911 | |
| 3912 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3913 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3914 | if (intrinsic.TryDispatch(invoke)) { |
| 3915 | return; |
| 3916 | } |
| 3917 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3918 | HandleInvoke(invoke); |
| 3919 | } |
| 3920 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3921 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3922 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3923 | // art::PrepareForRegisterAllocation. |
| 3924 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3925 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3926 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3927 | if (intrinsic.TryDispatch(invoke)) { |
| 3928 | return; |
| 3929 | } |
| 3930 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3931 | HandleInvoke(invoke); |
| 3932 | } |
| 3933 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3934 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3935 | if (invoke->GetLocations()->Intrinsified()) { |
| 3936 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3937 | intrinsic.Dispatch(invoke); |
| 3938 | return true; |
| 3939 | } |
| 3940 | return false; |
| 3941 | } |
| 3942 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3943 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3944 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3945 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3946 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3947 | return desired_dispatch_info; |
| 3948 | } |
| 3949 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3950 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3951 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3952 | bool direct_code_loaded = false; |
| 3953 | switch (invoke->GetCodePtrLocation()) { |
| 3954 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3955 | // LR = code address from literal pool with link-time patch. |
| 3956 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3957 | direct_code_loaded = true; |
| 3958 | break; |
| 3959 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3960 | // LR = invoke->GetDirectCodePtr(); |
| 3961 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3962 | direct_code_loaded = true; |
| 3963 | break; |
| 3964 | default: |
| 3965 | break; |
| 3966 | } |
| 3967 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3968 | // 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] | 3969 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3970 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3971 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 3972 | uint32_t offset = |
| 3973 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3974 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3975 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3976 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3977 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3978 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3979 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3980 | break; |
| 3981 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3982 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3983 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3984 | break; |
| 3985 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3986 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3987 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3988 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3989 | break; |
| 3990 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3991 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3992 | const DexFile& dex_file = invoke->GetDexFile(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3993 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3994 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3995 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3996 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3997 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3998 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3999 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4000 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4001 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4002 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4003 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4004 | Register reg = XRegisterFrom(temp); |
| 4005 | Register method_reg; |
| 4006 | if (current_method.IsRegister()) { |
| 4007 | method_reg = XRegisterFrom(current_method); |
| 4008 | } else { |
| 4009 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4010 | DCHECK(!current_method.IsValid()); |
| 4011 | method_reg = reg; |
| 4012 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 4013 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 4014 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4015 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4016 | __ Ldr(reg.X(), |
| 4017 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4018 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4019 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4020 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4021 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4022 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 4023 | break; |
| 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | switch (invoke->GetCodePtrLocation()) { |
| 4028 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4029 | __ Bl(&frame_entry_label_); |
| 4030 | break; |
| 4031 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4032 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4033 | invoke->GetTargetMethod().dex_method_index); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4034 | vixl::aarch64::Label* label = &relative_call_patches_.back().label; |
| 4035 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4036 | __ Bind(label); |
| 4037 | __ bl(0); // Branch and link to itself. This will be overriden at link time. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4038 | break; |
| 4039 | } |
| 4040 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4041 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4042 | // LR prepared above for better instruction scheduling. |
| 4043 | DCHECK(direct_code_loaded); |
| 4044 | // lr() |
| 4045 | __ Blr(lr); |
| 4046 | break; |
| 4047 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4048 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4049 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4050 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4051 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4052 | // lr() |
| 4053 | __ Blr(lr); |
| 4054 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4055 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4056 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4057 | DCHECK(!IsLeafMethod()); |
| 4058 | } |
| 4059 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4060 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4061 | // Use the calling convention instead of the location of the receiver, as |
| 4062 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4063 | // slow path, the arguments have been moved to the right place, so here we are |
| 4064 | // guaranteed that the receiver is the first register of the calling convention. |
| 4065 | InvokeDexCallingConvention calling_convention; |
| 4066 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4067 | Register temp = XRegisterFrom(temp_in); |
| 4068 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4069 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4070 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4071 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4072 | |
| 4073 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4074 | |
| 4075 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4076 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4077 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4078 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4079 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4080 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4081 | // intermediate/temporary reference and because the current |
| 4082 | // concurrent copying collector keeps the from-space memory |
| 4083 | // intact/accessible until the end of the marking phase (the |
| 4084 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4085 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4086 | // temp = temp->GetMethodAt(method_offset); |
| 4087 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4088 | // lr = temp->GetEntryPoint(); |
| 4089 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 4090 | // lr(); |
| 4091 | __ Blr(lr); |
| 4092 | } |
| 4093 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4094 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4095 | const DexFile& dex_file, |
| 4096 | uint32_t string_index, |
| 4097 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4098 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 4099 | } |
| 4100 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4101 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4102 | const DexFile& dex_file, |
| 4103 | uint32_t type_index, |
| 4104 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4105 | return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_); |
| 4106 | } |
| 4107 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4108 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4109 | const DexFile& dex_file, |
| 4110 | uint32_t element_offset, |
| 4111 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4112 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4113 | } |
| 4114 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4115 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4116 | const DexFile& dex_file, |
| 4117 | uint32_t offset_or_index, |
| 4118 | vixl::aarch64::Label* adrp_label, |
| 4119 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4120 | // Add a patch entry and return the label. |
| 4121 | patches->emplace_back(dex_file, offset_or_index); |
| 4122 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4123 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4124 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4125 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4126 | return label; |
| 4127 | } |
| 4128 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4129 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4130 | const DexFile& dex_file, uint32_t string_index) { |
| 4131 | return boot_image_string_patches_.GetOrCreate( |
| 4132 | StringReference(&dex_file, string_index), |
| 4133 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4134 | } |
| 4135 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4136 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4137 | const DexFile& dex_file, uint32_t type_index) { |
| 4138 | return boot_image_type_patches_.GetOrCreate( |
| 4139 | TypeReference(&dex_file, type_index), |
| 4140 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4141 | } |
| 4142 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4143 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4144 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4145 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 4146 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 4147 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 4148 | } |
| 4149 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4150 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral( |
| 4151 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4152 | return DeduplicateUint64Literal(address); |
| 4153 | } |
| 4154 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4155 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4156 | vixl::aarch64::Register reg) { |
| 4157 | DCHECK(reg.IsX()); |
| 4158 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4159 | __ Bind(fixup_label); |
| 4160 | __ adrp(reg, /* offset placeholder */ 0); |
| 4161 | } |
| 4162 | |
| 4163 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4164 | vixl::aarch64::Register out, |
| 4165 | vixl::aarch64::Register base) { |
| 4166 | DCHECK(out.IsX()); |
| 4167 | DCHECK(base.IsX()); |
| 4168 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4169 | __ Bind(fixup_label); |
| 4170 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4171 | } |
| 4172 | |
| 4173 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4174 | vixl::aarch64::Register out, |
| 4175 | vixl::aarch64::Register base) { |
| 4176 | DCHECK(base.IsX()); |
| 4177 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4178 | __ Bind(fixup_label); |
| 4179 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4180 | } |
| 4181 | |
| 4182 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4183 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4184 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4185 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4186 | for (const PcRelativePatchInfo& info : infos) { |
| 4187 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4188 | &info.target_dex_file, |
| 4189 | info.pc_insn_label->GetLocation(), |
| 4190 | info.offset_or_index)); |
| 4191 | } |
| 4192 | } |
| 4193 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4194 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4195 | DCHECK(linker_patches->empty()); |
| 4196 | size_t size = |
| 4197 | method_patches_.size() + |
| 4198 | call_patches_.size() + |
| 4199 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4200 | pc_relative_dex_cache_patches_.size() + |
| 4201 | boot_image_string_patches_.size() + |
| 4202 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4203 | boot_image_type_patches_.size() + |
| 4204 | pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4205 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4206 | linker_patches->reserve(size); |
| 4207 | for (const auto& entry : method_patches_) { |
| 4208 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4209 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 4210 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4211 | target_method.dex_file, |
| 4212 | target_method.dex_method_index)); |
| 4213 | } |
| 4214 | for (const auto& entry : call_patches_) { |
| 4215 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4216 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 4217 | linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4218 | target_method.dex_file, |
| 4219 | target_method.dex_method_index)); |
| 4220 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4221 | for (const PatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) { |
| 4222 | linker_patches->push_back( |
| 4223 | LinkerPatch::RelativeCodePatch(info.label.GetLocation(), &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4224 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4225 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4226 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4227 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4228 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4229 | info.offset_or_index)); |
| 4230 | } |
| 4231 | for (const auto& entry : boot_image_string_patches_) { |
| 4232 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4233 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4234 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4235 | target_string.dex_file, |
| 4236 | target_string.string_index)); |
| 4237 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4238 | if (!GetCompilerOptions().IsBootImage()) { |
| 4239 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4240 | linker_patches); |
| 4241 | } else { |
| 4242 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4243 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4244 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4245 | for (const auto& entry : boot_image_type_patches_) { |
| 4246 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4247 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4248 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4249 | target_type.dex_file, |
| 4250 | target_type.type_index)); |
| 4251 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4252 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4253 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4254 | for (const auto& entry : boot_image_address_patches_) { |
| 4255 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4256 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4257 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4258 | } |
| 4259 | } |
| 4260 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4261 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4262 | Uint32ToLiteralMap* map) { |
| 4263 | return map->GetOrCreate( |
| 4264 | value, |
| 4265 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4266 | } |
| 4267 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4268 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4269 | return uint64_literals_.GetOrCreate( |
| 4270 | value, |
| 4271 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4274 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4275 | MethodReference target_method, |
| 4276 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4277 | return map->GetOrCreate( |
| 4278 | target_method, |
| 4279 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4282 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4283 | MethodReference target_method) { |
| 4284 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 4285 | } |
| 4286 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4287 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4288 | MethodReference target_method) { |
| 4289 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 4290 | } |
| 4291 | |
| 4292 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4293 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4294 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4295 | // art::PrepareForRegisterAllocation. |
| 4296 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4297 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4298 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4299 | return; |
| 4300 | } |
| 4301 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4302 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4303 | LocationSummary* locations = invoke->GetLocations(); |
| 4304 | codegen_->GenerateStaticOrDirectCall( |
| 4305 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4306 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4310 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4311 | return; |
| 4312 | } |
| 4313 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4314 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4315 | DCHECK(!codegen_->IsLeafMethod()); |
| 4316 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4317 | } |
| 4318 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4319 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4320 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4321 | switch (desired_class_load_kind) { |
| 4322 | case HLoadClass::LoadKind::kReferrersClass: |
| 4323 | break; |
| 4324 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4325 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4326 | break; |
| 4327 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4328 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4329 | break; |
| 4330 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4331 | break; |
| 4332 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 4333 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4334 | break; |
| 4335 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 4336 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4337 | break; |
| 4338 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4339 | break; |
| 4340 | } |
| 4341 | return desired_class_load_kind; |
| 4342 | } |
| 4343 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4344 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4345 | if (cls->NeedsAccessCheck()) { |
| 4346 | InvokeRuntimeCallingConvention calling_convention; |
| 4347 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4348 | cls, |
| 4349 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4350 | LocationFrom(vixl::aarch64::x0), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4351 | /* code_generator_supports_read_barrier */ true); |
| 4352 | return; |
| 4353 | } |
| 4354 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4355 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4356 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4357 | ? LocationSummary::kCallOnSlowPath |
| 4358 | : LocationSummary::kNoCall; |
| 4359 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4360 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4361 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4362 | } |
| 4363 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4364 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4365 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 4366 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4367 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4368 | } |
| 4369 | locations->SetOut(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4373 | if (cls->NeedsAccessCheck()) { |
| 4374 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4375 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4376 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4377 | return; |
| 4378 | } |
| 4379 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4380 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4381 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4382 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4383 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4384 | ? kWithoutReadBarrier |
| 4385 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4386 | bool generate_null_check = false; |
| 4387 | switch (cls->GetLoadKind()) { |
| 4388 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4389 | DCHECK(!cls->CanCallRuntime()); |
| 4390 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4391 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4392 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4393 | GenerateGcRootFieldLoad(cls, |
| 4394 | out_loc, |
| 4395 | current_method, |
| 4396 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4397 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4398 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4399 | break; |
| 4400 | } |
| 4401 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4402 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4403 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4404 | cls->GetTypeIndex())); |
| 4405 | break; |
| 4406 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4407 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4408 | // Add ADRP with its PC-relative type patch. |
| 4409 | const DexFile& dex_file = cls->GetDexFile(); |
| 4410 | uint32_t type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4411 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4412 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4413 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4414 | vixl::aarch64::Label* add_label = |
| 4415 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4416 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4417 | break; |
| 4418 | } |
| 4419 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4420 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4421 | DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress())); |
| 4422 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress())); |
| 4423 | break; |
| 4424 | } |
| 4425 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 4426 | DCHECK_NE(cls->GetAddress(), 0u); |
| 4427 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4428 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4429 | // multiple types, simply split the dex cache address to a 16KiB aligned base |
| 4430 | // loaded from a literal and the remaining offset embedded in the load. |
| 4431 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 4432 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 4433 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4434 | uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4435 | uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4436 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4437 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4438 | GenerateGcRootFieldLoad(cls, |
| 4439 | out_loc, |
| 4440 | out.X(), |
| 4441 | offset, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4442 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4443 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4444 | generate_null_check = !cls->IsInDexCache(); |
| 4445 | break; |
| 4446 | } |
| 4447 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 4448 | // Add ADRP with its PC-relative DexCache access patch. |
| 4449 | const DexFile& dex_file = cls->GetDexFile(); |
| 4450 | uint32_t element_offset = cls->GetDexCacheElementOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4451 | vixl::aarch64::Label* adrp_label = |
| 4452 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4453 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4454 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4455 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4456 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4457 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4458 | GenerateGcRootFieldLoad(cls, |
| 4459 | out_loc, |
| 4460 | out.X(), |
| 4461 | /* offset placeholder */ 0, |
| 4462 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4463 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4464 | generate_null_check = !cls->IsInDexCache(); |
| 4465 | break; |
| 4466 | } |
| 4467 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 4468 | MemberOffset resolved_types_offset = |
| 4469 | ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 4470 | // /* GcRoot<mirror::Class>[] */ out = |
| 4471 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 4472 | Register current_method = InputRegisterAt(cls, 0); |
| 4473 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 4474 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4475 | GenerateGcRootFieldLoad(cls, |
| 4476 | out_loc, |
| 4477 | out.X(), |
| 4478 | CodeGenerator::GetCacheOffset(cls->GetTypeIndex()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4479 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4480 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4481 | generate_null_check = !cls->IsInDexCache(); |
| 4482 | break; |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 4487 | DCHECK(cls->CanCallRuntime()); |
| 4488 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 4489 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4490 | codegen_->AddSlowPath(slow_path); |
| 4491 | if (generate_null_check) { |
| 4492 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4493 | } |
| 4494 | if (cls->MustGenerateClinitCheck()) { |
| 4495 | GenerateClassInitializationCheck(slow_path, out); |
| 4496 | } else { |
| 4497 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4498 | } |
| 4499 | } |
| 4500 | } |
| 4501 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4502 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4503 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4506 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4507 | LocationSummary* locations = |
| 4508 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4509 | locations->SetOut(Location::RequiresRegister()); |
| 4510 | } |
| 4511 | |
| 4512 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4513 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4514 | } |
| 4515 | |
| 4516 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4517 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4518 | } |
| 4519 | |
| 4520 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4521 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4522 | } |
| 4523 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4524 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4525 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4526 | switch (desired_string_load_kind) { |
| 4527 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4528 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4529 | break; |
| 4530 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4531 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4532 | break; |
| 4533 | case HLoadString::LoadKind::kBootImageAddress: |
| 4534 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4535 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4536 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4537 | break; |
| 4538 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4539 | break; |
| 4540 | } |
| 4541 | return desired_string_load_kind; |
| 4542 | } |
| 4543 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4544 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 4545 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
| 4546 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 4547 | ? LocationSummary::kCallOnMainOnly |
| 4548 | : LocationSummary::kCallOnSlowPath) |
| 4549 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4550 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4551 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4552 | InvokeRuntimeCallingConvention calling_convention; |
| 4553 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4554 | } else { |
| 4555 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4556 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4557 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4558 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 4559 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4560 | InvokeRuntimeCallingConvention calling_convention; |
| 4561 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4562 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4563 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4564 | Primitive::kPrimNot).GetCode()); |
| 4565 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4566 | } else { |
| 4567 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4568 | } |
| 4569 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4570 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4574 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4575 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4576 | switch (load->GetLoadKind()) { |
| 4577 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4578 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4579 | load->GetStringIndex())); |
| 4580 | return; // No dex cache slow path. |
| 4581 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4582 | // Add ADRP with its PC-relative String patch. |
| 4583 | const DexFile& dex_file = load->GetDexFile(); |
| 4584 | uint32_t string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4585 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4586 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4587 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4588 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4589 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4590 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4591 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4592 | return; // No dex cache slow path. |
| 4593 | } |
| 4594 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4595 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4596 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4597 | return; // No dex cache slow path. |
| 4598 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4599 | case HLoadString::LoadKind::kBssEntry: { |
| 4600 | // Add ADRP with its PC-relative String .bss entry patch. |
| 4601 | const DexFile& dex_file = load->GetDexFile(); |
| 4602 | uint32_t string_index = load->GetStringIndex(); |
| 4603 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4604 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4605 | Register temp = temps.AcquireX(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4606 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4607 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4608 | // Add LDR with its PC-relative String patch. |
| 4609 | vixl::aarch64::Label* ldr_label = |
| 4610 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 4611 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4612 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 4613 | load->GetLocations()->Out(), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4614 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4615 | /* offset placeholder */ 0u, |
| 4616 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4617 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4618 | SlowPathCodeARM64* slow_path = |
| 4619 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4620 | codegen_->AddSlowPath(slow_path); |
| 4621 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 4622 | __ Bind(slow_path->GetExitLabel()); |
| 4623 | return; |
| 4624 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4625 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4626 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4627 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4628 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4629 | // 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] | 4630 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4631 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4632 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex()); |
| 4633 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 4634 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4637 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4638 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4639 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4640 | } |
| 4641 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4642 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4643 | // Will be generated at use site. |
| 4644 | } |
| 4645 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4646 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4647 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4648 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4649 | InvokeRuntimeCallingConvention calling_convention; |
| 4650 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4651 | } |
| 4652 | |
| 4653 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4654 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject: kQuickUnlockObject, |
| 4655 | instruction, |
| 4656 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4657 | if (instruction->IsEnter()) { |
| 4658 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4659 | } else { |
| 4660 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4661 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4664 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4665 | LocationSummary* locations = |
| 4666 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4667 | switch (mul->GetResultType()) { |
| 4668 | case Primitive::kPrimInt: |
| 4669 | case Primitive::kPrimLong: |
| 4670 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4671 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4672 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4673 | break; |
| 4674 | |
| 4675 | case Primitive::kPrimFloat: |
| 4676 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4677 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4678 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4679 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4680 | break; |
| 4681 | |
| 4682 | default: |
| 4683 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4688 | switch (mul->GetResultType()) { |
| 4689 | case Primitive::kPrimInt: |
| 4690 | case Primitive::kPrimLong: |
| 4691 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4692 | break; |
| 4693 | |
| 4694 | case Primitive::kPrimFloat: |
| 4695 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4696 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4697 | break; |
| 4698 | |
| 4699 | default: |
| 4700 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4701 | } |
| 4702 | } |
| 4703 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4704 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4705 | LocationSummary* locations = |
| 4706 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4707 | switch (neg->GetResultType()) { |
| 4708 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4709 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4710 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4711 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4712 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4713 | |
| 4714 | case Primitive::kPrimFloat: |
| 4715 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4716 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4717 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4718 | break; |
| 4719 | |
| 4720 | default: |
| 4721 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4726 | switch (neg->GetResultType()) { |
| 4727 | case Primitive::kPrimInt: |
| 4728 | case Primitive::kPrimLong: |
| 4729 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4730 | break; |
| 4731 | |
| 4732 | case Primitive::kPrimFloat: |
| 4733 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4734 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4735 | break; |
| 4736 | |
| 4737 | default: |
| 4738 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4739 | } |
| 4740 | } |
| 4741 | |
| 4742 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4743 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4744 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4745 | InvokeRuntimeCallingConvention calling_convention; |
| 4746 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4747 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4748 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4749 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4753 | LocationSummary* locations = instruction->GetLocations(); |
| 4754 | InvokeRuntimeCallingConvention calling_convention; |
| 4755 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4756 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4757 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4758 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4759 | // of poisoning the reference. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4760 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4761 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4762 | } |
| 4763 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4764 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4765 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4766 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4767 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4768 | if (instruction->IsStringAlloc()) { |
| 4769 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4770 | } else { |
| 4771 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4772 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4773 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4774 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4775 | } |
| 4776 | |
| 4777 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4778 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4779 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4780 | if (instruction->IsStringAlloc()) { |
| 4781 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4782 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4783 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4784 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4785 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4786 | __ Blr(lr); |
| 4787 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4788 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4789 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4790 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4791 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4795 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4796 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4797 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4801 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4802 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4803 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4804 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4805 | break; |
| 4806 | |
| 4807 | default: |
| 4808 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4809 | } |
| 4810 | } |
| 4811 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4812 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4813 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4814 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4815 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4816 | } |
| 4817 | |
| 4818 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4819 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4820 | } |
| 4821 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4822 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4823 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4824 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4825 | } |
| 4826 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4827 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4828 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4829 | return; |
| 4830 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4831 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4832 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4833 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4834 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4835 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4836 | } |
| 4837 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4838 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4839 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4840 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4841 | |
| 4842 | LocationSummary* locations = instruction->GetLocations(); |
| 4843 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4844 | |
| 4845 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4846 | } |
| 4847 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4848 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4849 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4852 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4853 | HandleBinaryOp(instruction); |
| 4854 | } |
| 4855 | |
| 4856 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4857 | HandleBinaryOp(instruction); |
| 4858 | } |
| 4859 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4860 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4861 | LOG(FATAL) << "Unreachable"; |
| 4862 | } |
| 4863 | |
| 4864 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4865 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4866 | } |
| 4867 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4868 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4869 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4870 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4871 | if (location.IsStackSlot()) { |
| 4872 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4873 | } else if (location.IsDoubleStackSlot()) { |
| 4874 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4875 | } |
| 4876 | locations->SetOut(location); |
| 4877 | } |
| 4878 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4879 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4880 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4881 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4885 | LocationSummary* locations = |
| 4886 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4887 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4891 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4892 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4893 | } |
| 4894 | |
| 4895 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4896 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4897 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4898 | locations->SetInAt(i, Location::Any()); |
| 4899 | } |
| 4900 | locations->SetOut(Location::Any()); |
| 4901 | } |
| 4902 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4903 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4904 | LOG(FATAL) << "Unreachable"; |
| 4905 | } |
| 4906 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4907 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4908 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4909 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4910 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 4911 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4912 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4913 | |
| 4914 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4915 | case Primitive::kPrimInt: |
| 4916 | case Primitive::kPrimLong: |
| 4917 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4918 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4919 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4920 | break; |
| 4921 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4922 | case Primitive::kPrimFloat: |
| 4923 | case Primitive::kPrimDouble: { |
| 4924 | InvokeRuntimeCallingConvention calling_convention; |
| 4925 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4926 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4927 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4928 | |
| 4929 | break; |
| 4930 | } |
| 4931 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4932 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4933 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4938 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4939 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4940 | switch (type) { |
| 4941 | case Primitive::kPrimInt: |
| 4942 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4943 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4944 | break; |
| 4945 | } |
| 4946 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4947 | case Primitive::kPrimFloat: |
| 4948 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4949 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 4950 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4951 | if (type == Primitive::kPrimFloat) { |
| 4952 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4953 | } else { |
| 4954 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4955 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4956 | break; |
| 4957 | } |
| 4958 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4959 | default: |
| 4960 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4961 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4962 | } |
| 4963 | } |
| 4964 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4965 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4966 | memory_barrier->SetLocations(nullptr); |
| 4967 | } |
| 4968 | |
| 4969 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4970 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4973 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4974 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4975 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4976 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4977 | } |
| 4978 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4979 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4980 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4981 | } |
| 4982 | |
| 4983 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4984 | instruction->SetLocations(nullptr); |
| 4985 | } |
| 4986 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4987 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4988 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4989 | } |
| 4990 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4991 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4992 | HandleBinaryOp(ror); |
| 4993 | } |
| 4994 | |
| 4995 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4996 | HandleBinaryOp(ror); |
| 4997 | } |
| 4998 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4999 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5000 | HandleShift(shl); |
| 5001 | } |
| 5002 | |
| 5003 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5004 | HandleShift(shl); |
| 5005 | } |
| 5006 | |
| 5007 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5008 | HandleShift(shr); |
| 5009 | } |
| 5010 | |
| 5011 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5012 | HandleShift(shr); |
| 5013 | } |
| 5014 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5015 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5016 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5020 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5021 | } |
| 5022 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5023 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5024 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5028 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5032 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5033 | } |
| 5034 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5035 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5036 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5039 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5040 | HUnresolvedInstanceFieldGet* instruction) { |
| 5041 | FieldAccessCallingConventionARM64 calling_convention; |
| 5042 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5043 | instruction, instruction->GetFieldType(), calling_convention); |
| 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5047 | HUnresolvedInstanceFieldGet* instruction) { |
| 5048 | FieldAccessCallingConventionARM64 calling_convention; |
| 5049 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5050 | instruction->GetFieldType(), |
| 5051 | instruction->GetFieldIndex(), |
| 5052 | instruction->GetDexPc(), |
| 5053 | calling_convention); |
| 5054 | } |
| 5055 | |
| 5056 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5057 | HUnresolvedInstanceFieldSet* instruction) { |
| 5058 | FieldAccessCallingConventionARM64 calling_convention; |
| 5059 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5060 | instruction, instruction->GetFieldType(), calling_convention); |
| 5061 | } |
| 5062 | |
| 5063 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5064 | HUnresolvedInstanceFieldSet* instruction) { |
| 5065 | FieldAccessCallingConventionARM64 calling_convention; |
| 5066 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5067 | instruction->GetFieldType(), |
| 5068 | instruction->GetFieldIndex(), |
| 5069 | instruction->GetDexPc(), |
| 5070 | calling_convention); |
| 5071 | } |
| 5072 | |
| 5073 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5074 | HUnresolvedStaticFieldGet* instruction) { |
| 5075 | FieldAccessCallingConventionARM64 calling_convention; |
| 5076 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5077 | instruction, instruction->GetFieldType(), calling_convention); |
| 5078 | } |
| 5079 | |
| 5080 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5081 | HUnresolvedStaticFieldGet* instruction) { |
| 5082 | FieldAccessCallingConventionARM64 calling_convention; |
| 5083 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5084 | instruction->GetFieldType(), |
| 5085 | instruction->GetFieldIndex(), |
| 5086 | instruction->GetDexPc(), |
| 5087 | calling_convention); |
| 5088 | } |
| 5089 | |
| 5090 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5091 | HUnresolvedStaticFieldSet* instruction) { |
| 5092 | FieldAccessCallingConventionARM64 calling_convention; |
| 5093 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5094 | instruction, instruction->GetFieldType(), calling_convention); |
| 5095 | } |
| 5096 | |
| 5097 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5098 | HUnresolvedStaticFieldSet* instruction) { |
| 5099 | FieldAccessCallingConventionARM64 calling_convention; |
| 5100 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5101 | instruction->GetFieldType(), |
| 5102 | instruction->GetFieldIndex(), |
| 5103 | instruction->GetDexPc(), |
| 5104 | calling_convention); |
| 5105 | } |
| 5106 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5107 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5108 | LocationSummary* locations = |
| 5109 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5110 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5114 | HBasicBlock* block = instruction->GetBlock(); |
| 5115 | if (block->GetLoopInformation() != nullptr) { |
| 5116 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5117 | // The back edge will generate the suspend check. |
| 5118 | return; |
| 5119 | } |
| 5120 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5121 | // The goto will generate the suspend check. |
| 5122 | return; |
| 5123 | } |
| 5124 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5125 | } |
| 5126 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5127 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5128 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5129 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5130 | InvokeRuntimeCallingConvention calling_convention; |
| 5131 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5132 | } |
| 5133 | |
| 5134 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5135 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5136 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5140 | LocationSummary* locations = |
| 5141 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5142 | Primitive::Type input_type = conversion->GetInputType(); |
| 5143 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5144 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5145 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5146 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5147 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5148 | } |
| 5149 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5150 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5151 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5152 | } else { |
| 5153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5154 | } |
| 5155 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5156 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5157 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5158 | } else { |
| 5159 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5164 | Primitive::Type result_type = conversion->GetResultType(); |
| 5165 | Primitive::Type input_type = conversion->GetInputType(); |
| 5166 | |
| 5167 | DCHECK_NE(input_type, result_type); |
| 5168 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5169 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5170 | int result_size = Primitive::ComponentSize(result_type); |
| 5171 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5172 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5173 | Register output = OutputRegister(conversion); |
| 5174 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5175 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5176 | // 'int' values are used directly as W registers, discarding the top |
| 5177 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5178 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5179 | // top 32 bits of the target register. We theoretically could leave those |
| 5180 | // bits unchanged, but we would have to make sure that no code uses a |
| 5181 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5182 | // zero. |
| 5183 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5184 | } else if (result_type == Primitive::kPrimChar || |
| 5185 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5186 | __ Ubfx(output, |
| 5187 | output.IsX() ? source.X() : source.W(), |
| 5188 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5189 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5190 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5191 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5192 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5193 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5194 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5195 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5196 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5197 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5198 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5199 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5200 | } else { |
| 5201 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5202 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5203 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5204 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5205 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5206 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5207 | HandleShift(ushr); |
| 5208 | } |
| 5209 | |
| 5210 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5211 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5215 | HandleBinaryOp(instruction); |
| 5216 | } |
| 5217 | |
| 5218 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5219 | HandleBinaryOp(instruction); |
| 5220 | } |
| 5221 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5222 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5223 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5224 | LOG(FATAL) << "Unreachable"; |
| 5225 | } |
| 5226 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5227 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5228 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5229 | LOG(FATAL) << "Unreachable"; |
| 5230 | } |
| 5231 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5232 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5233 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5234 | LocationSummary* locations = |
| 5235 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5236 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5237 | } |
| 5238 | |
| 5239 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5240 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5241 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5242 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5243 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5244 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5245 | // 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] | 5246 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5247 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5248 | // make sure we don't emit it if the target may run out of range. |
| 5249 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5250 | // ranges and emit the tables only as required. |
| 5251 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5252 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5253 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5254 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5255 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5256 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5257 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5258 | Register temp = temps.AcquireW(); |
| 5259 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5260 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5261 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5262 | // Jump to successors[0] if value == lower_bound. |
| 5263 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5264 | int32_t last_index = 0; |
| 5265 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5266 | __ Subs(temp, temp, Operand(2)); |
| 5267 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5268 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5269 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5270 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5271 | } |
| 5272 | if (num_entries - last_index == 2) { |
| 5273 | // The last missing case_value. |
| 5274 | __ Cmp(temp, Operand(1)); |
| 5275 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | // And the default for any other value. |
| 5279 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5280 | __ B(codegen_->GetLabelOf(default_block)); |
| 5281 | } |
| 5282 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5283 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5284 | |
| 5285 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5286 | |
| 5287 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5288 | // registers, we are free to block one. |
| 5289 | Register temp_w = temps.AcquireW(); |
| 5290 | Register index; |
| 5291 | // Remove the bias. |
| 5292 | if (lower_bound != 0) { |
| 5293 | index = temp_w; |
| 5294 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5295 | } else { |
| 5296 | index = value_reg; |
| 5297 | } |
| 5298 | |
| 5299 | // Jump to default block if index is out of the range. |
| 5300 | __ Cmp(index, Operand(num_entries)); |
| 5301 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5302 | |
| 5303 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5304 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5305 | // register pressure. |
| 5306 | Register table_base = temps.AcquireX(); |
| 5307 | // Load jump offset from the table. |
| 5308 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5309 | Register jump_offset = temp_w; |
| 5310 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5311 | |
| 5312 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5313 | Register target_address = table_base; |
| 5314 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5315 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5319 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5320 | HInstruction* instruction, |
| 5321 | Location out, |
| 5322 | uint32_t offset, |
| 5323 | Location maybe_temp, |
| 5324 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5325 | Primitive::Type type = Primitive::kPrimNot; |
| 5326 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5327 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5328 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5329 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5330 | if (kUseBakerReadBarrier) { |
| 5331 | // Load with fast path based Baker's read barrier. |
| 5332 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5333 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5334 | out, |
| 5335 | out_reg, |
| 5336 | offset, |
| 5337 | temp_reg, |
| 5338 | /* needs_null_check */ false, |
| 5339 | /* use_load_acquire */ false); |
| 5340 | } else { |
| 5341 | // Load with slow path based read barrier. |
| 5342 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5343 | // in the following move operation, as we will need it for the |
| 5344 | // read barrier below. |
| 5345 | __ Mov(temp_reg, out_reg); |
| 5346 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5347 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5348 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5349 | } |
| 5350 | } else { |
| 5351 | // Plain load with no read barrier. |
| 5352 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5353 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5354 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5355 | } |
| 5356 | } |
| 5357 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5358 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5359 | HInstruction* instruction, |
| 5360 | Location out, |
| 5361 | Location obj, |
| 5362 | uint32_t offset, |
| 5363 | Location maybe_temp, |
| 5364 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5365 | Primitive::Type type = Primitive::kPrimNot; |
| 5366 | Register out_reg = RegisterFrom(out, type); |
| 5367 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5368 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5369 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5370 | if (kUseBakerReadBarrier) { |
| 5371 | // Load with fast path based Baker's read barrier. |
| 5372 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5373 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5374 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5375 | out, |
| 5376 | obj_reg, |
| 5377 | offset, |
| 5378 | temp_reg, |
| 5379 | /* needs_null_check */ false, |
| 5380 | /* use_load_acquire */ false); |
| 5381 | } else { |
| 5382 | // Load with slow path based read barrier. |
| 5383 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5384 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5385 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5386 | } |
| 5387 | } else { |
| 5388 | // Plain load with no read barrier. |
| 5389 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5390 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5391 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5392 | } |
| 5393 | } |
| 5394 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5395 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5396 | HInstruction* instruction, |
| 5397 | Location root, |
| 5398 | Register obj, |
| 5399 | uint32_t offset, |
| 5400 | vixl::aarch64::Label* fixup_label, |
| 5401 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5402 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5403 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5404 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5405 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5406 | if (kUseBakerReadBarrier) { |
| 5407 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5408 | // Baker's read barrier are used: |
| 5409 | // |
| 5410 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5411 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5412 | // if (temp != null) { |
| 5413 | // root = temp(root) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5414 | // } |
| 5415 | |
| 5416 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5417 | if (fixup_label == nullptr) { |
| 5418 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5419 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5420 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5421 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5422 | static_assert( |
| 5423 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5424 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5425 | "have different sizes."); |
| 5426 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5427 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5428 | "have different sizes."); |
| 5429 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5430 | Register temp = lr; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5431 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5432 | // Slow path marking the GC root `root`. The entrypoint will alrady be loaded in temp. |
| 5433 | SlowPathCodeARM64* slow_path = |
| 5434 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, |
| 5435 | root, |
| 5436 | LocationFrom(temp)); |
| 5437 | codegen_->AddSlowPath(slow_path); |
| 5438 | const int32_t entry_point_offset = |
| 5439 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 5440 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5441 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5442 | // threads are suspended or running a checkpoint. |
| 5443 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
| 5444 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 5445 | // checking GetIsGcMarking. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5446 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5447 | __ Bind(slow_path->GetExitLabel()); |
| 5448 | } else { |
| 5449 | // GC root loaded through a slow path for read barriers other |
| 5450 | // than Baker's. |
| 5451 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5452 | if (fixup_label == nullptr) { |
| 5453 | __ Add(root_reg.X(), obj.X(), offset); |
| 5454 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5455 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5456 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5457 | // /* mirror::Object* */ root = root->Read() |
| 5458 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5459 | } |
| 5460 | } else { |
| 5461 | // Plain GC root load with no read barrier. |
| 5462 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5463 | if (fixup_label == nullptr) { |
| 5464 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5465 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5466 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5467 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5468 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5469 | // do not have to unpoison `root_reg` here. |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5474 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5475 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5476 | uint32_t offset, |
| 5477 | Register temp, |
| 5478 | bool needs_null_check, |
| 5479 | bool use_load_acquire) { |
| 5480 | DCHECK(kEmitCompilerReadBarrier); |
| 5481 | DCHECK(kUseBakerReadBarrier); |
| 5482 | |
| 5483 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5484 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5485 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5486 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5487 | ref, |
| 5488 | obj, |
| 5489 | offset, |
| 5490 | no_index, |
| 5491 | no_scale_factor, |
| 5492 | temp, |
| 5493 | needs_null_check, |
| 5494 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5495 | } |
| 5496 | |
| 5497 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5498 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5499 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5500 | uint32_t data_offset, |
| 5501 | Location index, |
| 5502 | Register temp, |
| 5503 | bool needs_null_check) { |
| 5504 | DCHECK(kEmitCompilerReadBarrier); |
| 5505 | DCHECK(kUseBakerReadBarrier); |
| 5506 | |
| 5507 | // Array cells are never volatile variables, therefore array loads |
| 5508 | // never use Load-Acquire instructions on ARM64. |
| 5509 | const bool use_load_acquire = false; |
| 5510 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5511 | static_assert( |
| 5512 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5513 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5514 | // /* HeapReference<Object> */ ref = |
| 5515 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5516 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5517 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5518 | ref, |
| 5519 | obj, |
| 5520 | data_offset, |
| 5521 | index, |
| 5522 | scale_factor, |
| 5523 | temp, |
| 5524 | needs_null_check, |
| 5525 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5529 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5530 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5531 | uint32_t offset, |
| 5532 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5533 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5534 | Register temp, |
| 5535 | bool needs_null_check, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5536 | bool use_load_acquire, |
| 5537 | bool always_update_field) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5538 | DCHECK(kEmitCompilerReadBarrier); |
| 5539 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5540 | // If we are emitting an array load, we should not be using a |
| 5541 | // Load Acquire instruction. In other words: |
| 5542 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5543 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5544 | |
| 5545 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5546 | UseScratchRegisterScope temps(masm); |
| 5547 | |
| 5548 | // In slow path based read barriers, the read barrier call is |
| 5549 | // inserted after the original load. However, in fast path based |
| 5550 | // Baker's read barriers, we need to perform the load of |
| 5551 | // mirror::Object::monitor_ *before* the original reference load. |
| 5552 | // This load-load ordering is required by the read barrier. |
| 5553 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5554 | // |
| 5555 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5556 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5557 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 5558 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5559 | // if (is_gray) { |
| 5560 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5561 | // } |
| 5562 | // |
| 5563 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5564 | // slightly more complex as it performs additional checks that we do |
| 5565 | // not do here for performance reasons. |
| 5566 | |
| 5567 | Primitive::Type type = Primitive::kPrimNot; |
| 5568 | Register ref_reg = RegisterFrom(ref, type); |
| 5569 | DCHECK(obj.IsW()); |
| 5570 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5571 | |
| 5572 | // /* int32_t */ monitor = obj->monitor_ |
| 5573 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5574 | if (needs_null_check) { |
| 5575 | MaybeRecordImplicitNullCheck(instruction); |
| 5576 | } |
| 5577 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5578 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5579 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5580 | |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5581 | // Introduce a dependency on the lock_word including rb_state, |
| 5582 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5583 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5584 | // `obj` is unchanged by this operation, but its value now depends |
| 5585 | // on `temp`. |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5586 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5587 | |
| 5588 | // The actual reference load. |
| 5589 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5590 | // Load types involving an "index": ArrayGet, |
| 5591 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5592 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5593 | if (use_load_acquire) { |
| 5594 | // UnsafeGetObjectVolatile intrinsic case. |
| 5595 | // Register `index` is not an index in an object array, but an |
| 5596 | // offset to an object reference field within object `obj`. |
| 5597 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5598 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5599 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5600 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5601 | DCHECK_EQ(offset, 0u); |
| 5602 | DCHECK_EQ(scale_factor, 0u); |
| 5603 | DCHECK_EQ(needs_null_check, 0u); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5604 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5605 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5606 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5607 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5608 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5609 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5610 | if (index.IsConstant()) { |
| 5611 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5612 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5613 | } else { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5614 | Register temp3 = temps.AcquireW(); |
| 5615 | __ Add(temp3, obj, offset); |
| 5616 | Load(type, ref_reg, HeapOperand(temp3, XRegisterFrom(index), LSL, scale_factor)); |
| 5617 | temps.Release(temp3); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5618 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5619 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5620 | } else { |
| 5621 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5622 | MemOperand field = HeapOperand(obj, offset); |
| 5623 | if (use_load_acquire) { |
| 5624 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5625 | } else { |
| 5626 | Load(type, ref_reg, field); |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5631 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5632 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5633 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5634 | SlowPathCodeARM64* slow_path; |
| 5635 | if (always_update_field) { |
| 5636 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 only supports |
| 5637 | // address of the form `obj + field_offset`, where `obj` is a |
| 5638 | // register and `field_offset` is a register. Thus `offset` and |
| 5639 | // `scale_factor` above are expected to be null in this code path. |
| 5640 | DCHECK_EQ(offset, 0u); |
| 5641 | DCHECK_EQ(scale_factor, 0u); /* "times 1" */ |
| 5642 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM64( |
| 5643 | instruction, ref, obj, /* field_offset */ index, temp); |
| 5644 | } else { |
| 5645 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
| 5646 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5647 | AddSlowPath(slow_path); |
| 5648 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 5649 | // if (rb_state == ReadBarrier::GrayState()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5650 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5651 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 5652 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5653 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5654 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5655 | __ Bind(slow_path->GetExitLabel()); |
| 5656 | } |
| 5657 | |
| 5658 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5659 | Location out, |
| 5660 | Location ref, |
| 5661 | Location obj, |
| 5662 | uint32_t offset, |
| 5663 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5664 | DCHECK(kEmitCompilerReadBarrier); |
| 5665 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5666 | // Insert a slow path based read barrier *after* the reference load. |
| 5667 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5668 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5669 | // reference will be carried out by the runtime within the slow |
| 5670 | // path. |
| 5671 | // |
| 5672 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5673 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5674 | // not used by the artReadBarrierSlow entry point. |
| 5675 | // |
| 5676 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5677 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5678 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5679 | AddSlowPath(slow_path); |
| 5680 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5681 | __ B(slow_path->GetEntryLabel()); |
| 5682 | __ Bind(slow_path->GetExitLabel()); |
| 5683 | } |
| 5684 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5685 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5686 | Location out, |
| 5687 | Location ref, |
| 5688 | Location obj, |
| 5689 | uint32_t offset, |
| 5690 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5691 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5692 | // Baker's read barriers shall be handled by the fast path |
| 5693 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5694 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5695 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5696 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5697 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5698 | } else if (kPoisonHeapReferences) { |
| 5699 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5700 | } |
| 5701 | } |
| 5702 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5703 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5704 | Location out, |
| 5705 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5706 | DCHECK(kEmitCompilerReadBarrier); |
| 5707 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5708 | // Insert a slow path based read barrier *after* the GC root load. |
| 5709 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5710 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5711 | // not need to do anything special for this here. |
| 5712 | SlowPathCodeARM64* slow_path = |
| 5713 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5714 | AddSlowPath(slow_path); |
| 5715 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5716 | __ B(slow_path->GetEntryLabel()); |
| 5717 | __ Bind(slow_path->GetExitLabel()); |
| 5718 | } |
| 5719 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5720 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5721 | LocationSummary* locations = |
| 5722 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5724 | locations->SetOut(Location::RequiresRegister()); |
| 5725 | } |
| 5726 | |
| 5727 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5728 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5729 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5730 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5731 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5732 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5733 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5734 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5735 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5736 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5737 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5738 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5739 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5740 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5741 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 5744 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5745 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5746 | #undef __ |
| 5747 | #undef QUICK_ENTRY_POINT |
| 5748 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5749 | } // namespace arm64 |
| 5750 | } // namespace art |