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 | Location arg0, arg1; |
| 463 | if (instruction_->IsInstanceOf()) { |
| 464 | arg0 = locations->InAt(1); |
| 465 | arg1 = locations->Out(); |
| 466 | } else { |
| 467 | arg0 = locations->InAt(0); |
| 468 | arg1 = locations->InAt(1); |
| 469 | } |
| 470 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 471 | DCHECK(instruction_->IsCheckCast() |
| 472 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 473 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 474 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 476 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 477 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 478 | if (!is_fatal_) { |
| 479 | SaveLiveRegisters(codegen, locations); |
| 480 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 481 | |
| 482 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 483 | // move resolver. |
| 484 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 485 | codegen->EmitParallelMoves(arg0, |
| 486 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 487 | Primitive::kPrimNot, |
| 488 | arg1, |
| 489 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 490 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 491 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 492 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 493 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Class*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 494 | Primitive::Type ret_type = instruction_->GetType(); |
| 495 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 496 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 497 | } else { |
| 498 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 499 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 500 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 503 | if (!is_fatal_) { |
| 504 | RestoreLiveRegisters(codegen, locations); |
| 505 | __ B(GetExitLabel()); |
| 506 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 509 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 510 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 511 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 512 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 513 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 514 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 515 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 516 | }; |
| 517 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 518 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 519 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 520 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 521 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 522 | |
| 523 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 524 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 526 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 527 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 530 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 531 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 532 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 533 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 534 | }; |
| 535 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 536 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 537 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 538 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 539 | |
| 540 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 541 | LocationSummary* locations = instruction_->GetLocations(); |
| 542 | __ Bind(GetEntryLabel()); |
| 543 | SaveLiveRegisters(codegen, locations); |
| 544 | |
| 545 | InvokeRuntimeCallingConvention calling_convention; |
| 546 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 547 | parallel_move.AddMove( |
| 548 | locations->InAt(0), |
| 549 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 550 | Primitive::kPrimNot, |
| 551 | nullptr); |
| 552 | parallel_move.AddMove( |
| 553 | locations->InAt(1), |
| 554 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 555 | Primitive::kPrimInt, |
| 556 | nullptr); |
| 557 | parallel_move.AddMove( |
| 558 | locations->InAt(2), |
| 559 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 560 | Primitive::kPrimNot, |
| 561 | nullptr); |
| 562 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 563 | |
| 564 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 565 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 566 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 567 | RestoreLiveRegisters(codegen, locations); |
| 568 | __ B(GetExitLabel()); |
| 569 | } |
| 570 | |
| 571 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 572 | |
| 573 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 574 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 575 | }; |
| 576 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 577 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 578 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 579 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 580 | |
| 581 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 582 | // underlying code buffer and we have generated the jump table with right size. |
| 583 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 584 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 585 | |
| 586 | __ Bind(&table_start_); |
| 587 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 588 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 589 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 590 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 591 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 592 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 593 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 594 | Literal<int32_t> literal(jump_offset); |
| 595 | __ place(&literal); |
| 596 | } |
| 597 | } |
| 598 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 599 | // Slow path marking an object reference `ref` during a read |
| 600 | // barrier. The field `obj.field` in the object `obj` holding this |
| 601 | // reference does not get updated by this slow path after marking (see |
| 602 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 below for that). |
| 603 | // |
| 604 | // This means that after the execution of this slow path, `ref` will |
| 605 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 606 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 607 | // probably still be a from-space reference (unless it gets updated by |
| 608 | // another thread, or if another thread installed another object |
| 609 | // reference (different from `ref`) in `obj.field`). |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 610 | // If entrypoint is a valid location it is assumed to already be holding the entrypoint. The case |
| 611 | // where the entrypoint is passed in is for the GcRoot read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 612 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 613 | public: |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 614 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 615 | Location ref, |
| 616 | Location entrypoint = Location::NoLocation()) |
| 617 | : SlowPathCodeARM64(instruction), |
| 618 | ref_(ref), |
| 619 | entrypoint_(entrypoint) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 620 | DCHECK(kEmitCompilerReadBarrier); |
| 621 | } |
| 622 | |
| 623 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 624 | |
| 625 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 626 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 627 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 628 | DCHECK(ref_.IsRegister()) << ref_; |
| 629 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 630 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 631 | instruction_->IsStaticFieldGet() || |
| 632 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 633 | instruction_->IsArraySet() || |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 634 | instruction_->IsLoadClass() || |
| 635 | instruction_->IsLoadString() || |
| 636 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 637 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 638 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 639 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 640 | << "Unexpected instruction in read barrier marking slow path: " |
| 641 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 642 | // The read barrier instrumentation of object ArrayGet |
| 643 | // instructions does not support the HIntermediateAddress |
| 644 | // instruction. |
| 645 | DCHECK(!(instruction_->IsArrayGet() && |
| 646 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 647 | |
| 648 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 649 | // No need to save live registers; it's taken care of by the |
| 650 | // entrypoint. Also, there is no need to update the stack mask, |
| 651 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 652 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 653 | DCHECK_NE(ref_.reg(), LR); |
| 654 | DCHECK_NE(ref_.reg(), WSP); |
| 655 | DCHECK_NE(ref_.reg(), WZR); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 656 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 657 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 658 | DCHECK_NE(ref_.reg(), IP0); |
| 659 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 660 | // "Compact" slow path, saving two moves. |
| 661 | // |
| 662 | // Instead of using the standard runtime calling convention (input |
| 663 | // and output in W0): |
| 664 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 665 | // W0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 666 | // W0 <- ReadBarrierMark(W0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 667 | // ref <- W0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 668 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 669 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 670 | // of a dedicated entrypoint: |
| 671 | // |
| 672 | // rX <- ReadBarrierMarkRegX(rX) |
| 673 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 674 | if (entrypoint_.IsValid()) { |
| 675 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 676 | __ Blr(XRegisterFrom(entrypoint_)); |
| 677 | } else { |
| 678 | // Entrypoint is not already loaded, load from the thread. |
| 679 | int32_t entry_point_offset = |
| 680 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 681 | // This runtime call does not require a stack map. |
| 682 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 683 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 684 | __ B(GetExitLabel()); |
| 685 | } |
| 686 | |
| 687 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 688 | // The location (register) of the marked object reference. |
| 689 | const Location ref_; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 690 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 691 | // The location of the entrypoint if it is already loaded. |
| 692 | const Location entrypoint_; |
| 693 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 694 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 695 | }; |
| 696 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 697 | // Slow path marking an object reference `ref` during a read barrier, |
| 698 | // and if needed, atomically updating the field `obj.field` in the |
| 699 | // object `obj` holding this reference after marking (contrary to |
| 700 | // ReadBarrierMarkSlowPathARM64 above, which never tries to update |
| 701 | // `obj.field`). |
| 702 | // |
| 703 | // This means that after the execution of this slow path, both `ref` |
| 704 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 705 | // hold the same to-space reference (unless another thread installed |
| 706 | // another object reference (different from `ref`) in `obj.field`). |
| 707 | class ReadBarrierMarkAndUpdateFieldSlowPathARM64 : public SlowPathCodeARM64 { |
| 708 | public: |
| 709 | ReadBarrierMarkAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 710 | Location ref, |
| 711 | Register obj, |
| 712 | Location field_offset, |
| 713 | Register temp) |
| 714 | : SlowPathCodeARM64(instruction), |
| 715 | ref_(ref), |
| 716 | obj_(obj), |
| 717 | field_offset_(field_offset), |
| 718 | temp_(temp) { |
| 719 | DCHECK(kEmitCompilerReadBarrier); |
| 720 | } |
| 721 | |
| 722 | const char* GetDescription() const OVERRIDE { |
| 723 | return "ReadBarrierMarkAndUpdateFieldSlowPathARM64"; |
| 724 | } |
| 725 | |
| 726 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 727 | LocationSummary* locations = instruction_->GetLocations(); |
| 728 | Register ref_reg = WRegisterFrom(ref_); |
| 729 | DCHECK(locations->CanCall()); |
| 730 | DCHECK(ref_.IsRegister()) << ref_; |
| 731 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 732 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 733 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 734 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 735 | << instruction_->DebugName(); |
| 736 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 737 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 738 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 739 | |
| 740 | __ Bind(GetEntryLabel()); |
| 741 | |
| 742 | // Save the old reference. |
| 743 | // Note that we cannot use IP to save the old reference, as IP is |
| 744 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 745 | // need the old reference after the call to that entry point. |
| 746 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 747 | __ Mov(temp_.W(), ref_reg); |
| 748 | |
| 749 | // No need to save live registers; it's taken care of by the |
| 750 | // entrypoint. Also, there is no need to update the stack mask, |
| 751 | // as this runtime call will not trigger a garbage collection. |
| 752 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 753 | DCHECK_NE(ref_.reg(), LR); |
| 754 | DCHECK_NE(ref_.reg(), WSP); |
| 755 | DCHECK_NE(ref_.reg(), WZR); |
| 756 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 757 | // as a temporary, it cannot be the entry point's input/output. |
| 758 | DCHECK_NE(ref_.reg(), IP0); |
| 759 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 760 | // "Compact" slow path, saving two moves. |
| 761 | // |
| 762 | // Instead of using the standard runtime calling convention (input |
| 763 | // and output in W0): |
| 764 | // |
| 765 | // W0 <- ref |
| 766 | // W0 <- ReadBarrierMark(W0) |
| 767 | // ref <- W0 |
| 768 | // |
| 769 | // we just use rX (the register containing `ref`) as input and output |
| 770 | // of a dedicated entrypoint: |
| 771 | // |
| 772 | // rX <- ReadBarrierMarkRegX(rX) |
| 773 | // |
| 774 | int32_t entry_point_offset = |
| 775 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 776 | // This runtime call does not require a stack map. |
| 777 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 778 | |
| 779 | // If the new reference is different from the old reference, |
| 780 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 781 | // |
| 782 | // Note that this field could also hold a different object, if |
| 783 | // another thread had concurrently changed it. In that case, the |
| 784 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 785 | // (CAS) operation below would abort the CAS, leaving the field |
| 786 | // as-is. |
| 787 | vixl::aarch64::Label done; |
| 788 | __ Cmp(temp_.W(), ref_reg); |
| 789 | __ B(eq, &done); |
| 790 | |
| 791 | // Update the the holder's field atomically. This may fail if |
| 792 | // mutator updates before us, but it's OK. This is achieved |
| 793 | // using a strong compare-and-set (CAS) operation with relaxed |
| 794 | // memory synchronization ordering, where the expected value is |
| 795 | // the old reference and the desired value is the new reference. |
| 796 | |
| 797 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 798 | UseScratchRegisterScope temps(masm); |
| 799 | |
| 800 | // Convenience aliases. |
| 801 | Register base = obj_.W(); |
| 802 | Register offset = XRegisterFrom(field_offset_); |
| 803 | Register expected = temp_.W(); |
| 804 | Register value = ref_reg; |
| 805 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 806 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 807 | |
| 808 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 809 | |
| 810 | if (kPoisonHeapReferences) { |
| 811 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 812 | if (value.Is(expected)) { |
| 813 | // Do not poison `value`, as it is the same register as |
| 814 | // `expected`, which has just been poisoned. |
| 815 | } else { |
| 816 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | // do { |
| 821 | // tmp_value = [tmp_ptr] - expected; |
| 822 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 823 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 824 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 825 | __ Bind(&loop_head); |
| 826 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 827 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 828 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 829 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 830 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 831 | __ B(&exit_loop); |
| 832 | __ Bind(&comparison_failed); |
| 833 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 834 | __ Bind(&exit_loop); |
| 835 | |
| 836 | if (kPoisonHeapReferences) { |
| 837 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 838 | if (value.Is(expected)) { |
| 839 | // Do not unpoison `value`, as it is the same register as |
| 840 | // `expected`, which has just been unpoisoned. |
| 841 | } else { |
| 842 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | __ Bind(&done); |
| 847 | __ B(GetExitLabel()); |
| 848 | } |
| 849 | |
| 850 | private: |
| 851 | // The location (register) of the marked object reference. |
| 852 | const Location ref_; |
| 853 | // The register containing the object holding the marked object reference field. |
| 854 | const Register obj_; |
| 855 | // The location of the offset of the marked reference field within `obj_`. |
| 856 | Location field_offset_; |
| 857 | |
| 858 | const Register temp_; |
| 859 | |
| 860 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM64); |
| 861 | }; |
| 862 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 863 | // Slow path generating a read barrier for a heap reference. |
| 864 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 865 | public: |
| 866 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 867 | Location out, |
| 868 | Location ref, |
| 869 | Location obj, |
| 870 | uint32_t offset, |
| 871 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 872 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 873 | out_(out), |
| 874 | ref_(ref), |
| 875 | obj_(obj), |
| 876 | offset_(offset), |
| 877 | index_(index) { |
| 878 | DCHECK(kEmitCompilerReadBarrier); |
| 879 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 880 | // has been overwritten by (or after) the heap object reference load |
| 881 | // to be instrumented, e.g.: |
| 882 | // |
| 883 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 884 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 885 | // |
| 886 | // In that case, we have lost the information about the original |
| 887 | // object, and the emitted read barrier cannot work properly. |
| 888 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 889 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 890 | } |
| 891 | |
| 892 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 893 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 894 | LocationSummary* locations = instruction_->GetLocations(); |
| 895 | Primitive::Type type = Primitive::kPrimNot; |
| 896 | DCHECK(locations->CanCall()); |
| 897 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 898 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 899 | instruction_->IsStaticFieldGet() || |
| 900 | instruction_->IsArrayGet() || |
| 901 | instruction_->IsInstanceOf() || |
| 902 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 903 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 904 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 905 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 906 | // The read barrier instrumentation of object ArrayGet |
| 907 | // instructions does not support the HIntermediateAddress |
| 908 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 909 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 910 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 911 | |
| 912 | __ Bind(GetEntryLabel()); |
| 913 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 914 | SaveLiveRegisters(codegen, locations); |
| 915 | |
| 916 | // We may have to change the index's value, but as `index_` is a |
| 917 | // constant member (like other "inputs" of this slow path), |
| 918 | // introduce a copy of it, `index`. |
| 919 | Location index = index_; |
| 920 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 921 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 922 | if (instruction_->IsArrayGet()) { |
| 923 | // Compute the actual memory offset and store it in `index`. |
| 924 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 925 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 926 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 927 | // We are about to change the value of `index_reg` (see the |
| 928 | // calls to vixl::MacroAssembler::Lsl and |
| 929 | // vixl::MacroAssembler::Mov below), but it has |
| 930 | // not been saved by the previous call to |
| 931 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 932 | // callee-save register -- |
| 933 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 934 | // callee-save registers, as it has been designed with the |
| 935 | // assumption that callee-save registers are supposed to be |
| 936 | // handled by the called function. So, as a callee-save |
| 937 | // register, `index_reg` _would_ eventually be saved onto |
| 938 | // the stack, but it would be too late: we would have |
| 939 | // changed its value earlier. Therefore, we manually save |
| 940 | // it here into another freely available register, |
| 941 | // `free_reg`, chosen of course among the caller-save |
| 942 | // registers (as a callee-save `free_reg` register would |
| 943 | // exhibit the same problem). |
| 944 | // |
| 945 | // Note we could have requested a temporary register from |
| 946 | // the register allocator instead; but we prefer not to, as |
| 947 | // this is a slow path, and we know we can find a |
| 948 | // caller-save register that is available. |
| 949 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 950 | __ Mov(free_reg.W(), index_reg); |
| 951 | index_reg = free_reg; |
| 952 | index = LocationFrom(index_reg); |
| 953 | } else { |
| 954 | // The initial register stored in `index_` has already been |
| 955 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 956 | // (as it is not a callee-save register), so we can freely |
| 957 | // use it. |
| 958 | } |
| 959 | // Shifting the index value contained in `index_reg` by the scale |
| 960 | // factor (2) cannot overflow in practice, as the runtime is |
| 961 | // unable to allocate object arrays with a size larger than |
| 962 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 963 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 964 | static_assert( |
| 965 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 966 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 967 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 968 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 969 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 970 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 971 | // (as in the case of ArrayGet), as it is actually an offset |
| 972 | // to an object field within an object. |
| 973 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 974 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 975 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 976 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 977 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 978 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 979 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
| 983 | // We're moving two or three locations to locations that could |
| 984 | // overlap, so we need a parallel move resolver. |
| 985 | InvokeRuntimeCallingConvention calling_convention; |
| 986 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 987 | parallel_move.AddMove(ref_, |
| 988 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 989 | type, |
| 990 | nullptr); |
| 991 | parallel_move.AddMove(obj_, |
| 992 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 993 | type, |
| 994 | nullptr); |
| 995 | if (index.IsValid()) { |
| 996 | parallel_move.AddMove(index, |
| 997 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 998 | Primitive::kPrimInt, |
| 999 | nullptr); |
| 1000 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1001 | } else { |
| 1002 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1003 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1004 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1005 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1006 | instruction_, |
| 1007 | instruction_->GetDexPc(), |
| 1008 | this); |
| 1009 | CheckEntrypointTypes< |
| 1010 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1011 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1012 | |
| 1013 | RestoreLiveRegisters(codegen, locations); |
| 1014 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1015 | __ B(GetExitLabel()); |
| 1016 | } |
| 1017 | |
| 1018 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1019 | |
| 1020 | private: |
| 1021 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1022 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1023 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1024 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1025 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1026 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1027 | } |
| 1028 | } |
| 1029 | // We shall never fail to find a free caller-save register, as |
| 1030 | // there are more than two core caller-save registers on ARM64 |
| 1031 | // (meaning it is possible to find one which is different from |
| 1032 | // `ref` and `obj`). |
| 1033 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1034 | LOG(FATAL) << "Could not find a free register"; |
| 1035 | UNREACHABLE(); |
| 1036 | } |
| 1037 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1038 | const Location out_; |
| 1039 | const Location ref_; |
| 1040 | const Location obj_; |
| 1041 | const uint32_t offset_; |
| 1042 | // An additional location containing an index to an array. |
| 1043 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1044 | // UnsafeGetObjectVolatile intrinsics. |
| 1045 | const Location index_; |
| 1046 | |
| 1047 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1048 | }; |
| 1049 | |
| 1050 | // Slow path generating a read barrier for a GC root. |
| 1051 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1052 | public: |
| 1053 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1054 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1055 | DCHECK(kEmitCompilerReadBarrier); |
| 1056 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1057 | |
| 1058 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1059 | LocationSummary* locations = instruction_->GetLocations(); |
| 1060 | Primitive::Type type = Primitive::kPrimNot; |
| 1061 | DCHECK(locations->CanCall()); |
| 1062 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1063 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1064 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1065 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1066 | |
| 1067 | __ Bind(GetEntryLabel()); |
| 1068 | SaveLiveRegisters(codegen, locations); |
| 1069 | |
| 1070 | InvokeRuntimeCallingConvention calling_convention; |
| 1071 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1072 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1073 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1074 | // thus we need a 64-bit move here, and we cannot use |
| 1075 | // |
| 1076 | // arm64_codegen->MoveLocation( |
| 1077 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1078 | // root_, |
| 1079 | // type); |
| 1080 | // |
| 1081 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1082 | // reference type (`Primitive::kPrimNot`). |
| 1083 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1084 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1085 | instruction_, |
| 1086 | instruction_->GetDexPc(), |
| 1087 | this); |
| 1088 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1089 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1090 | |
| 1091 | RestoreLiveRegisters(codegen, locations); |
| 1092 | __ B(GetExitLabel()); |
| 1093 | } |
| 1094 | |
| 1095 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1096 | |
| 1097 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1098 | const Location out_; |
| 1099 | const Location root_; |
| 1100 | |
| 1101 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1102 | }; |
| 1103 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1104 | #undef __ |
| 1105 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1106 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1107 | Location next_location; |
| 1108 | if (type == Primitive::kPrimVoid) { |
| 1109 | LOG(FATAL) << "Unreachable type " << type; |
| 1110 | } |
| 1111 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1112 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1113 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 1114 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1115 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1116 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1117 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1118 | } else { |
| 1119 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1120 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1121 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1124 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1125 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1126 | return next_location; |
| 1127 | } |
| 1128 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1129 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1130 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1131 | } |
| 1132 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1133 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1134 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1135 | const CompilerOptions& compiler_options, |
| 1136 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1137 | : CodeGenerator(graph, |
| 1138 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1139 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1140 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1141 | callee_saved_core_registers.GetList(), |
| 1142 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1143 | compiler_options, |
| 1144 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1145 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1146 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1147 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1148 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1149 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1150 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1151 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1152 | uint32_literals_(std::less<uint32_t>(), |
| 1153 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1154 | uint64_literals_(std::less<uint64_t>(), |
| 1155 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1156 | method_patches_(MethodReferenceComparator(), |
| 1157 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1158 | call_patches_(MethodReferenceComparator(), |
| 1159 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1160 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1161 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1162 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1163 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1164 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1165 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1166 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1167 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1168 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 1169 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1170 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1171 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1172 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1173 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1174 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1175 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1176 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1177 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1178 | jump_table->EmitTable(this); |
| 1179 | } |
| 1180 | } |
| 1181 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1182 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1183 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1184 | // Ensure we emit the literal pool. |
| 1185 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1186 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1187 | CodeGenerator::Finalize(allocator); |
| 1188 | } |
| 1189 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1190 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1191 | // Note: There are 6 kinds of moves: |
| 1192 | // 1. constant -> GPR/FPR (non-cycle) |
| 1193 | // 2. constant -> stack (non-cycle) |
| 1194 | // 3. GPR/FPR -> GPR/FPR |
| 1195 | // 4. GPR/FPR -> stack |
| 1196 | // 5. stack -> GPR/FPR |
| 1197 | // 6. stack -> stack (non-cycle) |
| 1198 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1199 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1200 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1201 | // dependency. |
| 1202 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1203 | } |
| 1204 | |
| 1205 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1206 | vixl_temps_.Close(); |
| 1207 | } |
| 1208 | |
| 1209 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 1210 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 1211 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 1212 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 1213 | Location scratch = GetScratchLocation(kind); |
| 1214 | if (!scratch.Equals(Location::NoLocation())) { |
| 1215 | return scratch; |
| 1216 | } |
| 1217 | // Allocate from VIXL temp registers. |
| 1218 | if (kind == Location::kRegister) { |
| 1219 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1220 | } else { |
| 1221 | DCHECK(kind == Location::kFpuRegister); |
| 1222 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1223 | } |
| 1224 | AddScratchLocation(scratch); |
| 1225 | return scratch; |
| 1226 | } |
| 1227 | |
| 1228 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1229 | if (loc.IsRegister()) { |
| 1230 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1231 | } else { |
| 1232 | DCHECK(loc.IsFpuRegister()); |
| 1233 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1234 | } |
| 1235 | RemoveScratchLocation(loc); |
| 1236 | } |
| 1237 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1238 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1239 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1240 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1243 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1244 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1245 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1246 | __ Bind(&frame_entry_label_); |
| 1247 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1248 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1249 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1250 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1251 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1252 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1253 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1254 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1255 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1256 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1257 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1258 | if (!HasEmptyFrame()) { |
| 1259 | int frame_size = GetFrameSize(); |
| 1260 | // Stack layout: |
| 1261 | // sp[frame_size - 8] : lr. |
| 1262 | // ... : other preserved core registers. |
| 1263 | // ... : other preserved fp registers. |
| 1264 | // ... : reserved frame space. |
| 1265 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1266 | |
| 1267 | // Save the current method if we need it. Note that we do not |
| 1268 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1269 | // in the SSA graph. |
| 1270 | if (RequiresCurrentMethod()) { |
| 1271 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1272 | } else { |
| 1273 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1274 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1275 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1276 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1277 | frame_size - GetCoreSpillSize()); |
| 1278 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1279 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1280 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1284 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1285 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1286 | if (!HasEmptyFrame()) { |
| 1287 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1288 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1289 | frame_size - FrameEntrySpillSize()); |
| 1290 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1291 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1292 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1293 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1294 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1295 | __ Ret(); |
| 1296 | GetAssembler()->cfi().RestoreState(); |
| 1297 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1300 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1301 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1302 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1303 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1306 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1307 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1308 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1309 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1310 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1313 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1314 | __ Bind(GetLabelOf(block)); |
| 1315 | } |
| 1316 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1317 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1318 | DCHECK(location.IsRegister()); |
| 1319 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1320 | } |
| 1321 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1322 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1323 | if (location.IsRegister()) { |
| 1324 | locations->AddTemp(location); |
| 1325 | } else { |
| 1326 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1327 | } |
| 1328 | } |
| 1329 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1330 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1331 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1332 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1333 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1334 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1335 | if (value_can_be_null) { |
| 1336 | __ Cbz(value, &done); |
| 1337 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1338 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1339 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1340 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1341 | if (value_can_be_null) { |
| 1342 | __ Bind(&done); |
| 1343 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1346 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1347 | // Blocked core registers: |
| 1348 | // lr : Runtime reserved. |
| 1349 | // tr : Runtime reserved. |
| 1350 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1351 | // ip1 : VIXL core temp. |
| 1352 | // ip0 : VIXL core temp. |
| 1353 | // |
| 1354 | // Blocked fp registers: |
| 1355 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1356 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1357 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1358 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1359 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1360 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1361 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1362 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1363 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1364 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1365 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1366 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1367 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1368 | // Stubs do not save callee-save floating point registers. If the graph |
| 1369 | // is debuggable, we need to deal with these registers differently. For |
| 1370 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1371 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1372 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1373 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1374 | } |
| 1375 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1376 | } |
| 1377 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1378 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1379 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1380 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1381 | return kArm64WordSize; |
| 1382 | } |
| 1383 | |
| 1384 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1385 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1386 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1387 | return kArm64WordSize; |
| 1388 | } |
| 1389 | |
| 1390 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1391 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1392 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1393 | return kArm64WordSize; |
| 1394 | } |
| 1395 | |
| 1396 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1397 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1398 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1399 | return kArm64WordSize; |
| 1400 | } |
| 1401 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1402 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1403 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1407 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1410 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1411 | if (constant->IsIntConstant()) { |
| 1412 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1413 | } else if (constant->IsLongConstant()) { |
| 1414 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1415 | } else if (constant->IsNullConstant()) { |
| 1416 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1417 | } else if (constant->IsFloatConstant()) { |
| 1418 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1419 | } else { |
| 1420 | DCHECK(constant->IsDoubleConstant()); |
| 1421 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1422 | } |
| 1423 | } |
| 1424 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1425 | |
| 1426 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1427 | DCHECK(constant.IsConstant()); |
| 1428 | HConstant* cst = constant.GetConstant(); |
| 1429 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1430 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1431 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1432 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1433 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1434 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1435 | } |
| 1436 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1437 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1438 | Location source, |
| 1439 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1440 | if (source.Equals(destination)) { |
| 1441 | return; |
| 1442 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1443 | |
| 1444 | // A valid move can always be inferred from the destination and source |
| 1445 | // locations. When moving from and to a register, the argument type can be |
| 1446 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1447 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1448 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1449 | |
| 1450 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1451 | if (unspecified_type) { |
| 1452 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1453 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1454 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1455 | || src_cst->IsFloatConstant() |
| 1456 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1457 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1458 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1459 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1460 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1461 | // type is appropriate. Else the source is a register, and since the |
| 1462 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1463 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1464 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1465 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1466 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1467 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1468 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1469 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1470 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1471 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1472 | __ Ldr(dst, StackOperandFrom(source)); |
| 1473 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1474 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1475 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1476 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1477 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1478 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1479 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1480 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1481 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1482 | ? Primitive::kPrimLong |
| 1483 | : Primitive::kPrimInt; |
| 1484 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1485 | } |
| 1486 | } else { |
| 1487 | DCHECK(source.IsFpuRegister()); |
| 1488 | if (destination.IsRegister()) { |
| 1489 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1490 | ? Primitive::kPrimDouble |
| 1491 | : Primitive::kPrimFloat; |
| 1492 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1493 | } else { |
| 1494 | DCHECK(destination.IsFpuRegister()); |
| 1495 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1496 | } |
| 1497 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1498 | } else { // The destination is not a register. It must be a stack slot. |
| 1499 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1500 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1501 | if (unspecified_type) { |
| 1502 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1503 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1504 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1505 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1506 | } |
| 1507 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1508 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1509 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1510 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1511 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1512 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1513 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1514 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1515 | HConstant* src_cst = source.GetConstant(); |
| 1516 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1517 | if (src_cst->IsZeroBitPattern()) { |
| 1518 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1519 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1520 | if (src_cst->IsIntConstant()) { |
| 1521 | temp = temps.AcquireW(); |
| 1522 | } else if (src_cst->IsLongConstant()) { |
| 1523 | temp = temps.AcquireX(); |
| 1524 | } else if (src_cst->IsFloatConstant()) { |
| 1525 | temp = temps.AcquireS(); |
| 1526 | } else { |
| 1527 | DCHECK(src_cst->IsDoubleConstant()); |
| 1528 | temp = temps.AcquireD(); |
| 1529 | } |
| 1530 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1531 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1532 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1533 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1534 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1535 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1536 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1537 | // There is generally less pressure on FP registers. |
| 1538 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1539 | __ Ldr(temp, StackOperandFrom(source)); |
| 1540 | __ Str(temp, StackOperandFrom(destination)); |
| 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1546 | CPURegister dst, |
| 1547 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1548 | switch (type) { |
| 1549 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1550 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1551 | break; |
| 1552 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1553 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1554 | break; |
| 1555 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1556 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1557 | break; |
| 1558 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1559 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1560 | break; |
| 1561 | case Primitive::kPrimInt: |
| 1562 | case Primitive::kPrimNot: |
| 1563 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1564 | case Primitive::kPrimFloat: |
| 1565 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1566 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1567 | __ Ldr(dst, src); |
| 1568 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1569 | case Primitive::kPrimVoid: |
| 1570 | LOG(FATAL) << "Unreachable type " << type; |
| 1571 | } |
| 1572 | } |
| 1573 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1574 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1575 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1576 | const MemOperand& src, |
| 1577 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1578 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1579 | BlockPoolsScope block_pools(masm); |
| 1580 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1581 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1582 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1583 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1584 | DCHECK(!src.IsPreIndex()); |
| 1585 | DCHECK(!src.IsPostIndex()); |
| 1586 | |
| 1587 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1588 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1589 | MemOperand base = MemOperand(temp_base); |
| 1590 | switch (type) { |
| 1591 | case Primitive::kPrimBoolean: |
| 1592 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1593 | if (needs_null_check) { |
| 1594 | MaybeRecordImplicitNullCheck(instruction); |
| 1595 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | case Primitive::kPrimByte: |
| 1598 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1599 | if (needs_null_check) { |
| 1600 | MaybeRecordImplicitNullCheck(instruction); |
| 1601 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1602 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1603 | break; |
| 1604 | case Primitive::kPrimChar: |
| 1605 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1606 | if (needs_null_check) { |
| 1607 | MaybeRecordImplicitNullCheck(instruction); |
| 1608 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1609 | break; |
| 1610 | case Primitive::kPrimShort: |
| 1611 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1612 | if (needs_null_check) { |
| 1613 | MaybeRecordImplicitNullCheck(instruction); |
| 1614 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1615 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1616 | break; |
| 1617 | case Primitive::kPrimInt: |
| 1618 | case Primitive::kPrimNot: |
| 1619 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1620 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1621 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1622 | if (needs_null_check) { |
| 1623 | MaybeRecordImplicitNullCheck(instruction); |
| 1624 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1625 | break; |
| 1626 | case Primitive::kPrimFloat: |
| 1627 | case Primitive::kPrimDouble: { |
| 1628 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1629 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1630 | |
| 1631 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1632 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1633 | if (needs_null_check) { |
| 1634 | MaybeRecordImplicitNullCheck(instruction); |
| 1635 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1636 | __ Fmov(FPRegister(dst), temp); |
| 1637 | break; |
| 1638 | } |
| 1639 | case Primitive::kPrimVoid: |
| 1640 | LOG(FATAL) << "Unreachable type " << type; |
| 1641 | } |
| 1642 | } |
| 1643 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1644 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1645 | CPURegister src, |
| 1646 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1647 | switch (type) { |
| 1648 | case Primitive::kPrimBoolean: |
| 1649 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1650 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1651 | break; |
| 1652 | case Primitive::kPrimChar: |
| 1653 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1654 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1655 | break; |
| 1656 | case Primitive::kPrimInt: |
| 1657 | case Primitive::kPrimNot: |
| 1658 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1659 | case Primitive::kPrimFloat: |
| 1660 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1661 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1662 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1663 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1664 | case Primitive::kPrimVoid: |
| 1665 | LOG(FATAL) << "Unreachable type " << type; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1669 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1670 | CPURegister src, |
| 1671 | const MemOperand& dst) { |
| 1672 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1673 | Register temp_base = temps.AcquireX(); |
| 1674 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1675 | DCHECK(!dst.IsPreIndex()); |
| 1676 | DCHECK(!dst.IsPostIndex()); |
| 1677 | |
| 1678 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1679 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1680 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1681 | MemOperand base = MemOperand(temp_base); |
| 1682 | switch (type) { |
| 1683 | case Primitive::kPrimBoolean: |
| 1684 | case Primitive::kPrimByte: |
| 1685 | __ Stlrb(Register(src), base); |
| 1686 | break; |
| 1687 | case Primitive::kPrimChar: |
| 1688 | case Primitive::kPrimShort: |
| 1689 | __ Stlrh(Register(src), base); |
| 1690 | break; |
| 1691 | case Primitive::kPrimInt: |
| 1692 | case Primitive::kPrimNot: |
| 1693 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1694 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1695 | __ Stlr(Register(src), base); |
| 1696 | break; |
| 1697 | case Primitive::kPrimFloat: |
| 1698 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1699 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1700 | Register temp_src; |
| 1701 | if (src.IsZero()) { |
| 1702 | // The zero register is used to avoid synthesizing zero constants. |
| 1703 | temp_src = Register(src); |
| 1704 | } else { |
| 1705 | DCHECK(src.IsFPRegister()); |
| 1706 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1707 | __ Fmov(temp_src, FPRegister(src)); |
| 1708 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1709 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1710 | __ Stlr(temp_src, base); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1711 | break; |
| 1712 | } |
| 1713 | case Primitive::kPrimVoid: |
| 1714 | LOG(FATAL) << "Unreachable type " << type; |
| 1715 | } |
| 1716 | } |
| 1717 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1718 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1719 | HInstruction* instruction, |
| 1720 | uint32_t dex_pc, |
| 1721 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1722 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1723 | GenerateInvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1724 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1725 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1726 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1729 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1730 | HInstruction* instruction, |
| 1731 | SlowPathCode* slow_path) { |
| 1732 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1733 | GenerateInvokeRuntime(entry_point_offset); |
| 1734 | } |
| 1735 | |
| 1736 | void CodeGeneratorARM64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1737 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 1738 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1739 | __ Blr(lr); |
| 1740 | } |
| 1741 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1742 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1743 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1744 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1745 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1746 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1747 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1748 | // 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] | 1749 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1750 | __ Add(temp, class_reg, status_offset); |
| 1751 | __ Ldar(temp, HeapOperand(temp)); |
| 1752 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1753 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1754 | __ Bind(slow_path->GetExitLabel()); |
| 1755 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1756 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1757 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1758 | BarrierType type = BarrierAll; |
| 1759 | |
| 1760 | switch (kind) { |
| 1761 | case MemBarrierKind::kAnyAny: |
| 1762 | case MemBarrierKind::kAnyStore: { |
| 1763 | type = BarrierAll; |
| 1764 | break; |
| 1765 | } |
| 1766 | case MemBarrierKind::kLoadAny: { |
| 1767 | type = BarrierReads; |
| 1768 | break; |
| 1769 | } |
| 1770 | case MemBarrierKind::kStoreStore: { |
| 1771 | type = BarrierWrites; |
| 1772 | break; |
| 1773 | } |
| 1774 | default: |
| 1775 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1776 | } |
| 1777 | __ Dmb(InnerShareable, type); |
| 1778 | } |
| 1779 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1780 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1781 | HBasicBlock* successor) { |
| 1782 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1783 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1784 | if (slow_path == nullptr) { |
| 1785 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1786 | instruction->SetSlowPath(slow_path); |
| 1787 | codegen_->AddSlowPath(slow_path); |
| 1788 | if (successor != nullptr) { |
| 1789 | DCHECK(successor->IsLoopHeader()); |
| 1790 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1791 | } |
| 1792 | } else { |
| 1793 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1794 | } |
| 1795 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1796 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1797 | Register temp = temps.AcquireW(); |
| 1798 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1799 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1800 | if (successor == nullptr) { |
| 1801 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1802 | __ Bind(slow_path->GetReturnLabel()); |
| 1803 | } else { |
| 1804 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1805 | __ B(slow_path->GetEntryLabel()); |
| 1806 | // slow_path will return to GetLabelOf(successor). |
| 1807 | } |
| 1808 | } |
| 1809 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1810 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1811 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1812 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1813 | assembler_(codegen->GetAssembler()), |
| 1814 | codegen_(codegen) {} |
| 1815 | |
| 1816 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1817 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1818 | |
| 1819 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1820 | |
| 1821 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1822 | // Using a base helps identify when we hit such breakpoints. |
| 1823 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1824 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1825 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1826 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1827 | }; |
| 1828 | |
| 1829 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1830 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1831 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1832 | } \ |
| 1833 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1834 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1835 | locations->SetOut(Location::Any()); \ |
| 1836 | } |
| 1837 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1838 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1839 | |
| 1840 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1841 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1842 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1843 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1844 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1845 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1846 | Primitive::Type type = instr->GetResultType(); |
| 1847 | switch (type) { |
| 1848 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1849 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1850 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1851 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1852 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1853 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1854 | |
| 1855 | case Primitive::kPrimFloat: |
| 1856 | case Primitive::kPrimDouble: |
| 1857 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1858 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1859 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1860 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1861 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1862 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1863 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1867 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1868 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1869 | |
| 1870 | bool object_field_get_with_read_barrier = |
| 1871 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1872 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1873 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1874 | object_field_get_with_read_barrier ? |
| 1875 | LocationSummary::kCallOnSlowPath : |
| 1876 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1877 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1878 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1879 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1881 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1882 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1883 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1884 | // The output overlaps for an object field get when read barriers |
| 1885 | // are enabled: we do not want the load to overwrite the object's |
| 1886 | // location, as we need it to emit the read barrier. |
| 1887 | locations->SetOut( |
| 1888 | Location::RequiresRegister(), |
| 1889 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1894 | const FieldInfo& field_info) { |
| 1895 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1896 | LocationSummary* locations = instruction->GetLocations(); |
| 1897 | Location base_loc = locations->InAt(0); |
| 1898 | Location out = locations->Out(); |
| 1899 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1900 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1901 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1902 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1903 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1904 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1905 | // Object FieldGet with Baker's read barrier case. |
| 1906 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1907 | UseScratchRegisterScope temps(masm); |
| 1908 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1909 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1910 | Register temp = temps.AcquireW(); |
| 1911 | // Note that potential implicit null checks are handled in this |
| 1912 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1913 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1914 | instruction, |
| 1915 | out, |
| 1916 | base, |
| 1917 | offset, |
| 1918 | temp, |
| 1919 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1920 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1921 | } else { |
| 1922 | // General case. |
| 1923 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1924 | // Note that a potential implicit null check is handled in this |
| 1925 | // CodeGeneratorARM64::LoadAcquire call. |
| 1926 | // NB: LoadAcquire will record the pc info if needed. |
| 1927 | codegen_->LoadAcquire( |
| 1928 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1929 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1930 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1931 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1932 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1933 | if (field_type == Primitive::kPrimNot) { |
| 1934 | // If read barriers are enabled, emit read barriers other than |
| 1935 | // Baker's using a slow path (and also unpoison the loaded |
| 1936 | // reference, if heap poisoning is enabled). |
| 1937 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1938 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1939 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1943 | LocationSummary* locations = |
| 1944 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1945 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1946 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 1947 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 1948 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1949 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1950 | } else { |
| 1951 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1956 | const FieldInfo& field_info, |
| 1957 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1958 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1959 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1960 | |
| 1961 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1962 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1963 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1964 | Offset offset = field_info.GetFieldOffset(); |
| 1965 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1966 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1967 | { |
| 1968 | // We use a block to end the scratch scope before the write barrier, thus |
| 1969 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1970 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1971 | |
| 1972 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1973 | DCHECK(value.IsW()); |
| 1974 | Register temp = temps.AcquireW(); |
| 1975 | __ Mov(temp, value.W()); |
| 1976 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1977 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1978 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1979 | |
| 1980 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1981 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1982 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1983 | } else { |
| 1984 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1985 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1986 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1990 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1994 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1995 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1996 | |
| 1997 | switch (type) { |
| 1998 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1999 | case Primitive::kPrimLong: { |
| 2000 | Register dst = OutputRegister(instr); |
| 2001 | Register lhs = InputRegisterAt(instr, 0); |
| 2002 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2003 | if (instr->IsAdd()) { |
| 2004 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2005 | } else if (instr->IsAnd()) { |
| 2006 | __ And(dst, lhs, rhs); |
| 2007 | } else if (instr->IsOr()) { |
| 2008 | __ Orr(dst, lhs, rhs); |
| 2009 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2010 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2011 | } else if (instr->IsRor()) { |
| 2012 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2013 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2014 | __ Ror(dst, lhs, shift); |
| 2015 | } else { |
| 2016 | // Ensure shift distance is in the same size register as the result. If |
| 2017 | // we are rotating a long and the shift comes in a w register originally, |
| 2018 | // we don't need to sxtw for use as an x since the shift distances are |
| 2019 | // all & reg_bits - 1. |
| 2020 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2021 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2022 | } else { |
| 2023 | DCHECK(instr->IsXor()); |
| 2024 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2025 | } |
| 2026 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2027 | } |
| 2028 | case Primitive::kPrimFloat: |
| 2029 | case Primitive::kPrimDouble: { |
| 2030 | FPRegister dst = OutputFPRegister(instr); |
| 2031 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2032 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2033 | if (instr->IsAdd()) { |
| 2034 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2035 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2036 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2037 | } else { |
| 2038 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2039 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2040 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2041 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2042 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2043 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2047 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2048 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2049 | |
| 2050 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2051 | Primitive::Type type = instr->GetResultType(); |
| 2052 | switch (type) { |
| 2053 | case Primitive::kPrimInt: |
| 2054 | case Primitive::kPrimLong: { |
| 2055 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2056 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2057 | locations->SetOut(Location::RequiresRegister()); |
| 2058 | break; |
| 2059 | } |
| 2060 | default: |
| 2061 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2066 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2067 | |
| 2068 | Primitive::Type type = instr->GetType(); |
| 2069 | switch (type) { |
| 2070 | case Primitive::kPrimInt: |
| 2071 | case Primitive::kPrimLong: { |
| 2072 | Register dst = OutputRegister(instr); |
| 2073 | Register lhs = InputRegisterAt(instr, 0); |
| 2074 | Operand rhs = InputOperandAt(instr, 1); |
| 2075 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2076 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2077 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2078 | if (instr->IsShl()) { |
| 2079 | __ Lsl(dst, lhs, shift_value); |
| 2080 | } else if (instr->IsShr()) { |
| 2081 | __ Asr(dst, lhs, shift_value); |
| 2082 | } else { |
| 2083 | __ Lsr(dst, lhs, shift_value); |
| 2084 | } |
| 2085 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2086 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2087 | |
| 2088 | if (instr->IsShl()) { |
| 2089 | __ Lsl(dst, lhs, rhs_reg); |
| 2090 | } else if (instr->IsShr()) { |
| 2091 | __ Asr(dst, lhs, rhs_reg); |
| 2092 | } else { |
| 2093 | __ Lsr(dst, lhs, rhs_reg); |
| 2094 | } |
| 2095 | } |
| 2096 | break; |
| 2097 | } |
| 2098 | default: |
| 2099 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2100 | } |
| 2101 | } |
| 2102 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2103 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2104 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2108 | HandleBinaryOp(instruction); |
| 2109 | } |
| 2110 | |
| 2111 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2112 | HandleBinaryOp(instruction); |
| 2113 | } |
| 2114 | |
| 2115 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2116 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2119 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2120 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2121 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2123 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2124 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2125 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2126 | } |
| 2127 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2128 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2129 | Register dst = OutputRegister(instr); |
| 2130 | Register lhs = InputRegisterAt(instr, 0); |
| 2131 | Register rhs = InputRegisterAt(instr, 1); |
| 2132 | |
| 2133 | switch (instr->GetOpKind()) { |
| 2134 | case HInstruction::kAnd: |
| 2135 | __ Bic(dst, lhs, rhs); |
| 2136 | break; |
| 2137 | case HInstruction::kOr: |
| 2138 | __ Orn(dst, lhs, rhs); |
| 2139 | break; |
| 2140 | case HInstruction::kXor: |
| 2141 | __ Eon(dst, lhs, rhs); |
| 2142 | break; |
| 2143 | default: |
| 2144 | LOG(FATAL) << "Unreachable"; |
| 2145 | } |
| 2146 | } |
| 2147 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2148 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 2149 | HArm64DataProcWithShifterOp* instruction) { |
| 2150 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2151 | instruction->GetType() == Primitive::kPrimLong); |
| 2152 | LocationSummary* locations = |
| 2153 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2154 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2155 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2156 | } else { |
| 2157 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2158 | } |
| 2159 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2160 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2161 | } |
| 2162 | |
| 2163 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 2164 | HArm64DataProcWithShifterOp* instruction) { |
| 2165 | Primitive::Type type = instruction->GetType(); |
| 2166 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2167 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2168 | Register out = OutputRegister(instruction); |
| 2169 | Register left; |
| 2170 | if (kind != HInstruction::kNeg) { |
| 2171 | left = InputRegisterAt(instruction, 0); |
| 2172 | } |
| 2173 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 2174 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2175 | // conversion) can have a different type from the current instruction's type, |
| 2176 | // so we manually indicate the type. |
| 2177 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2178 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 2179 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2180 | |
| 2181 | Operand right_operand(0); |
| 2182 | |
| 2183 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2184 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 2185 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2186 | } else { |
| 2187 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 2188 | } |
| 2189 | |
| 2190 | // Logical binary operations do not support extension operations in the |
| 2191 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2192 | // the extension as a separate instruction. |
| 2193 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2194 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2195 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2196 | kind != HInstruction::kNeg)); |
| 2197 | switch (kind) { |
| 2198 | case HInstruction::kAdd: |
| 2199 | __ Add(out, left, right_operand); |
| 2200 | break; |
| 2201 | case HInstruction::kAnd: |
| 2202 | __ And(out, left, right_operand); |
| 2203 | break; |
| 2204 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2205 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2206 | __ Neg(out, right_operand); |
| 2207 | break; |
| 2208 | case HInstruction::kOr: |
| 2209 | __ Orr(out, left, right_operand); |
| 2210 | break; |
| 2211 | case HInstruction::kSub: |
| 2212 | __ Sub(out, left, right_operand); |
| 2213 | break; |
| 2214 | case HInstruction::kXor: |
| 2215 | __ Eor(out, left, right_operand); |
| 2216 | break; |
| 2217 | default: |
| 2218 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2219 | UNREACHABLE(); |
| 2220 | } |
| 2221 | } |
| 2222 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2223 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2224 | LocationSummary* locations = |
| 2225 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2226 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2227 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 2228 | locations->SetOut(Location::RequiresRegister()); |
| 2229 | } |
| 2230 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2231 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2232 | __ Add(OutputRegister(instruction), |
| 2233 | InputRegisterAt(instruction, 0), |
| 2234 | Operand(InputOperandAt(instruction, 1))); |
| 2235 | } |
| 2236 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2237 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2238 | LocationSummary* locations = |
| 2239 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2240 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2241 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2242 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2243 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2244 | // Don't allocate register for Mneg instruction. |
| 2245 | } else { |
| 2246 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2247 | Location::RequiresRegister()); |
| 2248 | } |
| 2249 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2250 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2251 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2252 | } |
| 2253 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2254 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2255 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2256 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2257 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2258 | |
| 2259 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2260 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2261 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2262 | if (instr->GetType() == Primitive::kPrimLong && |
| 2263 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2264 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2265 | vixl::aarch64::Instruction* prev = |
| 2266 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2267 | if (prev->IsLoadOrStore()) { |
| 2268 | // Make sure we emit only exactly one nop. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2269 | vixl::aarch64::CodeBufferCheckScope scope(masm, |
| 2270 | kInstructionSize, |
| 2271 | vixl::aarch64::CodeBufferCheckScope::kCheck, |
| 2272 | vixl::aarch64::CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2273 | __ nop(); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2278 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2279 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2280 | } else { |
| 2281 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2282 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2283 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2284 | __ Mneg(res, mul_left, mul_right); |
| 2285 | } else { |
| 2286 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2287 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2288 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2292 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2293 | bool object_array_get_with_read_barrier = |
| 2294 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2295 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2296 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2297 | object_array_get_with_read_barrier ? |
| 2298 | LocationSummary::kCallOnSlowPath : |
| 2299 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2300 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2301 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2302 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2303 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2304 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2305 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2306 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2307 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2308 | // The output overlaps in the case of an object array get with |
| 2309 | // read barriers enabled: we do not want the move to overwrite the |
| 2310 | // array's location, as we need it to emit the read barrier. |
| 2311 | locations->SetOut( |
| 2312 | Location::RequiresRegister(), |
| 2313 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2314 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2318 | Primitive::Type type = instruction->GetType(); |
| 2319 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2320 | LocationSummary* locations = instruction->GetLocations(); |
| 2321 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2322 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2323 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2324 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2325 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2326 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2327 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2328 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2329 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2330 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2331 | // The read barrier instrumentation of object ArrayGet instructions |
| 2332 | // does not support the HIntermediateAddress instruction. |
| 2333 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2334 | instruction->GetArray()->IsIntermediateAddress() && |
| 2335 | kEmitCompilerReadBarrier)); |
| 2336 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2337 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2338 | // Object ArrayGet with Baker's read barrier case. |
| 2339 | Register temp = temps.AcquireW(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2340 | // Note that a potential implicit null check is handled in the |
| 2341 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2342 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2343 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2344 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2345 | // General case. |
| 2346 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2347 | Register length; |
| 2348 | if (maybe_compressed_char_at) { |
| 2349 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2350 | length = temps.AcquireW(); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2351 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2352 | DCHECK_LT(count_offset, offset); |
| 2353 | int64_t adjusted_offset = static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2354 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2355 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2356 | } else { |
| 2357 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2358 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2359 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2360 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2361 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2362 | if (maybe_compressed_char_at) { |
| 2363 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2364 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2365 | "Expecting 0=compressed, 1=uncompressed"); |
| 2366 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2367 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2368 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2369 | __ B(&done); |
| 2370 | __ Bind(&uncompressed_load); |
| 2371 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2372 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2373 | __ Bind(&done); |
| 2374 | } else { |
| 2375 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2376 | source = HeapOperand(obj, offset); |
| 2377 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2378 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2379 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2380 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2381 | // We do not need to compute the intermediate address from the array: the |
| 2382 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2383 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2384 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2385 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2386 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2387 | } |
| 2388 | temp = obj; |
| 2389 | } else { |
| 2390 | __ Add(temp, obj, offset); |
| 2391 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2392 | if (maybe_compressed_char_at) { |
| 2393 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2394 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2395 | "Expecting 0=compressed, 1=uncompressed"); |
| 2396 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2397 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2398 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2399 | __ B(&done); |
| 2400 | __ Bind(&uncompressed_load); |
| 2401 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2402 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2403 | __ Bind(&done); |
| 2404 | } else { |
| 2405 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2406 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2407 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2408 | if (!maybe_compressed_char_at) { |
| 2409 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2410 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2411 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2412 | |
| 2413 | if (type == Primitive::kPrimNot) { |
| 2414 | static_assert( |
| 2415 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2416 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2417 | Location obj_loc = locations->InAt(0); |
| 2418 | if (index.IsConstant()) { |
| 2419 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2420 | } else { |
| 2421 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2422 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2423 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2424 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2427 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2428 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2429 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2430 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2434 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2435 | vixl::aarch64::Register out = OutputRegister(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2436 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2437 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2438 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2439 | // Mask out compression flag from String's array length. |
| 2440 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2441 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2442 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2443 | } |
| 2444 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2445 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2446 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2447 | |
| 2448 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2449 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2450 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2451 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2452 | LocationSummary::kCallOnSlowPath : |
| 2453 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2455 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2456 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2457 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2458 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2459 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2460 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2461 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2466 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2467 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2468 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2469 | bool needs_write_barrier = |
| 2470 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2471 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2472 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2473 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2474 | CPURegister source = value; |
| 2475 | Location index = locations->InAt(1); |
| 2476 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2477 | MemOperand destination = HeapOperand(array); |
| 2478 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2479 | BlockPoolsScope block_pools(masm); |
| 2480 | |
| 2481 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2482 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2483 | if (index.IsConstant()) { |
| 2484 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2485 | destination = HeapOperand(array, offset); |
| 2486 | } else { |
| 2487 | UseScratchRegisterScope temps(masm); |
| 2488 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2489 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2490 | // We do not need to compute the intermediate address from the array: the |
| 2491 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2492 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2493 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2494 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2495 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2496 | } |
| 2497 | temp = array; |
| 2498 | } else { |
| 2499 | __ Add(temp, array, offset); |
| 2500 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2501 | destination = HeapOperand(temp, |
| 2502 | XRegisterFrom(index), |
| 2503 | LSL, |
| 2504 | Primitive::ComponentSizeShift(value_type)); |
| 2505 | } |
| 2506 | codegen_->Store(value_type, value, destination); |
| 2507 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2508 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2509 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2510 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2511 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2512 | { |
| 2513 | // We use a block to end the scratch scope before the write barrier, thus |
| 2514 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2515 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2516 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2517 | if (index.IsConstant()) { |
| 2518 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2519 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2520 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2521 | destination = HeapOperand(temp, |
| 2522 | XRegisterFrom(index), |
| 2523 | LSL, |
| 2524 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2525 | } |
| 2526 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2527 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2528 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2529 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2530 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2531 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2532 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2533 | codegen_->AddSlowPath(slow_path); |
| 2534 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2535 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2536 | __ Cbnz(Register(value), &non_zero); |
| 2537 | if (!index.IsConstant()) { |
| 2538 | __ Add(temp, array, offset); |
| 2539 | } |
| 2540 | __ Str(wzr, destination); |
| 2541 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2542 | __ B(&done); |
| 2543 | __ Bind(&non_zero); |
| 2544 | } |
| 2545 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2546 | // Note that when Baker read barriers are enabled, the type |
| 2547 | // checks are performed without read barriers. This is fine, |
| 2548 | // even in the case where a class object is in the from-space |
| 2549 | // after the flip, as a comparison involving such a type would |
| 2550 | // not produce a false positive; it may of course produce a |
| 2551 | // false negative, in which case we would take the ArraySet |
| 2552 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2553 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2554 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2555 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2556 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2557 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2558 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2559 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2560 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2561 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2562 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2563 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2564 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2565 | // nor `temp2`, as we are comparing two poisoned references. |
| 2566 | __ Cmp(temp, temp2); |
| 2567 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2568 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2569 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2570 | vixl::aarch64::Label do_put; |
| 2571 | __ B(eq, &do_put); |
| 2572 | // If heap poisoning is enabled, the `temp` reference has |
| 2573 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2574 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2575 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2576 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2577 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2578 | // If heap poisoning is enabled, no need to unpoison |
| 2579 | // `temp`, as we are comparing against null below. |
| 2580 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2581 | __ Bind(&do_put); |
| 2582 | } else { |
| 2583 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2588 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2589 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2590 | __ Mov(temp2, value.W()); |
| 2591 | GetAssembler()->PoisonHeapReference(temp2); |
| 2592 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | if (!index.IsConstant()) { |
| 2596 | __ Add(temp, array, offset); |
| 2597 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2598 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2599 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2600 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2601 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2602 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2603 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2604 | |
| 2605 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2606 | |
| 2607 | if (done.IsLinked()) { |
| 2608 | __ Bind(&done); |
| 2609 | } |
| 2610 | |
| 2611 | if (slow_path != nullptr) { |
| 2612 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2613 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2614 | } |
| 2615 | } |
| 2616 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2617 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2618 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2619 | InvokeRuntimeCallingConvention calling_convention; |
| 2620 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2621 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2622 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2623 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2624 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2628 | BoundsCheckSlowPathARM64* slow_path = |
| 2629 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2630 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2631 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2632 | __ B(slow_path->GetEntryLabel(), hs); |
| 2633 | } |
| 2634 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2635 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2636 | LocationSummary* locations = |
| 2637 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2639 | if (check->HasUses()) { |
| 2640 | locations->SetOut(Location::SameAsFirstInput()); |
| 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2645 | // We assume the class is not null. |
| 2646 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2647 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2648 | codegen_->AddSlowPath(slow_path); |
| 2649 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2650 | } |
| 2651 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2652 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2653 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2654 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2655 | } |
| 2656 | |
| 2657 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2658 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2659 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2660 | if (rhs_loc.IsConstant()) { |
| 2661 | // 0.0 is the only immediate that can be encoded directly in |
| 2662 | // an FCMP instruction. |
| 2663 | // |
| 2664 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2665 | // specify that in a floating-point comparison, positive zero |
| 2666 | // and negative zero are considered equal, so we can use the |
| 2667 | // literal 0.0 for both cases here. |
| 2668 | // |
| 2669 | // Note however that some methods (Float.equal, Float.compare, |
| 2670 | // Float.compareTo, Double.equal, Double.compare, |
| 2671 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2672 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2673 | // -0.0. So if we ever translate calls to these methods into a |
| 2674 | // HCompare instruction, we must handle the -0.0 case with |
| 2675 | // care here. |
| 2676 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2677 | __ Fcmp(lhs_reg, 0.0); |
| 2678 | } else { |
| 2679 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2680 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2683 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2684 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2685 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2686 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2687 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimBoolean: |
| 2689 | case Primitive::kPrimByte: |
| 2690 | case Primitive::kPrimShort: |
| 2691 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2692 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2693 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2694 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2695 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2696 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2697 | break; |
| 2698 | } |
| 2699 | case Primitive::kPrimFloat: |
| 2700 | case Primitive::kPrimDouble: { |
| 2701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2702 | locations->SetInAt(1, |
| 2703 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2704 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2705 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2706 | locations->SetOut(Location::RequiresRegister()); |
| 2707 | break; |
| 2708 | } |
| 2709 | default: |
| 2710 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2715 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2716 | |
| 2717 | // 0 if: left == right |
| 2718 | // 1 if: left > right |
| 2719 | // -1 if: left < right |
| 2720 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2721 | case Primitive::kPrimBoolean: |
| 2722 | case Primitive::kPrimByte: |
| 2723 | case Primitive::kPrimShort: |
| 2724 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2725 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimLong: { |
| 2727 | Register result = OutputRegister(compare); |
| 2728 | Register left = InputRegisterAt(compare, 0); |
| 2729 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2730 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2731 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2732 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2733 | break; |
| 2734 | } |
| 2735 | case Primitive::kPrimFloat: |
| 2736 | case Primitive::kPrimDouble: { |
| 2737 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2738 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2739 | __ Cset(result, ne); |
| 2740 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2741 | break; |
| 2742 | } |
| 2743 | default: |
| 2744 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2745 | } |
| 2746 | } |
| 2747 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2748 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2749 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2750 | |
| 2751 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2752 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2753 | locations->SetInAt(1, |
| 2754 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2755 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2756 | : Location::RequiresFpuRegister()); |
| 2757 | } else { |
| 2758 | // Integer cases. |
| 2759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2760 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2761 | } |
| 2762 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2763 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2764 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2765 | } |
| 2766 | } |
| 2767 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2768 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2769 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2770 | return; |
| 2771 | } |
| 2772 | |
| 2773 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2774 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2775 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2776 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2777 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2778 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2779 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2780 | } else { |
| 2781 | // Integer cases. |
| 2782 | Register lhs = InputRegisterAt(instruction, 0); |
| 2783 | Operand rhs = InputOperandAt(instruction, 1); |
| 2784 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2785 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2786 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2790 | M(Equal) \ |
| 2791 | M(NotEqual) \ |
| 2792 | M(LessThan) \ |
| 2793 | M(LessThanOrEqual) \ |
| 2794 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2795 | M(GreaterThanOrEqual) \ |
| 2796 | M(Below) \ |
| 2797 | M(BelowOrEqual) \ |
| 2798 | M(Above) \ |
| 2799 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2800 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2801 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2802 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2803 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2804 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2805 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2806 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2807 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2808 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2809 | |
| 2810 | LocationSummary* locations = instruction->GetLocations(); |
| 2811 | Location second = locations->InAt(1); |
| 2812 | DCHECK(second.IsConstant()); |
| 2813 | |
| 2814 | Register out = OutputRegister(instruction); |
| 2815 | Register dividend = InputRegisterAt(instruction, 0); |
| 2816 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2817 | DCHECK(imm == 1 || imm == -1); |
| 2818 | |
| 2819 | if (instruction->IsRem()) { |
| 2820 | __ Mov(out, 0); |
| 2821 | } else { |
| 2822 | if (imm == 1) { |
| 2823 | __ Mov(out, dividend); |
| 2824 | } else { |
| 2825 | __ Neg(out, dividend); |
| 2826 | } |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2831 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2832 | |
| 2833 | LocationSummary* locations = instruction->GetLocations(); |
| 2834 | Location second = locations->InAt(1); |
| 2835 | DCHECK(second.IsConstant()); |
| 2836 | |
| 2837 | Register out = OutputRegister(instruction); |
| 2838 | Register dividend = InputRegisterAt(instruction, 0); |
| 2839 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2840 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2841 | int ctz_imm = CTZ(abs_imm); |
| 2842 | |
| 2843 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2844 | Register temp = temps.AcquireSameSizeAs(out); |
| 2845 | |
| 2846 | if (instruction->IsDiv()) { |
| 2847 | __ Add(temp, dividend, abs_imm - 1); |
| 2848 | __ Cmp(dividend, 0); |
| 2849 | __ Csel(out, temp, dividend, lt); |
| 2850 | if (imm > 0) { |
| 2851 | __ Asr(out, out, ctz_imm); |
| 2852 | } else { |
| 2853 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2854 | } |
| 2855 | } else { |
| 2856 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2857 | __ Asr(temp, dividend, bits - 1); |
| 2858 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2859 | __ Add(out, dividend, temp); |
| 2860 | __ And(out, out, abs_imm - 1); |
| 2861 | __ Sub(out, out, temp); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2866 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2867 | |
| 2868 | LocationSummary* locations = instruction->GetLocations(); |
| 2869 | Location second = locations->InAt(1); |
| 2870 | DCHECK(second.IsConstant()); |
| 2871 | |
| 2872 | Register out = OutputRegister(instruction); |
| 2873 | Register dividend = InputRegisterAt(instruction, 0); |
| 2874 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2875 | |
| 2876 | Primitive::Type type = instruction->GetResultType(); |
| 2877 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2878 | |
| 2879 | int64_t magic; |
| 2880 | int shift; |
| 2881 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2882 | |
| 2883 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2884 | Register temp = temps.AcquireSameSizeAs(out); |
| 2885 | |
| 2886 | // temp = get_high(dividend * magic) |
| 2887 | __ Mov(temp, magic); |
| 2888 | if (type == Primitive::kPrimLong) { |
| 2889 | __ Smulh(temp, dividend, temp); |
| 2890 | } else { |
| 2891 | __ Smull(temp.X(), dividend, temp); |
| 2892 | __ Lsr(temp.X(), temp.X(), 32); |
| 2893 | } |
| 2894 | |
| 2895 | if (imm > 0 && magic < 0) { |
| 2896 | __ Add(temp, temp, dividend); |
| 2897 | } else if (imm < 0 && magic > 0) { |
| 2898 | __ Sub(temp, temp, dividend); |
| 2899 | } |
| 2900 | |
| 2901 | if (shift != 0) { |
| 2902 | __ Asr(temp, temp, shift); |
| 2903 | } |
| 2904 | |
| 2905 | if (instruction->IsDiv()) { |
| 2906 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2907 | } else { |
| 2908 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2909 | // TODO: Strength reduction for msub. |
| 2910 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2911 | __ Mov(temp_imm, imm); |
| 2912 | __ Msub(out, temp, temp_imm, dividend); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2917 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2918 | Primitive::Type type = instruction->GetResultType(); |
| 2919 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2920 | |
| 2921 | LocationSummary* locations = instruction->GetLocations(); |
| 2922 | Register out = OutputRegister(instruction); |
| 2923 | Location second = locations->InAt(1); |
| 2924 | |
| 2925 | if (second.IsConstant()) { |
| 2926 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2927 | |
| 2928 | if (imm == 0) { |
| 2929 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2930 | } else if (imm == 1 || imm == -1) { |
| 2931 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2932 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2933 | DivRemByPowerOfTwo(instruction); |
| 2934 | } else { |
| 2935 | DCHECK(imm <= -2 || imm >= 2); |
| 2936 | GenerateDivRemWithAnyConstant(instruction); |
| 2937 | } |
| 2938 | } else { |
| 2939 | Register dividend = InputRegisterAt(instruction, 0); |
| 2940 | Register divisor = InputRegisterAt(instruction, 1); |
| 2941 | if (instruction->IsDiv()) { |
| 2942 | __ Sdiv(out, dividend, divisor); |
| 2943 | } else { |
| 2944 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2945 | Register temp = temps.AcquireSameSizeAs(out); |
| 2946 | __ Sdiv(temp, dividend, divisor); |
| 2947 | __ Msub(out, temp, divisor, dividend); |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2952 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2953 | LocationSummary* locations = |
| 2954 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2955 | switch (div->GetResultType()) { |
| 2956 | case Primitive::kPrimInt: |
| 2957 | case Primitive::kPrimLong: |
| 2958 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2959 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2960 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2961 | break; |
| 2962 | |
| 2963 | case Primitive::kPrimFloat: |
| 2964 | case Primitive::kPrimDouble: |
| 2965 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2966 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2967 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2968 | break; |
| 2969 | |
| 2970 | default: |
| 2971 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2976 | Primitive::Type type = div->GetResultType(); |
| 2977 | switch (type) { |
| 2978 | case Primitive::kPrimInt: |
| 2979 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2980 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2981 | break; |
| 2982 | |
| 2983 | case Primitive::kPrimFloat: |
| 2984 | case Primitive::kPrimDouble: |
| 2985 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2986 | break; |
| 2987 | |
| 2988 | default: |
| 2989 | LOG(FATAL) << "Unexpected div type " << type; |
| 2990 | } |
| 2991 | } |
| 2992 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2993 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2994 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2995 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2999 | SlowPathCodeARM64* slow_path = |
| 3000 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3001 | codegen_->AddSlowPath(slow_path); |
| 3002 | Location value = instruction->GetLocations()->InAt(0); |
| 3003 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3004 | Primitive::Type type = instruction->GetType(); |
| 3005 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3006 | if (!Primitive::IsIntegralType(type)) { |
| 3007 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3008 | return; |
| 3009 | } |
| 3010 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3011 | if (value.IsConstant()) { |
| 3012 | int64_t divisor = Int64ConstantFrom(value); |
| 3013 | if (divisor == 0) { |
| 3014 | __ B(slow_path->GetEntryLabel()); |
| 3015 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3016 | // A division by a non-null constant is valid. We don't need to perform |
| 3017 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3018 | } |
| 3019 | } else { |
| 3020 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3021 | } |
| 3022 | } |
| 3023 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3024 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3025 | LocationSummary* locations = |
| 3026 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3027 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3028 | } |
| 3029 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3030 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3031 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3032 | // Will be generated at use site. |
| 3033 | } |
| 3034 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3035 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3036 | exit->SetLocations(nullptr); |
| 3037 | } |
| 3038 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3039 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3040 | } |
| 3041 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3042 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3043 | LocationSummary* locations = |
| 3044 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3045 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3046 | } |
| 3047 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3048 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3049 | // Will be generated at use site. |
| 3050 | } |
| 3051 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3052 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3053 | DCHECK(!successor->IsExitBlock()); |
| 3054 | HBasicBlock* block = got->GetBlock(); |
| 3055 | HInstruction* previous = got->GetPrevious(); |
| 3056 | HLoopInformation* info = block->GetLoopInformation(); |
| 3057 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3058 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3059 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3060 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3061 | return; |
| 3062 | } |
| 3063 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3064 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3065 | } |
| 3066 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3067 | __ B(codegen_->GetLabelOf(successor)); |
| 3068 | } |
| 3069 | } |
| 3070 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3071 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3072 | got->SetLocations(nullptr); |
| 3073 | } |
| 3074 | |
| 3075 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3076 | HandleGoto(got, got->GetSuccessor()); |
| 3077 | } |
| 3078 | |
| 3079 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3080 | try_boundary->SetLocations(nullptr); |
| 3081 | } |
| 3082 | |
| 3083 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3084 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3085 | if (!successor->IsExitBlock()) { |
| 3086 | HandleGoto(try_boundary, successor); |
| 3087 | } |
| 3088 | } |
| 3089 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3090 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3091 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3092 | vixl::aarch64::Label* true_target, |
| 3093 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3094 | // FP branching requires both targets to be explicit. If either of the targets |
| 3095 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3096 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3097 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3098 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3099 | if (true_target == nullptr && false_target == nullptr) { |
| 3100 | // Nothing to do. The code always falls through. |
| 3101 | return; |
| 3102 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3103 | // Constant condition, statically compared against "true" (integer value 1). |
| 3104 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3105 | if (true_target != nullptr) { |
| 3106 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3107 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3108 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3109 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3110 | if (false_target != nullptr) { |
| 3111 | __ B(false_target); |
| 3112 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3113 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3114 | return; |
| 3115 | } |
| 3116 | |
| 3117 | // The following code generates these patterns: |
| 3118 | // (1) true_target == nullptr && false_target != nullptr |
| 3119 | // - opposite condition true => branch to false_target |
| 3120 | // (2) true_target != nullptr && false_target == nullptr |
| 3121 | // - condition true => branch to true_target |
| 3122 | // (3) true_target != nullptr && false_target != nullptr |
| 3123 | // - condition true => branch to true_target |
| 3124 | // - branch to false_target |
| 3125 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3126 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3127 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3128 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3129 | if (true_target == nullptr) { |
| 3130 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3131 | } else { |
| 3132 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3133 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3134 | } else { |
| 3135 | // The condition instruction has not been materialized, use its inputs as |
| 3136 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3137 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3138 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3139 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3140 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3141 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3142 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3143 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3144 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3145 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3146 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3147 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3148 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3149 | // Integer cases. |
| 3150 | Register lhs = InputRegisterAt(condition, 0); |
| 3151 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3152 | |
| 3153 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3154 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3155 | if (true_target == nullptr) { |
| 3156 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3157 | non_fallthrough_target = false_target; |
| 3158 | } else { |
| 3159 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3160 | non_fallthrough_target = true_target; |
| 3161 | } |
| 3162 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3163 | 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] | 3164 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3165 | switch (arm64_cond) { |
| 3166 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3167 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3168 | break; |
| 3169 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3170 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | case lt: |
| 3173 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3174 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3175 | break; |
| 3176 | case ge: |
| 3177 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3178 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3179 | break; |
| 3180 | default: |
| 3181 | // Without the `static_cast` the compiler throws an error for |
| 3182 | // `-Werror=sign-promo`. |
| 3183 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3184 | } |
| 3185 | } else { |
| 3186 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3187 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3188 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3189 | } |
| 3190 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3191 | |
| 3192 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3193 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3194 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3195 | __ B(false_target); |
| 3196 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3197 | |
| 3198 | if (fallthrough_target.IsLinked()) { |
| 3199 | __ Bind(&fallthrough_target); |
| 3200 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3201 | } |
| 3202 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3203 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3204 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3205 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3206 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3211 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3212 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3213 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3214 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3215 | true_target = nullptr; |
| 3216 | } |
| 3217 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3218 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3219 | false_target = nullptr; |
| 3220 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3221 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3225 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3226 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3227 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3228 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3234 | SlowPathCodeARM64* slow_path = |
| 3235 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3236 | GenerateTestAndBranch(deoptimize, |
| 3237 | /* condition_input_index */ 0, |
| 3238 | slow_path->GetEntryLabel(), |
| 3239 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3242 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3243 | return condition->IsCondition() && |
| 3244 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3245 | } |
| 3246 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3247 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3248 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3249 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3250 | : ARM64Condition(cond); |
| 3251 | } |
| 3252 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3253 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3254 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3255 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3256 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3257 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3258 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3259 | } else { |
| 3260 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3261 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3262 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3263 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3264 | // Ask VIXL whether we should synthesize constants in registers. |
| 3265 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3266 | Operand true_op = is_true_value_constant ? |
| 3267 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3268 | Operand false_op = is_false_value_constant ? |
| 3269 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3270 | bool true_value_in_register = false; |
| 3271 | bool false_value_in_register = false; |
| 3272 | MacroAssembler::GetCselSynthesisInformation( |
| 3273 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3274 | true_value_in_register |= !is_true_value_constant; |
| 3275 | false_value_in_register |= !is_false_value_constant; |
| 3276 | |
| 3277 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3278 | : Location::ConstantLocation(cst_true_value)); |
| 3279 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3280 | : Location::ConstantLocation(cst_false_value)); |
| 3281 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3282 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3283 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3284 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3285 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3286 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3290 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3291 | Condition csel_cond; |
| 3292 | |
| 3293 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3294 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3295 | // Use the condition flags set by the previous instruction. |
| 3296 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3297 | } else { |
| 3298 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3299 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3300 | } |
| 3301 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3302 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3303 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3304 | } else { |
| 3305 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3306 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3309 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3310 | __ Fcsel(OutputFPRegister(select), |
| 3311 | InputFPRegisterAt(select, 1), |
| 3312 | InputFPRegisterAt(select, 0), |
| 3313 | csel_cond); |
| 3314 | } else { |
| 3315 | __ Csel(OutputRegister(select), |
| 3316 | InputOperandAt(select, 1), |
| 3317 | InputOperandAt(select, 0), |
| 3318 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3319 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3322 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3323 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3324 | } |
| 3325 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3326 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3327 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | void CodeGeneratorARM64::GenerateNop() { |
| 3331 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3332 | } |
| 3333 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3334 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3335 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3339 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3343 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3347 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3348 | } |
| 3349 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3350 | // Temp is used for read barrier. |
| 3351 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3352 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3353 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3354 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3355 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3356 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3357 | return 1; |
| 3358 | } |
| 3359 | return 0; |
| 3360 | } |
| 3361 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3362 | // 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] | 3363 | // interface pointer, one for loading the current interface. |
| 3364 | // The other checks have one temp for loading the object's class. |
| 3365 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3366 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3367 | return 3; |
| 3368 | } |
| 3369 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3372 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3373 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3374 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3375 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3376 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3377 | case TypeCheckKind::kExactCheck: |
| 3378 | case TypeCheckKind::kAbstractClassCheck: |
| 3379 | case TypeCheckKind::kClassHierarchyCheck: |
| 3380 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3381 | call_kind = |
| 3382 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3383 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3384 | break; |
| 3385 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3386 | case TypeCheckKind::kUnresolvedCheck: |
| 3387 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3388 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3389 | break; |
| 3390 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3391 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3392 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3393 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3394 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3395 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3396 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3397 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3398 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3399 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3400 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3401 | // Add temps if necessary for read barriers. |
| 3402 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3406 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3407 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3408 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3409 | Register obj = InputRegisterAt(instruction, 0); |
| 3410 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3411 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3412 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3413 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3414 | DCHECK_LE(num_temps, 1u); |
| 3415 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3416 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3417 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3418 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3419 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3420 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3421 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3422 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3423 | |
| 3424 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3425 | // Avoid null check if we know `obj` is not null. |
| 3426 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3427 | __ Cbz(obj, &zero); |
| 3428 | } |
| 3429 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3430 | // /* HeapReference<Class> */ out = obj->klass_ |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3431 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3432 | out_loc, |
| 3433 | obj_loc, |
| 3434 | class_offset, |
| 3435 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3436 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3437 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3438 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3439 | case TypeCheckKind::kExactCheck: { |
| 3440 | __ Cmp(out, cls); |
| 3441 | __ Cset(out, eq); |
| 3442 | if (zero.IsLinked()) { |
| 3443 | __ B(&done); |
| 3444 | } |
| 3445 | break; |
| 3446 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3447 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3448 | case TypeCheckKind::kAbstractClassCheck: { |
| 3449 | // If the class is abstract, we eagerly fetch the super class of the |
| 3450 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3451 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3452 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3453 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3454 | GenerateReferenceLoadOneRegister(instruction, |
| 3455 | out_loc, |
| 3456 | super_offset, |
| 3457 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3458 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3459 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3460 | __ Cbz(out, &done); |
| 3461 | __ Cmp(out, cls); |
| 3462 | __ B(ne, &loop); |
| 3463 | __ Mov(out, 1); |
| 3464 | if (zero.IsLinked()) { |
| 3465 | __ B(&done); |
| 3466 | } |
| 3467 | break; |
| 3468 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3469 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3470 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3471 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3472 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3473 | __ Bind(&loop); |
| 3474 | __ Cmp(out, cls); |
| 3475 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3476 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3477 | GenerateReferenceLoadOneRegister(instruction, |
| 3478 | out_loc, |
| 3479 | super_offset, |
| 3480 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3481 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3482 | __ Cbnz(out, &loop); |
| 3483 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3484 | __ B(&done); |
| 3485 | __ Bind(&success); |
| 3486 | __ Mov(out, 1); |
| 3487 | if (zero.IsLinked()) { |
| 3488 | __ B(&done); |
| 3489 | } |
| 3490 | break; |
| 3491 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3492 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3493 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3494 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3495 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3496 | __ Cmp(out, cls); |
| 3497 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3498 | // 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] | 3499 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3500 | GenerateReferenceLoadOneRegister(instruction, |
| 3501 | out_loc, |
| 3502 | component_offset, |
| 3503 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3504 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3505 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3506 | __ Cbz(out, &done); |
| 3507 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3508 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3509 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3510 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3511 | __ Mov(out, 1); |
| 3512 | __ B(&done); |
| 3513 | break; |
| 3514 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3515 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3516 | case TypeCheckKind::kArrayCheck: { |
| 3517 | __ Cmp(out, cls); |
| 3518 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3519 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3520 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3521 | codegen_->AddSlowPath(slow_path); |
| 3522 | __ B(ne, slow_path->GetEntryLabel()); |
| 3523 | __ Mov(out, 1); |
| 3524 | if (zero.IsLinked()) { |
| 3525 | __ B(&done); |
| 3526 | } |
| 3527 | break; |
| 3528 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3529 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3530 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3531 | case TypeCheckKind::kInterfaceCheck: { |
| 3532 | // Note that we indeed only call on slow path, but we always go |
| 3533 | // into the slow path for the unresolved and interface check |
| 3534 | // cases. |
| 3535 | // |
| 3536 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3537 | // entry point without resorting to a type checking slow path |
| 3538 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3539 | // require to assign fixed registers for the inputs of this |
| 3540 | // HInstanceOf instruction (following the runtime calling |
| 3541 | // convention), which might be cluttered by the potential first |
| 3542 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3543 | // |
| 3544 | // TODO: Introduce a new runtime entry point taking the object |
| 3545 | // to test (instead of its class) as argument, and let it deal |
| 3546 | // with the read barrier issues. This will let us refactor this |
| 3547 | // case of the `switch` code as it was previously (with a direct |
| 3548 | // call to the runtime not using a type checking slow path). |
| 3549 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3550 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3551 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3552 | /* is_fatal */ false); |
| 3553 | codegen_->AddSlowPath(slow_path); |
| 3554 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3555 | if (zero.IsLinked()) { |
| 3556 | __ B(&done); |
| 3557 | } |
| 3558 | break; |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | if (zero.IsLinked()) { |
| 3563 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3564 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | if (done.IsLinked()) { |
| 3568 | __ Bind(&done); |
| 3569 | } |
| 3570 | |
| 3571 | if (slow_path != nullptr) { |
| 3572 | __ Bind(slow_path->GetExitLabel()); |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3577 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3578 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3579 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3580 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3581 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3582 | case TypeCheckKind::kExactCheck: |
| 3583 | case TypeCheckKind::kAbstractClassCheck: |
| 3584 | case TypeCheckKind::kClassHierarchyCheck: |
| 3585 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3586 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3587 | LocationSummary::kCallOnSlowPath : |
| 3588 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3589 | break; |
| 3590 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3591 | case TypeCheckKind::kUnresolvedCheck: |
| 3592 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3593 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3594 | break; |
| 3595 | } |
| 3596 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3597 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3598 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3599 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3600 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 3601 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3605 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3606 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3607 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3608 | Register obj = InputRegisterAt(instruction, 0); |
| 3609 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3610 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3611 | DCHECK_GE(num_temps, 1u); |
| 3612 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3613 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3614 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 3615 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3616 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3617 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3618 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3619 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3620 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3621 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3622 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3623 | const uint32_t object_array_data_offset = |
| 3624 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3625 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3626 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3627 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3628 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3629 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3630 | if (!kEmitCompilerReadBarrier) { |
| 3631 | is_type_check_slow_path_fatal = |
| 3632 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3633 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3634 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3635 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3636 | !instruction->CanThrowIntoCatchBlock(); |
| 3637 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3638 | SlowPathCodeARM64* type_check_slow_path = |
| 3639 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3640 | is_type_check_slow_path_fatal); |
| 3641 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3642 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3643 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3644 | // Avoid null check if we know obj is not null. |
| 3645 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3646 | __ Cbz(obj, &done); |
| 3647 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3648 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3649 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3650 | case TypeCheckKind::kExactCheck: |
| 3651 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3652 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3653 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3654 | temp_loc, |
| 3655 | obj_loc, |
| 3656 | class_offset, |
| 3657 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3658 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3659 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3660 | __ Cmp(temp, cls); |
| 3661 | // Jump to slow path for throwing the exception or doing a |
| 3662 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3663 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3666 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3667 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3668 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3669 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3670 | temp_loc, |
| 3671 | obj_loc, |
| 3672 | class_offset, |
| 3673 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3674 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3675 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3676 | // If the class is abstract, we eagerly fetch the super class of the |
| 3677 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3678 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3679 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3680 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3681 | GenerateReferenceLoadOneRegister(instruction, |
| 3682 | temp_loc, |
| 3683 | super_offset, |
| 3684 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3685 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3686 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3687 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3688 | // exception. |
| 3689 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3690 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3691 | __ Cmp(temp, cls); |
| 3692 | __ B(ne, &loop); |
| 3693 | break; |
| 3694 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3695 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3696 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3697 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3698 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3699 | temp_loc, |
| 3700 | obj_loc, |
| 3701 | class_offset, |
| 3702 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3703 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3704 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3705 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3706 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3707 | __ Bind(&loop); |
| 3708 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3709 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3710 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3711 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3712 | GenerateReferenceLoadOneRegister(instruction, |
| 3713 | temp_loc, |
| 3714 | super_offset, |
| 3715 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3716 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3717 | |
| 3718 | // If the class reference currently in `temp` is not null, jump |
| 3719 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3720 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3721 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3722 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3723 | break; |
| 3724 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3725 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3726 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3727 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3728 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3729 | temp_loc, |
| 3730 | obj_loc, |
| 3731 | class_offset, |
| 3732 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3733 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3734 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3735 | // Do an exact check. |
| 3736 | __ Cmp(temp, cls); |
| 3737 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3738 | |
| 3739 | // 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] | 3740 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3741 | GenerateReferenceLoadOneRegister(instruction, |
| 3742 | temp_loc, |
| 3743 | component_offset, |
| 3744 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3745 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3746 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3747 | // If the component type is null, jump to the slow path to throw the exception. |
| 3748 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3749 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 3750 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3751 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3752 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3753 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3754 | break; |
| 3755 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3756 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3757 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3758 | // 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] | 3759 | // |
| 3760 | // We cannot directly call the CheckCast runtime entry point |
| 3761 | // without resorting to a type checking slow path here (i.e. by |
| 3762 | // calling InvokeRuntime directly), as it would require to |
| 3763 | // assign fixed registers for the inputs of this HInstanceOf |
| 3764 | // instruction (following the runtime calling convention), which |
| 3765 | // might be cluttered by the potential first read barrier |
| 3766 | // emission at the beginning of this method. |
| 3767 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3768 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3769 | case TypeCheckKind::kInterfaceCheck: { |
| 3770 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3771 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3772 | temp_loc, |
| 3773 | obj_loc, |
| 3774 | class_offset, |
| 3775 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3776 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3777 | |
| 3778 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 3779 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3780 | temp_loc, |
| 3781 | temp_loc, |
| 3782 | iftable_offset, |
| 3783 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3784 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3785 | // Null iftable means it is empty and will always fail the check. |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame^] | 3786 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3787 | |
| 3788 | // Loop through the iftable and check if any class matches. |
| 3789 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
| 3790 | |
| 3791 | vixl::aarch64::Label start_loop; |
| 3792 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame^] | 3793 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3794 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 3795 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3796 | // Go to next interface. |
| 3797 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 3798 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame^] | 3799 | // Compare the classes and continue the loop if they do not match. |
| 3800 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 3801 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3802 | break; |
| 3803 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3804 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3805 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3806 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3807 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3810 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3811 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3812 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3813 | } |
| 3814 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3815 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3816 | // Will be generated at use site. |
| 3817 | } |
| 3818 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3819 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3820 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3821 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3822 | } |
| 3823 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3824 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3825 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3828 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3829 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3830 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3831 | // the method_idx. |
| 3832 | HandleInvoke(invoke); |
| 3833 | } |
| 3834 | |
| 3835 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3836 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3837 | } |
| 3838 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3839 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3840 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3841 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3842 | } |
| 3843 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3844 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3845 | HandleInvoke(invoke); |
| 3846 | } |
| 3847 | |
| 3848 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3849 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3850 | LocationSummary* locations = invoke->GetLocations(); |
| 3851 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3852 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3853 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3854 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3855 | |
| 3856 | // The register ip1 is required to be used for the hidden argument in |
| 3857 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3858 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3859 | UseScratchRegisterScope scratch_scope(masm); |
| 3860 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3861 | scratch_scope.Exclude(ip1); |
| 3862 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3863 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3864 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3865 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3866 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3867 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3868 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3869 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3870 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3871 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3872 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3873 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3874 | // emit a read barrier for the previous class reference load. |
| 3875 | // However this is not required in practice, as this is an |
| 3876 | // intermediate/temporary reference and because the current |
| 3877 | // concurrent copying collector keeps the from-space memory |
| 3878 | // intact/accessible until the end of the marking phase (the |
| 3879 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3880 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3881 | __ Ldr(temp, |
| 3882 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3883 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3884 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3885 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3886 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3887 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3888 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3889 | // lr(); |
| 3890 | __ Blr(lr); |
| 3891 | DCHECK(!codegen_->IsLeafMethod()); |
| 3892 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3893 | } |
| 3894 | |
| 3895 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3896 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3897 | if (intrinsic.TryDispatch(invoke)) { |
| 3898 | return; |
| 3899 | } |
| 3900 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3901 | HandleInvoke(invoke); |
| 3902 | } |
| 3903 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3904 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3905 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3906 | // art::PrepareForRegisterAllocation. |
| 3907 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3908 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3909 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3910 | if (intrinsic.TryDispatch(invoke)) { |
| 3911 | return; |
| 3912 | } |
| 3913 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3914 | HandleInvoke(invoke); |
| 3915 | } |
| 3916 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3917 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3918 | if (invoke->GetLocations()->Intrinsified()) { |
| 3919 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3920 | intrinsic.Dispatch(invoke); |
| 3921 | return true; |
| 3922 | } |
| 3923 | return false; |
| 3924 | } |
| 3925 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3926 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3927 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3928 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3929 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3930 | return desired_dispatch_info; |
| 3931 | } |
| 3932 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3933 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3934 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3935 | bool direct_code_loaded = false; |
| 3936 | switch (invoke->GetCodePtrLocation()) { |
| 3937 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3938 | // LR = code address from literal pool with link-time patch. |
| 3939 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3940 | direct_code_loaded = true; |
| 3941 | break; |
| 3942 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3943 | // LR = invoke->GetDirectCodePtr(); |
| 3944 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3945 | direct_code_loaded = true; |
| 3946 | break; |
| 3947 | default: |
| 3948 | break; |
| 3949 | } |
| 3950 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3951 | // 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] | 3952 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3953 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3954 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 3955 | uint32_t offset = |
| 3956 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3957 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3958 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3959 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3960 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3961 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3962 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3963 | break; |
| 3964 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3965 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3966 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3967 | break; |
| 3968 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3969 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3970 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3971 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3972 | break; |
| 3973 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3974 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3975 | const DexFile& dex_file = invoke->GetDexFile(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3976 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3977 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3978 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3979 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3980 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3981 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3982 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3983 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3984 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3985 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3986 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3987 | Register reg = XRegisterFrom(temp); |
| 3988 | Register method_reg; |
| 3989 | if (current_method.IsRegister()) { |
| 3990 | method_reg = XRegisterFrom(current_method); |
| 3991 | } else { |
| 3992 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3993 | DCHECK(!current_method.IsValid()); |
| 3994 | method_reg = reg; |
| 3995 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3996 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3997 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3998 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3999 | __ Ldr(reg.X(), |
| 4000 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4001 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4002 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4003 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4004 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4005 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 4006 | break; |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | switch (invoke->GetCodePtrLocation()) { |
| 4011 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4012 | __ Bl(&frame_entry_label_); |
| 4013 | break; |
| 4014 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4015 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4016 | invoke->GetTargetMethod().dex_method_index); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4017 | vixl::aarch64::Label* label = &relative_call_patches_.back().label; |
| 4018 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4019 | __ Bind(label); |
| 4020 | __ 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] | 4021 | break; |
| 4022 | } |
| 4023 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4024 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4025 | // LR prepared above for better instruction scheduling. |
| 4026 | DCHECK(direct_code_loaded); |
| 4027 | // lr() |
| 4028 | __ Blr(lr); |
| 4029 | break; |
| 4030 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4031 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4032 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4033 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4034 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4035 | // lr() |
| 4036 | __ Blr(lr); |
| 4037 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4038 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4039 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4040 | DCHECK(!IsLeafMethod()); |
| 4041 | } |
| 4042 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4043 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4044 | // Use the calling convention instead of the location of the receiver, as |
| 4045 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4046 | // slow path, the arguments have been moved to the right place, so here we are |
| 4047 | // guaranteed that the receiver is the first register of the calling convention. |
| 4048 | InvokeDexCallingConvention calling_convention; |
| 4049 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4050 | Register temp = XRegisterFrom(temp_in); |
| 4051 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4052 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4053 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4054 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4055 | |
| 4056 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4057 | |
| 4058 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4059 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4060 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4061 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4062 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4063 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4064 | // intermediate/temporary reference and because the current |
| 4065 | // concurrent copying collector keeps the from-space memory |
| 4066 | // intact/accessible until the end of the marking phase (the |
| 4067 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4068 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4069 | // temp = temp->GetMethodAt(method_offset); |
| 4070 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4071 | // lr = temp->GetEntryPoint(); |
| 4072 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 4073 | // lr(); |
| 4074 | __ Blr(lr); |
| 4075 | } |
| 4076 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4077 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4078 | const DexFile& dex_file, |
| 4079 | uint32_t string_index, |
| 4080 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4081 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 4082 | } |
| 4083 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4084 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4085 | const DexFile& dex_file, |
| 4086 | uint32_t type_index, |
| 4087 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4088 | return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_); |
| 4089 | } |
| 4090 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4091 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4092 | const DexFile& dex_file, |
| 4093 | uint32_t element_offset, |
| 4094 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4095 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4096 | } |
| 4097 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4098 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4099 | const DexFile& dex_file, |
| 4100 | uint32_t offset_or_index, |
| 4101 | vixl::aarch64::Label* adrp_label, |
| 4102 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4103 | // Add a patch entry and return the label. |
| 4104 | patches->emplace_back(dex_file, offset_or_index); |
| 4105 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4106 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4107 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4108 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4109 | return label; |
| 4110 | } |
| 4111 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4112 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4113 | const DexFile& dex_file, uint32_t string_index) { |
| 4114 | return boot_image_string_patches_.GetOrCreate( |
| 4115 | StringReference(&dex_file, string_index), |
| 4116 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4117 | } |
| 4118 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4119 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4120 | const DexFile& dex_file, uint32_t type_index) { |
| 4121 | return boot_image_type_patches_.GetOrCreate( |
| 4122 | TypeReference(&dex_file, type_index), |
| 4123 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4124 | } |
| 4125 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4126 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4127 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4128 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 4129 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 4130 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 4131 | } |
| 4132 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4133 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral( |
| 4134 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4135 | return DeduplicateUint64Literal(address); |
| 4136 | } |
| 4137 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4138 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4139 | vixl::aarch64::Register reg) { |
| 4140 | DCHECK(reg.IsX()); |
| 4141 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4142 | __ Bind(fixup_label); |
| 4143 | __ adrp(reg, /* offset placeholder */ 0); |
| 4144 | } |
| 4145 | |
| 4146 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4147 | vixl::aarch64::Register out, |
| 4148 | vixl::aarch64::Register base) { |
| 4149 | DCHECK(out.IsX()); |
| 4150 | DCHECK(base.IsX()); |
| 4151 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4152 | __ Bind(fixup_label); |
| 4153 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4154 | } |
| 4155 | |
| 4156 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4157 | vixl::aarch64::Register out, |
| 4158 | vixl::aarch64::Register base) { |
| 4159 | DCHECK(base.IsX()); |
| 4160 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4161 | __ Bind(fixup_label); |
| 4162 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4163 | } |
| 4164 | |
| 4165 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4166 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4167 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4168 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4169 | for (const PcRelativePatchInfo& info : infos) { |
| 4170 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4171 | &info.target_dex_file, |
| 4172 | info.pc_insn_label->GetLocation(), |
| 4173 | info.offset_or_index)); |
| 4174 | } |
| 4175 | } |
| 4176 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4177 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4178 | DCHECK(linker_patches->empty()); |
| 4179 | size_t size = |
| 4180 | method_patches_.size() + |
| 4181 | call_patches_.size() + |
| 4182 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4183 | pc_relative_dex_cache_patches_.size() + |
| 4184 | boot_image_string_patches_.size() + |
| 4185 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4186 | boot_image_type_patches_.size() + |
| 4187 | pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4188 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4189 | linker_patches->reserve(size); |
| 4190 | for (const auto& entry : method_patches_) { |
| 4191 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4192 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 4193 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4194 | target_method.dex_file, |
| 4195 | target_method.dex_method_index)); |
| 4196 | } |
| 4197 | for (const auto& entry : call_patches_) { |
| 4198 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4199 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 4200 | linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4201 | target_method.dex_file, |
| 4202 | target_method.dex_method_index)); |
| 4203 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4204 | for (const PatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) { |
| 4205 | linker_patches->push_back( |
| 4206 | LinkerPatch::RelativeCodePatch(info.label.GetLocation(), &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4207 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4208 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4209 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4210 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4211 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4212 | info.offset_or_index)); |
| 4213 | } |
| 4214 | for (const auto& entry : boot_image_string_patches_) { |
| 4215 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4216 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4217 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4218 | target_string.dex_file, |
| 4219 | target_string.string_index)); |
| 4220 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4221 | if (!GetCompilerOptions().IsBootImage()) { |
| 4222 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4223 | linker_patches); |
| 4224 | } else { |
| 4225 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4226 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4227 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4228 | for (const auto& entry : boot_image_type_patches_) { |
| 4229 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4230 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4231 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4232 | target_type.dex_file, |
| 4233 | target_type.type_index)); |
| 4234 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4235 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4236 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4237 | for (const auto& entry : boot_image_address_patches_) { |
| 4238 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4239 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4240 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4244 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4245 | Uint32ToLiteralMap* map) { |
| 4246 | return map->GetOrCreate( |
| 4247 | value, |
| 4248 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4249 | } |
| 4250 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4251 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4252 | return uint64_literals_.GetOrCreate( |
| 4253 | value, |
| 4254 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4257 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4258 | MethodReference target_method, |
| 4259 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4260 | return map->GetOrCreate( |
| 4261 | target_method, |
| 4262 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4263 | } |
| 4264 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4265 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4266 | MethodReference target_method) { |
| 4267 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 4268 | } |
| 4269 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4270 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4271 | MethodReference target_method) { |
| 4272 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 4273 | } |
| 4274 | |
| 4275 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4276 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4277 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4278 | // art::PrepareForRegisterAllocation. |
| 4279 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4280 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4281 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4282 | return; |
| 4283 | } |
| 4284 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4285 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4286 | LocationSummary* locations = invoke->GetLocations(); |
| 4287 | codegen_->GenerateStaticOrDirectCall( |
| 4288 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4289 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4293 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4294 | return; |
| 4295 | } |
| 4296 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4297 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4298 | DCHECK(!codegen_->IsLeafMethod()); |
| 4299 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4300 | } |
| 4301 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4302 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4303 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4304 | switch (desired_class_load_kind) { |
| 4305 | case HLoadClass::LoadKind::kReferrersClass: |
| 4306 | break; |
| 4307 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4308 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4309 | break; |
| 4310 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4311 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4312 | break; |
| 4313 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4314 | break; |
| 4315 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 4316 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4317 | break; |
| 4318 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 4319 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4320 | break; |
| 4321 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4322 | break; |
| 4323 | } |
| 4324 | return desired_class_load_kind; |
| 4325 | } |
| 4326 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4327 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4328 | if (cls->NeedsAccessCheck()) { |
| 4329 | InvokeRuntimeCallingConvention calling_convention; |
| 4330 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4331 | cls, |
| 4332 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4333 | LocationFrom(vixl::aarch64::x0), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4334 | /* code_generator_supports_read_barrier */ true); |
| 4335 | return; |
| 4336 | } |
| 4337 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4338 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4339 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4340 | ? LocationSummary::kCallOnSlowPath |
| 4341 | : LocationSummary::kNoCall; |
| 4342 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4343 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4344 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4345 | } |
| 4346 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4347 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4348 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 4349 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4350 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4351 | } |
| 4352 | locations->SetOut(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4356 | if (cls->NeedsAccessCheck()) { |
| 4357 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4358 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4359 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4360 | return; |
| 4361 | } |
| 4362 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4363 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4364 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4365 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4366 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4367 | ? kWithoutReadBarrier |
| 4368 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4369 | bool generate_null_check = false; |
| 4370 | switch (cls->GetLoadKind()) { |
| 4371 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4372 | DCHECK(!cls->CanCallRuntime()); |
| 4373 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4374 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4375 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4376 | GenerateGcRootFieldLoad(cls, |
| 4377 | out_loc, |
| 4378 | current_method, |
| 4379 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4380 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4381 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4382 | break; |
| 4383 | } |
| 4384 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4385 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4386 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4387 | cls->GetTypeIndex())); |
| 4388 | break; |
| 4389 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4390 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4391 | // Add ADRP with its PC-relative type patch. |
| 4392 | const DexFile& dex_file = cls->GetDexFile(); |
| 4393 | uint32_t type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4394 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4395 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4396 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4397 | vixl::aarch64::Label* add_label = |
| 4398 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4399 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4400 | break; |
| 4401 | } |
| 4402 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4403 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4404 | DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress())); |
| 4405 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress())); |
| 4406 | break; |
| 4407 | } |
| 4408 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 4409 | DCHECK_NE(cls->GetAddress(), 0u); |
| 4410 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4411 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4412 | // multiple types, simply split the dex cache address to a 16KiB aligned base |
| 4413 | // loaded from a literal and the remaining offset embedded in the load. |
| 4414 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 4415 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 4416 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4417 | uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4418 | uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4419 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4420 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4421 | GenerateGcRootFieldLoad(cls, |
| 4422 | out_loc, |
| 4423 | out.X(), |
| 4424 | offset, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4425 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4426 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4427 | generate_null_check = !cls->IsInDexCache(); |
| 4428 | break; |
| 4429 | } |
| 4430 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 4431 | // Add ADRP with its PC-relative DexCache access patch. |
| 4432 | const DexFile& dex_file = cls->GetDexFile(); |
| 4433 | uint32_t element_offset = cls->GetDexCacheElementOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4434 | vixl::aarch64::Label* adrp_label = |
| 4435 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4436 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4437 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4438 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4439 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4440 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4441 | GenerateGcRootFieldLoad(cls, |
| 4442 | out_loc, |
| 4443 | out.X(), |
| 4444 | /* offset placeholder */ 0, |
| 4445 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4446 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4447 | generate_null_check = !cls->IsInDexCache(); |
| 4448 | break; |
| 4449 | } |
| 4450 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 4451 | MemberOffset resolved_types_offset = |
| 4452 | ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 4453 | // /* GcRoot<mirror::Class>[] */ out = |
| 4454 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 4455 | Register current_method = InputRegisterAt(cls, 0); |
| 4456 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 4457 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4458 | GenerateGcRootFieldLoad(cls, |
| 4459 | out_loc, |
| 4460 | out.X(), |
| 4461 | CodeGenerator::GetCacheOffset(cls->GetTypeIndex()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4462 | /* fixup_label */ nullptr, |
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 | } |
| 4468 | |
| 4469 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 4470 | DCHECK(cls->CanCallRuntime()); |
| 4471 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 4472 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4473 | codegen_->AddSlowPath(slow_path); |
| 4474 | if (generate_null_check) { |
| 4475 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4476 | } |
| 4477 | if (cls->MustGenerateClinitCheck()) { |
| 4478 | GenerateClassInitializationCheck(slow_path, out); |
| 4479 | } else { |
| 4480 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | } |
| 4484 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4485 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4486 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4487 | } |
| 4488 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4489 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4490 | LocationSummary* locations = |
| 4491 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4492 | locations->SetOut(Location::RequiresRegister()); |
| 4493 | } |
| 4494 | |
| 4495 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4496 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4497 | } |
| 4498 | |
| 4499 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4500 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4501 | } |
| 4502 | |
| 4503 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4504 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4507 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4508 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4509 | switch (desired_string_load_kind) { |
| 4510 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4511 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4512 | break; |
| 4513 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4514 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4515 | break; |
| 4516 | case HLoadString::LoadKind::kBootImageAddress: |
| 4517 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4518 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4519 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4520 | break; |
| 4521 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4522 | break; |
| 4523 | } |
| 4524 | return desired_string_load_kind; |
| 4525 | } |
| 4526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4527 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 4528 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
| 4529 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 4530 | ? LocationSummary::kCallOnMainOnly |
| 4531 | : LocationSummary::kCallOnSlowPath) |
| 4532 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4533 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4534 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4535 | InvokeRuntimeCallingConvention calling_convention; |
| 4536 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4537 | } else { |
| 4538 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4539 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4540 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4541 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 4542 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4543 | InvokeRuntimeCallingConvention calling_convention; |
| 4544 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4545 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4546 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4547 | Primitive::kPrimNot).GetCode()); |
| 4548 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4549 | } else { |
| 4550 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4551 | } |
| 4552 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4553 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4557 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4558 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4559 | switch (load->GetLoadKind()) { |
| 4560 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4561 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4562 | load->GetStringIndex())); |
| 4563 | return; // No dex cache slow path. |
| 4564 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4565 | // Add ADRP with its PC-relative String patch. |
| 4566 | const DexFile& dex_file = load->GetDexFile(); |
| 4567 | uint32_t string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4568 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4569 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4570 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4571 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4572 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4573 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4574 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4575 | return; // No dex cache slow path. |
| 4576 | } |
| 4577 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4578 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4579 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4580 | return; // No dex cache slow path. |
| 4581 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4582 | case HLoadString::LoadKind::kBssEntry: { |
| 4583 | // Add ADRP with its PC-relative String .bss entry patch. |
| 4584 | const DexFile& dex_file = load->GetDexFile(); |
| 4585 | uint32_t string_index = load->GetStringIndex(); |
| 4586 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4587 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4588 | Register temp = temps.AcquireX(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4589 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4590 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4591 | // Add LDR with its PC-relative String patch. |
| 4592 | vixl::aarch64::Label* ldr_label = |
| 4593 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 4594 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4595 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 4596 | load->GetLocations()->Out(), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4597 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4598 | /* offset placeholder */ 0u, |
| 4599 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4600 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4601 | SlowPathCodeARM64* slow_path = |
| 4602 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4603 | codegen_->AddSlowPath(slow_path); |
| 4604 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 4605 | __ Bind(slow_path->GetExitLabel()); |
| 4606 | return; |
| 4607 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4608 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4609 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4610 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4611 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4612 | // 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] | 4613 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4614 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4615 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex()); |
| 4616 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 4617 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4620 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4621 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4622 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4623 | } |
| 4624 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4625 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4626 | // Will be generated at use site. |
| 4627 | } |
| 4628 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4629 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4630 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4631 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4632 | InvokeRuntimeCallingConvention calling_convention; |
| 4633 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4634 | } |
| 4635 | |
| 4636 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4637 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject: kQuickUnlockObject, |
| 4638 | instruction, |
| 4639 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4640 | if (instruction->IsEnter()) { |
| 4641 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4642 | } else { |
| 4643 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4644 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4647 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4648 | LocationSummary* locations = |
| 4649 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4650 | switch (mul->GetResultType()) { |
| 4651 | case Primitive::kPrimInt: |
| 4652 | case Primitive::kPrimLong: |
| 4653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4654 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4655 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4656 | break; |
| 4657 | |
| 4658 | case Primitive::kPrimFloat: |
| 4659 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4660 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4661 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4662 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4663 | break; |
| 4664 | |
| 4665 | default: |
| 4666 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4671 | switch (mul->GetResultType()) { |
| 4672 | case Primitive::kPrimInt: |
| 4673 | case Primitive::kPrimLong: |
| 4674 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4675 | break; |
| 4676 | |
| 4677 | case Primitive::kPrimFloat: |
| 4678 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4679 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
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 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4687 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4688 | LocationSummary* locations = |
| 4689 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4690 | switch (neg->GetResultType()) { |
| 4691 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4692 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4693 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4694 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4695 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4696 | |
| 4697 | case Primitive::kPrimFloat: |
| 4698 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4699 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4700 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4701 | break; |
| 4702 | |
| 4703 | default: |
| 4704 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4709 | switch (neg->GetResultType()) { |
| 4710 | case Primitive::kPrimInt: |
| 4711 | case Primitive::kPrimLong: |
| 4712 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4713 | break; |
| 4714 | |
| 4715 | case Primitive::kPrimFloat: |
| 4716 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4717 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
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 LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4726 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4727 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4728 | InvokeRuntimeCallingConvention calling_convention; |
| 4729 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4730 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4731 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4732 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4736 | LocationSummary* locations = instruction->GetLocations(); |
| 4737 | InvokeRuntimeCallingConvention calling_convention; |
| 4738 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4739 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4740 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4741 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4742 | // of poisoning the reference. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4743 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4744 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4747 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4748 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4749 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4750 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4751 | if (instruction->IsStringAlloc()) { |
| 4752 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4753 | } else { |
| 4754 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4755 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4756 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4757 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4758 | } |
| 4759 | |
| 4760 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4761 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4762 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4763 | if (instruction->IsStringAlloc()) { |
| 4764 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4765 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4766 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4767 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4768 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4769 | __ Blr(lr); |
| 4770 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4771 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4772 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4773 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4774 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4778 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4779 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4780 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4784 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4785 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4786 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4787 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4788 | break; |
| 4789 | |
| 4790 | default: |
| 4791 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4792 | } |
| 4793 | } |
| 4794 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4795 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4796 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4797 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4798 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4799 | } |
| 4800 | |
| 4801 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4802 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4803 | } |
| 4804 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4805 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4806 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4807 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4808 | } |
| 4809 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4810 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4811 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4812 | return; |
| 4813 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4814 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4815 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4816 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4817 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4818 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4821 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4822 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4823 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4824 | |
| 4825 | LocationSummary* locations = instruction->GetLocations(); |
| 4826 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4827 | |
| 4828 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4829 | } |
| 4830 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4831 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4832 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4835 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4836 | HandleBinaryOp(instruction); |
| 4837 | } |
| 4838 | |
| 4839 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4840 | HandleBinaryOp(instruction); |
| 4841 | } |
| 4842 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4843 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4844 | LOG(FATAL) << "Unreachable"; |
| 4845 | } |
| 4846 | |
| 4847 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4848 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4849 | } |
| 4850 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4851 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4852 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4853 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4854 | if (location.IsStackSlot()) { |
| 4855 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4856 | } else if (location.IsDoubleStackSlot()) { |
| 4857 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4858 | } |
| 4859 | locations->SetOut(location); |
| 4860 | } |
| 4861 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4862 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4863 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4864 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4868 | LocationSummary* locations = |
| 4869 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4870 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4874 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4875 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4879 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4880 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4881 | locations->SetInAt(i, Location::Any()); |
| 4882 | } |
| 4883 | locations->SetOut(Location::Any()); |
| 4884 | } |
| 4885 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4886 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4887 | LOG(FATAL) << "Unreachable"; |
| 4888 | } |
| 4889 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4890 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4891 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4892 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4893 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 4894 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4895 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4896 | |
| 4897 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4898 | case Primitive::kPrimInt: |
| 4899 | case Primitive::kPrimLong: |
| 4900 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4901 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4902 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4903 | break; |
| 4904 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4905 | case Primitive::kPrimFloat: |
| 4906 | case Primitive::kPrimDouble: { |
| 4907 | InvokeRuntimeCallingConvention calling_convention; |
| 4908 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4909 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4910 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4911 | |
| 4912 | break; |
| 4913 | } |
| 4914 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4915 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4916 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4917 | } |
| 4918 | } |
| 4919 | |
| 4920 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4921 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4922 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4923 | switch (type) { |
| 4924 | case Primitive::kPrimInt: |
| 4925 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4926 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4927 | break; |
| 4928 | } |
| 4929 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4930 | case Primitive::kPrimFloat: |
| 4931 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4932 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 4933 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4934 | if (type == Primitive::kPrimFloat) { |
| 4935 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4936 | } else { |
| 4937 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4938 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4939 | break; |
| 4940 | } |
| 4941 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4942 | default: |
| 4943 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4944 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4945 | } |
| 4946 | } |
| 4947 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4948 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4949 | memory_barrier->SetLocations(nullptr); |
| 4950 | } |
| 4951 | |
| 4952 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4953 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4954 | } |
| 4955 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4956 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4957 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4958 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4959 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4960 | } |
| 4961 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4962 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4963 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4967 | instruction->SetLocations(nullptr); |
| 4968 | } |
| 4969 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4970 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4971 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4974 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4975 | HandleBinaryOp(ror); |
| 4976 | } |
| 4977 | |
| 4978 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4979 | HandleBinaryOp(ror); |
| 4980 | } |
| 4981 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4982 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4983 | HandleShift(shl); |
| 4984 | } |
| 4985 | |
| 4986 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4987 | HandleShift(shl); |
| 4988 | } |
| 4989 | |
| 4990 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4991 | HandleShift(shr); |
| 4992 | } |
| 4993 | |
| 4994 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4995 | HandleShift(shr); |
| 4996 | } |
| 4997 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4998 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4999 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5003 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5004 | } |
| 5005 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5006 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5007 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5011 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5015 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5018 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5019 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5022 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5023 | HUnresolvedInstanceFieldGet* instruction) { |
| 5024 | FieldAccessCallingConventionARM64 calling_convention; |
| 5025 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5026 | instruction, instruction->GetFieldType(), calling_convention); |
| 5027 | } |
| 5028 | |
| 5029 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5030 | HUnresolvedInstanceFieldGet* instruction) { |
| 5031 | FieldAccessCallingConventionARM64 calling_convention; |
| 5032 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5033 | instruction->GetFieldType(), |
| 5034 | instruction->GetFieldIndex(), |
| 5035 | instruction->GetDexPc(), |
| 5036 | calling_convention); |
| 5037 | } |
| 5038 | |
| 5039 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5040 | HUnresolvedInstanceFieldSet* instruction) { |
| 5041 | FieldAccessCallingConventionARM64 calling_convention; |
| 5042 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5043 | instruction, instruction->GetFieldType(), calling_convention); |
| 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5047 | HUnresolvedInstanceFieldSet* 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::VisitUnresolvedStaticFieldGet( |
| 5057 | HUnresolvedStaticFieldGet* instruction) { |
| 5058 | FieldAccessCallingConventionARM64 calling_convention; |
| 5059 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5060 | instruction, instruction->GetFieldType(), calling_convention); |
| 5061 | } |
| 5062 | |
| 5063 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5064 | HUnresolvedStaticFieldGet* 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::VisitUnresolvedStaticFieldSet( |
| 5074 | HUnresolvedStaticFieldSet* instruction) { |
| 5075 | FieldAccessCallingConventionARM64 calling_convention; |
| 5076 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5077 | instruction, instruction->GetFieldType(), calling_convention); |
| 5078 | } |
| 5079 | |
| 5080 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5081 | HUnresolvedStaticFieldSet* instruction) { |
| 5082 | FieldAccessCallingConventionARM64 calling_convention; |
| 5083 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5084 | instruction->GetFieldType(), |
| 5085 | instruction->GetFieldIndex(), |
| 5086 | instruction->GetDexPc(), |
| 5087 | calling_convention); |
| 5088 | } |
| 5089 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5090 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5091 | LocationSummary* locations = |
| 5092 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5093 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5097 | HBasicBlock* block = instruction->GetBlock(); |
| 5098 | if (block->GetLoopInformation() != nullptr) { |
| 5099 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5100 | // The back edge will generate the suspend check. |
| 5101 | return; |
| 5102 | } |
| 5103 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5104 | // The goto will generate the suspend check. |
| 5105 | return; |
| 5106 | } |
| 5107 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5108 | } |
| 5109 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5110 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5111 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5112 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5113 | InvokeRuntimeCallingConvention calling_convention; |
| 5114 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5115 | } |
| 5116 | |
| 5117 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5118 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5119 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5123 | LocationSummary* locations = |
| 5124 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5125 | Primitive::Type input_type = conversion->GetInputType(); |
| 5126 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5127 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5128 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5129 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5130 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5131 | } |
| 5132 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5133 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5134 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5135 | } else { |
| 5136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5137 | } |
| 5138 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5139 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5140 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5141 | } else { |
| 5142 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5143 | } |
| 5144 | } |
| 5145 | |
| 5146 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5147 | Primitive::Type result_type = conversion->GetResultType(); |
| 5148 | Primitive::Type input_type = conversion->GetInputType(); |
| 5149 | |
| 5150 | DCHECK_NE(input_type, result_type); |
| 5151 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5152 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5153 | int result_size = Primitive::ComponentSize(result_type); |
| 5154 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5155 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5156 | Register output = OutputRegister(conversion); |
| 5157 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5158 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5159 | // 'int' values are used directly as W registers, discarding the top |
| 5160 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5161 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5162 | // top 32 bits of the target register. We theoretically could leave those |
| 5163 | // bits unchanged, but we would have to make sure that no code uses a |
| 5164 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5165 | // zero. |
| 5166 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5167 | } else if (result_type == Primitive::kPrimChar || |
| 5168 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5169 | __ Ubfx(output, |
| 5170 | output.IsX() ? source.X() : source.W(), |
| 5171 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5172 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5173 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5174 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5175 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5176 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5177 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5178 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5179 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5180 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5181 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5182 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5183 | } else { |
| 5184 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5185 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5186 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5187 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5188 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5189 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5190 | HandleShift(ushr); |
| 5191 | } |
| 5192 | |
| 5193 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5194 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5198 | HandleBinaryOp(instruction); |
| 5199 | } |
| 5200 | |
| 5201 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5202 | HandleBinaryOp(instruction); |
| 5203 | } |
| 5204 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5205 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5206 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5207 | LOG(FATAL) << "Unreachable"; |
| 5208 | } |
| 5209 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5210 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5211 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5212 | LOG(FATAL) << "Unreachable"; |
| 5213 | } |
| 5214 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5215 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5216 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5217 | LocationSummary* locations = |
| 5218 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5220 | } |
| 5221 | |
| 5222 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5223 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5224 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5225 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5226 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5227 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5228 | // 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] | 5229 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5230 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5231 | // make sure we don't emit it if the target may run out of range. |
| 5232 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5233 | // ranges and emit the tables only as required. |
| 5234 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5235 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5236 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5237 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5238 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5239 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5240 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5241 | Register temp = temps.AcquireW(); |
| 5242 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5243 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5244 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5245 | // Jump to successors[0] if value == lower_bound. |
| 5246 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5247 | int32_t last_index = 0; |
| 5248 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5249 | __ Subs(temp, temp, Operand(2)); |
| 5250 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5251 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5252 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5253 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5254 | } |
| 5255 | if (num_entries - last_index == 2) { |
| 5256 | // The last missing case_value. |
| 5257 | __ Cmp(temp, Operand(1)); |
| 5258 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | // And the default for any other value. |
| 5262 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5263 | __ B(codegen_->GetLabelOf(default_block)); |
| 5264 | } |
| 5265 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5266 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5267 | |
| 5268 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5269 | |
| 5270 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5271 | // registers, we are free to block one. |
| 5272 | Register temp_w = temps.AcquireW(); |
| 5273 | Register index; |
| 5274 | // Remove the bias. |
| 5275 | if (lower_bound != 0) { |
| 5276 | index = temp_w; |
| 5277 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5278 | } else { |
| 5279 | index = value_reg; |
| 5280 | } |
| 5281 | |
| 5282 | // Jump to default block if index is out of the range. |
| 5283 | __ Cmp(index, Operand(num_entries)); |
| 5284 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5285 | |
| 5286 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5287 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5288 | // register pressure. |
| 5289 | Register table_base = temps.AcquireX(); |
| 5290 | // Load jump offset from the table. |
| 5291 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5292 | Register jump_offset = temp_w; |
| 5293 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5294 | |
| 5295 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5296 | Register target_address = table_base; |
| 5297 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5298 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5299 | } |
| 5300 | } |
| 5301 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5302 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5303 | HInstruction* instruction, |
| 5304 | Location out, |
| 5305 | uint32_t offset, |
| 5306 | Location maybe_temp, |
| 5307 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5308 | Primitive::Type type = Primitive::kPrimNot; |
| 5309 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5310 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5311 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5312 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5313 | if (kUseBakerReadBarrier) { |
| 5314 | // Load with fast path based Baker's read barrier. |
| 5315 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5316 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5317 | out, |
| 5318 | out_reg, |
| 5319 | offset, |
| 5320 | temp_reg, |
| 5321 | /* needs_null_check */ false, |
| 5322 | /* use_load_acquire */ false); |
| 5323 | } else { |
| 5324 | // Load with slow path based read barrier. |
| 5325 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5326 | // in the following move operation, as we will need it for the |
| 5327 | // read barrier below. |
| 5328 | __ Mov(temp_reg, out_reg); |
| 5329 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5330 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5331 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5332 | } |
| 5333 | } else { |
| 5334 | // Plain load with no read barrier. |
| 5335 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5336 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5337 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5338 | } |
| 5339 | } |
| 5340 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5341 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5342 | HInstruction* instruction, |
| 5343 | Location out, |
| 5344 | Location obj, |
| 5345 | uint32_t offset, |
| 5346 | Location maybe_temp, |
| 5347 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5348 | Primitive::Type type = Primitive::kPrimNot; |
| 5349 | Register out_reg = RegisterFrom(out, type); |
| 5350 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5351 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5352 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5353 | if (kUseBakerReadBarrier) { |
| 5354 | // Load with fast path based Baker's read barrier. |
| 5355 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5356 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5357 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5358 | out, |
| 5359 | obj_reg, |
| 5360 | offset, |
| 5361 | temp_reg, |
| 5362 | /* needs_null_check */ false, |
| 5363 | /* use_load_acquire */ false); |
| 5364 | } else { |
| 5365 | // Load with slow path based read barrier. |
| 5366 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5367 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5368 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5369 | } |
| 5370 | } else { |
| 5371 | // Plain load with no read barrier. |
| 5372 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5373 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5374 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5375 | } |
| 5376 | } |
| 5377 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5378 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5379 | HInstruction* instruction, |
| 5380 | Location root, |
| 5381 | Register obj, |
| 5382 | uint32_t offset, |
| 5383 | vixl::aarch64::Label* fixup_label, |
| 5384 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5385 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5386 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5387 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5388 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5389 | if (kUseBakerReadBarrier) { |
| 5390 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5391 | // Baker's read barrier are used: |
| 5392 | // |
| 5393 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5394 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5395 | // if (temp != null) { |
| 5396 | // root = temp(root) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5397 | // } |
| 5398 | |
| 5399 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5400 | if (fixup_label == nullptr) { |
| 5401 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5402 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5403 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5404 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5405 | static_assert( |
| 5406 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5407 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5408 | "have different sizes."); |
| 5409 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5410 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5411 | "have different sizes."); |
| 5412 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5413 | Register temp = lr; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5414 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 5415 | // Slow path marking the GC root `root`. The entrypoint will alrady be loaded in temp. |
| 5416 | SlowPathCodeARM64* slow_path = |
| 5417 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, |
| 5418 | root, |
| 5419 | LocationFrom(temp)); |
| 5420 | codegen_->AddSlowPath(slow_path); |
| 5421 | const int32_t entry_point_offset = |
| 5422 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 5423 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5424 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5425 | // threads are suspended or running a checkpoint. |
| 5426 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
| 5427 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 5428 | // checking GetIsGcMarking. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5429 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5430 | __ Bind(slow_path->GetExitLabel()); |
| 5431 | } else { |
| 5432 | // GC root loaded through a slow path for read barriers other |
| 5433 | // than Baker's. |
| 5434 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5435 | if (fixup_label == nullptr) { |
| 5436 | __ Add(root_reg.X(), obj.X(), offset); |
| 5437 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5438 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5439 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5440 | // /* mirror::Object* */ root = root->Read() |
| 5441 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5442 | } |
| 5443 | } else { |
| 5444 | // Plain GC root load with no read barrier. |
| 5445 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5446 | if (fixup_label == nullptr) { |
| 5447 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5448 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5449 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5450 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5451 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5452 | // do not have to unpoison `root_reg` here. |
| 5453 | } |
| 5454 | } |
| 5455 | |
| 5456 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5457 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5458 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5459 | uint32_t offset, |
| 5460 | Register temp, |
| 5461 | bool needs_null_check, |
| 5462 | bool use_load_acquire) { |
| 5463 | DCHECK(kEmitCompilerReadBarrier); |
| 5464 | DCHECK(kUseBakerReadBarrier); |
| 5465 | |
| 5466 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5467 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5468 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5469 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5470 | ref, |
| 5471 | obj, |
| 5472 | offset, |
| 5473 | no_index, |
| 5474 | no_scale_factor, |
| 5475 | temp, |
| 5476 | needs_null_check, |
| 5477 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5481 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5482 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5483 | uint32_t data_offset, |
| 5484 | Location index, |
| 5485 | Register temp, |
| 5486 | bool needs_null_check) { |
| 5487 | DCHECK(kEmitCompilerReadBarrier); |
| 5488 | DCHECK(kUseBakerReadBarrier); |
| 5489 | |
| 5490 | // Array cells are never volatile variables, therefore array loads |
| 5491 | // never use Load-Acquire instructions on ARM64. |
| 5492 | const bool use_load_acquire = false; |
| 5493 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5494 | static_assert( |
| 5495 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5496 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5497 | // /* HeapReference<Object> */ ref = |
| 5498 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5499 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5500 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5501 | ref, |
| 5502 | obj, |
| 5503 | data_offset, |
| 5504 | index, |
| 5505 | scale_factor, |
| 5506 | temp, |
| 5507 | needs_null_check, |
| 5508 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5512 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5513 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5514 | uint32_t offset, |
| 5515 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5516 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5517 | Register temp, |
| 5518 | bool needs_null_check, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5519 | bool use_load_acquire, |
| 5520 | bool always_update_field) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5521 | DCHECK(kEmitCompilerReadBarrier); |
| 5522 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5523 | // If we are emitting an array load, we should not be using a |
| 5524 | // Load Acquire instruction. In other words: |
| 5525 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5526 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5527 | |
| 5528 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5529 | UseScratchRegisterScope temps(masm); |
| 5530 | |
| 5531 | // In slow path based read barriers, the read barrier call is |
| 5532 | // inserted after the original load. However, in fast path based |
| 5533 | // Baker's read barriers, we need to perform the load of |
| 5534 | // mirror::Object::monitor_ *before* the original reference load. |
| 5535 | // This load-load ordering is required by the read barrier. |
| 5536 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5537 | // |
| 5538 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5539 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5540 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 5541 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5542 | // if (is_gray) { |
| 5543 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5544 | // } |
| 5545 | // |
| 5546 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5547 | // slightly more complex as it performs additional checks that we do |
| 5548 | // not do here for performance reasons. |
| 5549 | |
| 5550 | Primitive::Type type = Primitive::kPrimNot; |
| 5551 | Register ref_reg = RegisterFrom(ref, type); |
| 5552 | DCHECK(obj.IsW()); |
| 5553 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5554 | |
| 5555 | // /* int32_t */ monitor = obj->monitor_ |
| 5556 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5557 | if (needs_null_check) { |
| 5558 | MaybeRecordImplicitNullCheck(instruction); |
| 5559 | } |
| 5560 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5561 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5562 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5563 | |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5564 | // Introduce a dependency on the lock_word including rb_state, |
| 5565 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5566 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5567 | // `obj` is unchanged by this operation, but its value now depends |
| 5568 | // on `temp`. |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5569 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5570 | |
| 5571 | // The actual reference load. |
| 5572 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5573 | // Load types involving an "index": ArrayGet, |
| 5574 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5575 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5576 | if (use_load_acquire) { |
| 5577 | // UnsafeGetObjectVolatile intrinsic case. |
| 5578 | // Register `index` is not an index in an object array, but an |
| 5579 | // offset to an object reference field within object `obj`. |
| 5580 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5581 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5582 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5583 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5584 | DCHECK_EQ(offset, 0u); |
| 5585 | DCHECK_EQ(scale_factor, 0u); |
| 5586 | DCHECK_EQ(needs_null_check, 0u); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5587 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5588 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5589 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5590 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5591 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5592 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5593 | if (index.IsConstant()) { |
| 5594 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5595 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5596 | } else { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5597 | Register temp3 = temps.AcquireW(); |
| 5598 | __ Add(temp3, obj, offset); |
| 5599 | Load(type, ref_reg, HeapOperand(temp3, XRegisterFrom(index), LSL, scale_factor)); |
| 5600 | temps.Release(temp3); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5601 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5602 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5603 | } else { |
| 5604 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5605 | MemOperand field = HeapOperand(obj, offset); |
| 5606 | if (use_load_acquire) { |
| 5607 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5608 | } else { |
| 5609 | Load(type, ref_reg, field); |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5614 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5615 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5616 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5617 | SlowPathCodeARM64* slow_path; |
| 5618 | if (always_update_field) { |
| 5619 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 only supports |
| 5620 | // address of the form `obj + field_offset`, where `obj` is a |
| 5621 | // register and `field_offset` is a register. Thus `offset` and |
| 5622 | // `scale_factor` above are expected to be null in this code path. |
| 5623 | DCHECK_EQ(offset, 0u); |
| 5624 | DCHECK_EQ(scale_factor, 0u); /* "times 1" */ |
| 5625 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM64( |
| 5626 | instruction, ref, obj, /* field_offset */ index, temp); |
| 5627 | } else { |
| 5628 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
| 5629 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5630 | AddSlowPath(slow_path); |
| 5631 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 5632 | // if (rb_state == ReadBarrier::GrayState()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5633 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5634 | // 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] | 5635 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5636 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5637 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5638 | __ Bind(slow_path->GetExitLabel()); |
| 5639 | } |
| 5640 | |
| 5641 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5642 | Location out, |
| 5643 | Location ref, |
| 5644 | Location obj, |
| 5645 | uint32_t offset, |
| 5646 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5647 | DCHECK(kEmitCompilerReadBarrier); |
| 5648 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5649 | // Insert a slow path based read barrier *after* the reference load. |
| 5650 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5651 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5652 | // reference will be carried out by the runtime within the slow |
| 5653 | // path. |
| 5654 | // |
| 5655 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5656 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5657 | // not used by the artReadBarrierSlow entry point. |
| 5658 | // |
| 5659 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5660 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5661 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5662 | AddSlowPath(slow_path); |
| 5663 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5664 | __ B(slow_path->GetEntryLabel()); |
| 5665 | __ Bind(slow_path->GetExitLabel()); |
| 5666 | } |
| 5667 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5668 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5669 | Location out, |
| 5670 | Location ref, |
| 5671 | Location obj, |
| 5672 | uint32_t offset, |
| 5673 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5674 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5675 | // Baker's read barriers shall be handled by the fast path |
| 5676 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5677 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5678 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5679 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5680 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5681 | } else if (kPoisonHeapReferences) { |
| 5682 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5683 | } |
| 5684 | } |
| 5685 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5686 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5687 | Location out, |
| 5688 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5689 | DCHECK(kEmitCompilerReadBarrier); |
| 5690 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5691 | // Insert a slow path based read barrier *after* the GC root load. |
| 5692 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5693 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5694 | // not need to do anything special for this here. |
| 5695 | SlowPathCodeARM64* slow_path = |
| 5696 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5697 | AddSlowPath(slow_path); |
| 5698 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5699 | __ B(slow_path->GetEntryLabel()); |
| 5700 | __ Bind(slow_path->GetExitLabel()); |
| 5701 | } |
| 5702 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5703 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5704 | LocationSummary* locations = |
| 5705 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5707 | locations->SetOut(Location::RequiresRegister()); |
| 5708 | } |
| 5709 | |
| 5710 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5711 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5712 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5713 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5714 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5715 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5716 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5717 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5718 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5719 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5720 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5721 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5722 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5723 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5724 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 5727 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5728 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5729 | #undef __ |
| 5730 | #undef QUICK_ENTRY_POINT |
| 5731 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5732 | } // namespace arm64 |
| 5733 | } // namespace art |