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 | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 332 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 333 | public: |
| 334 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : SlowPathCodeARM64(instruction) {} |
| 335 | |
| 336 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 337 | LocationSummary* locations = instruction_->GetLocations(); |
| 338 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 339 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 340 | |
| 341 | __ Bind(GetEntryLabel()); |
| 342 | SaveLiveRegisters(codegen, locations); |
| 343 | |
| 344 | InvokeRuntimeCallingConvention calling_convention; |
| 345 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 346 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
| 347 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 348 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 349 | Primitive::Type type = instruction_->GetType(); |
| 350 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 351 | |
| 352 | RestoreLiveRegisters(codegen, locations); |
| 353 | |
| 354 | // Store the resolved String to the BSS entry. |
| 355 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 356 | Register temp = temps.AcquireX(); |
| 357 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
| 358 | // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary |
| 359 | // for the ADRP in the fast path, so that we can avoid the ADRP here. |
| 360 | vixl::aarch64::Label* adrp_label = |
| 361 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 362 | arm64_codegen->EmitAdrpPlaceholder(adrp_label, temp); |
| 363 | vixl::aarch64::Label* strp_label = |
| 364 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 365 | { |
| 366 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 367 | __ Bind(strp_label); |
| 368 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
| 369 | MemOperand(temp, /* offset placeholder */ 0)); |
| 370 | } |
| 371 | |
| 372 | __ B(GetExitLabel()); |
| 373 | } |
| 374 | |
| 375 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 376 | |
| 377 | private: |
| 378 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 379 | }; |
| 380 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 381 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 382 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 383 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 384 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 385 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 386 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 387 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 388 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 389 | // Live registers will be restored in the catch block if caught. |
| 390 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 391 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 392 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 393 | instruction_, |
| 394 | instruction_->GetDexPc(), |
| 395 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 396 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 399 | bool IsFatal() const OVERRIDE { return true; } |
| 400 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 401 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 402 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 403 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 404 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 405 | }; |
| 406 | |
| 407 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 408 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 409 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 410 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 411 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 412 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 413 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 414 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 415 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 416 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 417 | if (successor_ == nullptr) { |
| 418 | __ B(GetReturnLabel()); |
| 419 | } else { |
| 420 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 421 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 424 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 425 | DCHECK(successor_ == nullptr); |
| 426 | return &return_label_; |
| 427 | } |
| 428 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 429 | HBasicBlock* GetSuccessor() const { |
| 430 | return successor_; |
| 431 | } |
| 432 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 433 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 434 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 435 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 436 | // If not null, the block to branch to after the suspend check. |
| 437 | HBasicBlock* const successor_; |
| 438 | |
| 439 | // 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] | 440 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 441 | |
| 442 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 443 | }; |
| 444 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 445 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 446 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 447 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 448 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 449 | |
| 450 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 451 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 452 | Location class_to_check = locations->InAt(1); |
| 453 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 454 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 455 | DCHECK(instruction_->IsCheckCast() |
| 456 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 457 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 458 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 459 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 460 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 461 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 462 | if (!is_fatal_) { |
| 463 | SaveLiveRegisters(codegen, locations); |
| 464 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 465 | |
| 466 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 467 | // move resolver. |
| 468 | InvokeRuntimeCallingConvention calling_convention; |
| 469 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 470 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 471 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | |
| 473 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 474 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 475 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 476 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 477 | Primitive::Type ret_type = instruction_->GetType(); |
| 478 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 479 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 480 | } else { |
| 481 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 482 | arm64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 483 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 486 | if (!is_fatal_) { |
| 487 | RestoreLiveRegisters(codegen, locations); |
| 488 | __ B(GetExitLabel()); |
| 489 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 492 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 493 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 494 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 495 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 496 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 497 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 498 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 499 | }; |
| 500 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 501 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 502 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 503 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 504 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 505 | |
| 506 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 507 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 508 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 509 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 510 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 513 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 514 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 515 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 516 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 517 | }; |
| 518 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 519 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 520 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 521 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 522 | |
| 523 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 524 | LocationSummary* locations = instruction_->GetLocations(); |
| 525 | __ Bind(GetEntryLabel()); |
| 526 | SaveLiveRegisters(codegen, locations); |
| 527 | |
| 528 | InvokeRuntimeCallingConvention calling_convention; |
| 529 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 530 | parallel_move.AddMove( |
| 531 | locations->InAt(0), |
| 532 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 533 | Primitive::kPrimNot, |
| 534 | nullptr); |
| 535 | parallel_move.AddMove( |
| 536 | locations->InAt(1), |
| 537 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 538 | Primitive::kPrimInt, |
| 539 | nullptr); |
| 540 | parallel_move.AddMove( |
| 541 | locations->InAt(2), |
| 542 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 543 | Primitive::kPrimNot, |
| 544 | nullptr); |
| 545 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 546 | |
| 547 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 548 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 549 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 550 | RestoreLiveRegisters(codegen, locations); |
| 551 | __ B(GetExitLabel()); |
| 552 | } |
| 553 | |
| 554 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 555 | |
| 556 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 557 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 558 | }; |
| 559 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 560 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 561 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 562 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 563 | |
| 564 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 565 | // underlying code buffer and we have generated the jump table with right size. |
| 566 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 567 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 568 | |
| 569 | __ Bind(&table_start_); |
| 570 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 571 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 572 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 573 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 574 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 575 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 576 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 577 | Literal<int32_t> literal(jump_offset); |
| 578 | __ place(&literal); |
| 579 | } |
| 580 | } |
| 581 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 582 | // Slow path marking an object during a read barrier. |
| 583 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 584 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 585 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location obj) |
| 586 | : SlowPathCodeARM64(instruction), obj_(obj) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 587 | DCHECK(kEmitCompilerReadBarrier); |
| 588 | } |
| 589 | |
| 590 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 591 | |
| 592 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 593 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 594 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 595 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(obj_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 596 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 597 | instruction_->IsStaticFieldGet() || |
| 598 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 599 | instruction_->IsArraySet() || |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 600 | instruction_->IsLoadClass() || |
| 601 | instruction_->IsLoadString() || |
| 602 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 603 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 604 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 605 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 606 | << "Unexpected instruction in read barrier marking slow path: " |
| 607 | << instruction_->DebugName(); |
| 608 | |
| 609 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 610 | // No need to save live registers; it's taken care of by the |
| 611 | // entrypoint. Also, there is no need to update the stack mask, |
| 612 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 613 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 614 | DCHECK_NE(obj_.reg(), LR); |
| 615 | DCHECK_NE(obj_.reg(), WSP); |
| 616 | DCHECK_NE(obj_.reg(), WZR); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 617 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 618 | // as a temporary, it cannot be the entry point's input/output. |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 619 | DCHECK_NE(obj_.reg(), IP0); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 620 | DCHECK(0 <= obj_.reg() && obj_.reg() < kNumberOfWRegisters) << obj_.reg(); |
| 621 | // "Compact" slow path, saving two moves. |
| 622 | // |
| 623 | // Instead of using the standard runtime calling convention (input |
| 624 | // and output in W0): |
| 625 | // |
| 626 | // W0 <- obj |
| 627 | // W0 <- ReadBarrierMark(W0) |
| 628 | // obj <- W0 |
| 629 | // |
| 630 | // we just use rX (the register holding `obj`) as input and output |
| 631 | // of a dedicated entrypoint: |
| 632 | // |
| 633 | // rX <- ReadBarrierMarkRegX(rX) |
| 634 | // |
| 635 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 636 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(obj_.reg()); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 637 | // This runtime call does not require a stack map. |
| 638 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 639 | __ B(GetExitLabel()); |
| 640 | } |
| 641 | |
| 642 | private: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 643 | const Location obj_; |
| 644 | |
| 645 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 646 | }; |
| 647 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 648 | // Slow path generating a read barrier for a heap reference. |
| 649 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 650 | public: |
| 651 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 652 | Location out, |
| 653 | Location ref, |
| 654 | Location obj, |
| 655 | uint32_t offset, |
| 656 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 657 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 658 | out_(out), |
| 659 | ref_(ref), |
| 660 | obj_(obj), |
| 661 | offset_(offset), |
| 662 | index_(index) { |
| 663 | DCHECK(kEmitCompilerReadBarrier); |
| 664 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 665 | // has been overwritten by (or after) the heap object reference load |
| 666 | // to be instrumented, e.g.: |
| 667 | // |
| 668 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 669 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 670 | // |
| 671 | // In that case, we have lost the information about the original |
| 672 | // object, and the emitted read barrier cannot work properly. |
| 673 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 674 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 675 | } |
| 676 | |
| 677 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 678 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 679 | LocationSummary* locations = instruction_->GetLocations(); |
| 680 | Primitive::Type type = Primitive::kPrimNot; |
| 681 | DCHECK(locations->CanCall()); |
| 682 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 683 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 684 | instruction_->IsStaticFieldGet() || |
| 685 | instruction_->IsArrayGet() || |
| 686 | instruction_->IsInstanceOf() || |
| 687 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 688 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 689 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 690 | << instruction_->DebugName(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 691 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 692 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 693 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 694 | |
| 695 | __ Bind(GetEntryLabel()); |
| 696 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 697 | SaveLiveRegisters(codegen, locations); |
| 698 | |
| 699 | // We may have to change the index's value, but as `index_` is a |
| 700 | // constant member (like other "inputs" of this slow path), |
| 701 | // introduce a copy of it, `index`. |
| 702 | Location index = index_; |
| 703 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 704 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 705 | if (instruction_->IsArrayGet()) { |
| 706 | // Compute the actual memory offset and store it in `index`. |
| 707 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 708 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 709 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 710 | // We are about to change the value of `index_reg` (see the |
| 711 | // calls to vixl::MacroAssembler::Lsl and |
| 712 | // vixl::MacroAssembler::Mov below), but it has |
| 713 | // not been saved by the previous call to |
| 714 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 715 | // callee-save register -- |
| 716 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 717 | // callee-save registers, as it has been designed with the |
| 718 | // assumption that callee-save registers are supposed to be |
| 719 | // handled by the called function. So, as a callee-save |
| 720 | // register, `index_reg` _would_ eventually be saved onto |
| 721 | // the stack, but it would be too late: we would have |
| 722 | // changed its value earlier. Therefore, we manually save |
| 723 | // it here into another freely available register, |
| 724 | // `free_reg`, chosen of course among the caller-save |
| 725 | // registers (as a callee-save `free_reg` register would |
| 726 | // exhibit the same problem). |
| 727 | // |
| 728 | // Note we could have requested a temporary register from |
| 729 | // the register allocator instead; but we prefer not to, as |
| 730 | // this is a slow path, and we know we can find a |
| 731 | // caller-save register that is available. |
| 732 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 733 | __ Mov(free_reg.W(), index_reg); |
| 734 | index_reg = free_reg; |
| 735 | index = LocationFrom(index_reg); |
| 736 | } else { |
| 737 | // The initial register stored in `index_` has already been |
| 738 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 739 | // (as it is not a callee-save register), so we can freely |
| 740 | // use it. |
| 741 | } |
| 742 | // Shifting the index value contained in `index_reg` by the scale |
| 743 | // factor (2) cannot overflow in practice, as the runtime is |
| 744 | // unable to allocate object arrays with a size larger than |
| 745 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 746 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 747 | static_assert( |
| 748 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 749 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 750 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 751 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 752 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 753 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 754 | // (as in the case of ArrayGet), as it is actually an offset |
| 755 | // to an object field within an object. |
| 756 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 757 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 758 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 759 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 760 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 761 | DCHECK_EQ(offset_, 0U); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 762 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
| 766 | // We're moving two or three locations to locations that could |
| 767 | // overlap, so we need a parallel move resolver. |
| 768 | InvokeRuntimeCallingConvention calling_convention; |
| 769 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 770 | parallel_move.AddMove(ref_, |
| 771 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 772 | type, |
| 773 | nullptr); |
| 774 | parallel_move.AddMove(obj_, |
| 775 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 776 | type, |
| 777 | nullptr); |
| 778 | if (index.IsValid()) { |
| 779 | parallel_move.AddMove(index, |
| 780 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 781 | Primitive::kPrimInt, |
| 782 | nullptr); |
| 783 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 784 | } else { |
| 785 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 786 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 787 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 788 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 789 | instruction_, |
| 790 | instruction_->GetDexPc(), |
| 791 | this); |
| 792 | CheckEntrypointTypes< |
| 793 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 794 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 795 | |
| 796 | RestoreLiveRegisters(codegen, locations); |
| 797 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 798 | __ B(GetExitLabel()); |
| 799 | } |
| 800 | |
| 801 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 802 | |
| 803 | private: |
| 804 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 805 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 806 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 807 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 808 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 809 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 810 | } |
| 811 | } |
| 812 | // We shall never fail to find a free caller-save register, as |
| 813 | // there are more than two core caller-save registers on ARM64 |
| 814 | // (meaning it is possible to find one which is different from |
| 815 | // `ref` and `obj`). |
| 816 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 817 | LOG(FATAL) << "Could not find a free register"; |
| 818 | UNREACHABLE(); |
| 819 | } |
| 820 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 821 | const Location out_; |
| 822 | const Location ref_; |
| 823 | const Location obj_; |
| 824 | const uint32_t offset_; |
| 825 | // An additional location containing an index to an array. |
| 826 | // Only used for HArrayGet and the UnsafeGetObject & |
| 827 | // UnsafeGetObjectVolatile intrinsics. |
| 828 | const Location index_; |
| 829 | |
| 830 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 831 | }; |
| 832 | |
| 833 | // Slow path generating a read barrier for a GC root. |
| 834 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 835 | public: |
| 836 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 837 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 838 | DCHECK(kEmitCompilerReadBarrier); |
| 839 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 840 | |
| 841 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 842 | LocationSummary* locations = instruction_->GetLocations(); |
| 843 | Primitive::Type type = Primitive::kPrimNot; |
| 844 | DCHECK(locations->CanCall()); |
| 845 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 846 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 847 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 848 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 849 | |
| 850 | __ Bind(GetEntryLabel()); |
| 851 | SaveLiveRegisters(codegen, locations); |
| 852 | |
| 853 | InvokeRuntimeCallingConvention calling_convention; |
| 854 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 855 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 856 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 857 | // thus we need a 64-bit move here, and we cannot use |
| 858 | // |
| 859 | // arm64_codegen->MoveLocation( |
| 860 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 861 | // root_, |
| 862 | // type); |
| 863 | // |
| 864 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 865 | // reference type (`Primitive::kPrimNot`). |
| 866 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 867 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 868 | instruction_, |
| 869 | instruction_->GetDexPc(), |
| 870 | this); |
| 871 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 872 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 873 | |
| 874 | RestoreLiveRegisters(codegen, locations); |
| 875 | __ B(GetExitLabel()); |
| 876 | } |
| 877 | |
| 878 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 879 | |
| 880 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 881 | const Location out_; |
| 882 | const Location root_; |
| 883 | |
| 884 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 885 | }; |
| 886 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 887 | #undef __ |
| 888 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 889 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 890 | Location next_location; |
| 891 | if (type == Primitive::kPrimVoid) { |
| 892 | LOG(FATAL) << "Unreachable type " << type; |
| 893 | } |
| 894 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 895 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 896 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 897 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 898 | } else if (!Primitive::IsFloatingPointType(type) && |
| 899 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 900 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 901 | } else { |
| 902 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 903 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 904 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 907 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 908 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 909 | return next_location; |
| 910 | } |
| 911 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 912 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 913 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 916 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 917 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 918 | const CompilerOptions& compiler_options, |
| 919 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 920 | : CodeGenerator(graph, |
| 921 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 922 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 923 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 924 | callee_saved_core_registers.GetList(), |
| 925 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 926 | compiler_options, |
| 927 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 928 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 929 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 930 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 931 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 932 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 933 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 934 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 935 | uint32_literals_(std::less<uint32_t>(), |
| 936 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 937 | uint64_literals_(std::less<uint64_t>(), |
| 938 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 939 | method_patches_(MethodReferenceComparator(), |
| 940 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 941 | call_patches_(MethodReferenceComparator(), |
| 942 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 943 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 944 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 945 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 946 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 947 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 948 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 949 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 950 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 951 | boot_image_address_patches_(std::less<uint32_t>(), |
| 952 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 953 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 954 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 955 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 956 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 957 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 958 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 959 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 960 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 961 | jump_table->EmitTable(this); |
| 962 | } |
| 963 | } |
| 964 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 965 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 966 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 967 | // Ensure we emit the literal pool. |
| 968 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 969 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 970 | CodeGenerator::Finalize(allocator); |
| 971 | } |
| 972 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 973 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 974 | // Note: There are 6 kinds of moves: |
| 975 | // 1. constant -> GPR/FPR (non-cycle) |
| 976 | // 2. constant -> stack (non-cycle) |
| 977 | // 3. GPR/FPR -> GPR/FPR |
| 978 | // 4. GPR/FPR -> stack |
| 979 | // 5. stack -> GPR/FPR |
| 980 | // 6. stack -> stack (non-cycle) |
| 981 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 982 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 983 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 984 | // dependency. |
| 985 | vixl_temps_.Open(GetVIXLAssembler()); |
| 986 | } |
| 987 | |
| 988 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 989 | vixl_temps_.Close(); |
| 990 | } |
| 991 | |
| 992 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 993 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 994 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 995 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 996 | Location scratch = GetScratchLocation(kind); |
| 997 | if (!scratch.Equals(Location::NoLocation())) { |
| 998 | return scratch; |
| 999 | } |
| 1000 | // Allocate from VIXL temp registers. |
| 1001 | if (kind == Location::kRegister) { |
| 1002 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1003 | } else { |
| 1004 | DCHECK(kind == Location::kFpuRegister); |
| 1005 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1006 | } |
| 1007 | AddScratchLocation(scratch); |
| 1008 | return scratch; |
| 1009 | } |
| 1010 | |
| 1011 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1012 | if (loc.IsRegister()) { |
| 1013 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1014 | } else { |
| 1015 | DCHECK(loc.IsFpuRegister()); |
| 1016 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1017 | } |
| 1018 | RemoveScratchLocation(loc); |
| 1019 | } |
| 1020 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1021 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1022 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1023 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1026 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1027 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1028 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1029 | __ Bind(&frame_entry_label_); |
| 1030 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1031 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1032 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1033 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1034 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1035 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1036 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1037 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1038 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1039 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1040 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1041 | if (!HasEmptyFrame()) { |
| 1042 | int frame_size = GetFrameSize(); |
| 1043 | // Stack layout: |
| 1044 | // sp[frame_size - 8] : lr. |
| 1045 | // ... : other preserved core registers. |
| 1046 | // ... : other preserved fp registers. |
| 1047 | // ... : reserved frame space. |
| 1048 | // sp[0] : current method. |
| 1049 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1050 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1051 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1052 | frame_size - GetCoreSpillSize()); |
| 1053 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1054 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1055 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1059 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1060 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1061 | if (!HasEmptyFrame()) { |
| 1062 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1063 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1064 | frame_size - FrameEntrySpillSize()); |
| 1065 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1066 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1067 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1068 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1069 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1070 | __ Ret(); |
| 1071 | GetAssembler()->cfi().RestoreState(); |
| 1072 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1075 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1076 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1077 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1078 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1081 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1082 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1083 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1084 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1085 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1086 | } |
| 1087 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1088 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1089 | __ Bind(GetLabelOf(block)); |
| 1090 | } |
| 1091 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1092 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1093 | DCHECK(location.IsRegister()); |
| 1094 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1095 | } |
| 1096 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1097 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1098 | if (location.IsRegister()) { |
| 1099 | locations->AddTemp(location); |
| 1100 | } else { |
| 1101 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1102 | } |
| 1103 | } |
| 1104 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1105 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1106 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1107 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1108 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1109 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1110 | if (value_can_be_null) { |
| 1111 | __ Cbz(value, &done); |
| 1112 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1113 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1114 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1115 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1116 | if (value_can_be_null) { |
| 1117 | __ Bind(&done); |
| 1118 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1119 | } |
| 1120 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1121 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1122 | // Blocked core registers: |
| 1123 | // lr : Runtime reserved. |
| 1124 | // tr : Runtime reserved. |
| 1125 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1126 | // ip1 : VIXL core temp. |
| 1127 | // ip0 : VIXL core temp. |
| 1128 | // |
| 1129 | // Blocked fp registers: |
| 1130 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1131 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1132 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1133 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1134 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1135 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1136 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1137 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1138 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1139 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1140 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1141 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1142 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1143 | // Stubs do not save callee-save floating point registers. If the graph |
| 1144 | // is debuggable, we need to deal with these registers differently. For |
| 1145 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1146 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1147 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1148 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1149 | } |
| 1150 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1153 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1154 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1155 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1156 | return kArm64WordSize; |
| 1157 | } |
| 1158 | |
| 1159 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1160 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1161 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1162 | return kArm64WordSize; |
| 1163 | } |
| 1164 | |
| 1165 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1166 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1167 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1168 | return kArm64WordSize; |
| 1169 | } |
| 1170 | |
| 1171 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1172 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1173 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1174 | return kArm64WordSize; |
| 1175 | } |
| 1176 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1177 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1178 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1182 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1183 | } |
| 1184 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1185 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1186 | if (constant->IsIntConstant()) { |
| 1187 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1188 | } else if (constant->IsLongConstant()) { |
| 1189 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1190 | } else if (constant->IsNullConstant()) { |
| 1191 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1192 | } else if (constant->IsFloatConstant()) { |
| 1193 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1194 | } else { |
| 1195 | DCHECK(constant->IsDoubleConstant()); |
| 1196 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1197 | } |
| 1198 | } |
| 1199 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1200 | |
| 1201 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1202 | DCHECK(constant.IsConstant()); |
| 1203 | HConstant* cst = constant.GetConstant(); |
| 1204 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1205 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1206 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1207 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1208 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1209 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1210 | } |
| 1211 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1212 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1213 | Location source, |
| 1214 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1215 | if (source.Equals(destination)) { |
| 1216 | return; |
| 1217 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1218 | |
| 1219 | // A valid move can always be inferred from the destination and source |
| 1220 | // locations. When moving from and to a register, the argument type can be |
| 1221 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1222 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1223 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1224 | |
| 1225 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1226 | if (unspecified_type) { |
| 1227 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1228 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1229 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1230 | || src_cst->IsFloatConstant() |
| 1231 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1232 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1233 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1234 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1235 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1236 | // type is appropriate. Else the source is a register, and since the |
| 1237 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1238 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1239 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1240 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1241 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1242 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1243 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1244 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1245 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1246 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1247 | __ Ldr(dst, StackOperandFrom(source)); |
| 1248 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1249 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1250 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1251 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1252 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1253 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1254 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1255 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1256 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1257 | ? Primitive::kPrimLong |
| 1258 | : Primitive::kPrimInt; |
| 1259 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1260 | } |
| 1261 | } else { |
| 1262 | DCHECK(source.IsFpuRegister()); |
| 1263 | if (destination.IsRegister()) { |
| 1264 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1265 | ? Primitive::kPrimDouble |
| 1266 | : Primitive::kPrimFloat; |
| 1267 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1268 | } else { |
| 1269 | DCHECK(destination.IsFpuRegister()); |
| 1270 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1271 | } |
| 1272 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1273 | } else { // The destination is not a register. It must be a stack slot. |
| 1274 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1275 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1276 | if (unspecified_type) { |
| 1277 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1278 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1279 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1280 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1281 | } |
| 1282 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1283 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1284 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1285 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1286 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1287 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1288 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1289 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1290 | HConstant* src_cst = source.GetConstant(); |
| 1291 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1292 | if (src_cst->IsZeroBitPattern()) { |
| 1293 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1294 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1295 | if (src_cst->IsIntConstant()) { |
| 1296 | temp = temps.AcquireW(); |
| 1297 | } else if (src_cst->IsLongConstant()) { |
| 1298 | temp = temps.AcquireX(); |
| 1299 | } else if (src_cst->IsFloatConstant()) { |
| 1300 | temp = temps.AcquireS(); |
| 1301 | } else { |
| 1302 | DCHECK(src_cst->IsDoubleConstant()); |
| 1303 | temp = temps.AcquireD(); |
| 1304 | } |
| 1305 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1306 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1307 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1308 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1309 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1310 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1311 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1312 | // There is generally less pressure on FP registers. |
| 1313 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1314 | __ Ldr(temp, StackOperandFrom(source)); |
| 1315 | __ Str(temp, StackOperandFrom(destination)); |
| 1316 | } |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1321 | CPURegister dst, |
| 1322 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1323 | switch (type) { |
| 1324 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1325 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1326 | break; |
| 1327 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1328 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1329 | break; |
| 1330 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1331 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1332 | break; |
| 1333 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1334 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1335 | break; |
| 1336 | case Primitive::kPrimInt: |
| 1337 | case Primitive::kPrimNot: |
| 1338 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1339 | case Primitive::kPrimFloat: |
| 1340 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1341 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1342 | __ Ldr(dst, src); |
| 1343 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1344 | case Primitive::kPrimVoid: |
| 1345 | LOG(FATAL) << "Unreachable type " << type; |
| 1346 | } |
| 1347 | } |
| 1348 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1349 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1350 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1351 | const MemOperand& src, |
| 1352 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1353 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1354 | BlockPoolsScope block_pools(masm); |
| 1355 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1356 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1357 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1358 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1359 | DCHECK(!src.IsPreIndex()); |
| 1360 | DCHECK(!src.IsPostIndex()); |
| 1361 | |
| 1362 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1363 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1364 | MemOperand base = MemOperand(temp_base); |
| 1365 | switch (type) { |
| 1366 | case Primitive::kPrimBoolean: |
| 1367 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1368 | if (needs_null_check) { |
| 1369 | MaybeRecordImplicitNullCheck(instruction); |
| 1370 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1371 | break; |
| 1372 | case Primitive::kPrimByte: |
| 1373 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1374 | if (needs_null_check) { |
| 1375 | MaybeRecordImplicitNullCheck(instruction); |
| 1376 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1377 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1378 | break; |
| 1379 | case Primitive::kPrimChar: |
| 1380 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1381 | if (needs_null_check) { |
| 1382 | MaybeRecordImplicitNullCheck(instruction); |
| 1383 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1384 | break; |
| 1385 | case Primitive::kPrimShort: |
| 1386 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1387 | if (needs_null_check) { |
| 1388 | MaybeRecordImplicitNullCheck(instruction); |
| 1389 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1390 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1391 | break; |
| 1392 | case Primitive::kPrimInt: |
| 1393 | case Primitive::kPrimNot: |
| 1394 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1395 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1396 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1397 | if (needs_null_check) { |
| 1398 | MaybeRecordImplicitNullCheck(instruction); |
| 1399 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1400 | break; |
| 1401 | case Primitive::kPrimFloat: |
| 1402 | case Primitive::kPrimDouble: { |
| 1403 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1404 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1405 | |
| 1406 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1407 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1408 | if (needs_null_check) { |
| 1409 | MaybeRecordImplicitNullCheck(instruction); |
| 1410 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1411 | __ Fmov(FPRegister(dst), temp); |
| 1412 | break; |
| 1413 | } |
| 1414 | case Primitive::kPrimVoid: |
| 1415 | LOG(FATAL) << "Unreachable type " << type; |
| 1416 | } |
| 1417 | } |
| 1418 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1419 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1420 | CPURegister src, |
| 1421 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1422 | switch (type) { |
| 1423 | case Primitive::kPrimBoolean: |
| 1424 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1425 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1426 | break; |
| 1427 | case Primitive::kPrimChar: |
| 1428 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1429 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1430 | break; |
| 1431 | case Primitive::kPrimInt: |
| 1432 | case Primitive::kPrimNot: |
| 1433 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1434 | case Primitive::kPrimFloat: |
| 1435 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1436 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1437 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1438 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1439 | case Primitive::kPrimVoid: |
| 1440 | LOG(FATAL) << "Unreachable type " << type; |
| 1441 | } |
| 1442 | } |
| 1443 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1444 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1445 | CPURegister src, |
| 1446 | const MemOperand& dst) { |
| 1447 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1448 | Register temp_base = temps.AcquireX(); |
| 1449 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1450 | DCHECK(!dst.IsPreIndex()); |
| 1451 | DCHECK(!dst.IsPostIndex()); |
| 1452 | |
| 1453 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1454 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1455 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1456 | MemOperand base = MemOperand(temp_base); |
| 1457 | switch (type) { |
| 1458 | case Primitive::kPrimBoolean: |
| 1459 | case Primitive::kPrimByte: |
| 1460 | __ Stlrb(Register(src), base); |
| 1461 | break; |
| 1462 | case Primitive::kPrimChar: |
| 1463 | case Primitive::kPrimShort: |
| 1464 | __ Stlrh(Register(src), base); |
| 1465 | break; |
| 1466 | case Primitive::kPrimInt: |
| 1467 | case Primitive::kPrimNot: |
| 1468 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1469 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1470 | __ Stlr(Register(src), base); |
| 1471 | break; |
| 1472 | case Primitive::kPrimFloat: |
| 1473 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1474 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1475 | Register temp_src; |
| 1476 | if (src.IsZero()) { |
| 1477 | // The zero register is used to avoid synthesizing zero constants. |
| 1478 | temp_src = Register(src); |
| 1479 | } else { |
| 1480 | DCHECK(src.IsFPRegister()); |
| 1481 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1482 | __ Fmov(temp_src, FPRegister(src)); |
| 1483 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1484 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1485 | __ Stlr(temp_src, base); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1486 | break; |
| 1487 | } |
| 1488 | case Primitive::kPrimVoid: |
| 1489 | LOG(FATAL) << "Unreachable type " << type; |
| 1490 | } |
| 1491 | } |
| 1492 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1493 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1494 | HInstruction* instruction, |
| 1495 | uint32_t dex_pc, |
| 1496 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1497 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1498 | GenerateInvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1499 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1500 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1501 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1504 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1505 | HInstruction* instruction, |
| 1506 | SlowPathCode* slow_path) { |
| 1507 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1508 | GenerateInvokeRuntime(entry_point_offset); |
| 1509 | } |
| 1510 | |
| 1511 | void CodeGeneratorARM64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1512 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 1513 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1514 | __ Blr(lr); |
| 1515 | } |
| 1516 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1517 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1518 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1519 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1520 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1521 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1522 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1523 | // 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] | 1524 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1525 | __ Add(temp, class_reg, status_offset); |
| 1526 | __ Ldar(temp, HeapOperand(temp)); |
| 1527 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1528 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1529 | __ Bind(slow_path->GetExitLabel()); |
| 1530 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1531 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1532 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1533 | BarrierType type = BarrierAll; |
| 1534 | |
| 1535 | switch (kind) { |
| 1536 | case MemBarrierKind::kAnyAny: |
| 1537 | case MemBarrierKind::kAnyStore: { |
| 1538 | type = BarrierAll; |
| 1539 | break; |
| 1540 | } |
| 1541 | case MemBarrierKind::kLoadAny: { |
| 1542 | type = BarrierReads; |
| 1543 | break; |
| 1544 | } |
| 1545 | case MemBarrierKind::kStoreStore: { |
| 1546 | type = BarrierWrites; |
| 1547 | break; |
| 1548 | } |
| 1549 | default: |
| 1550 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1551 | } |
| 1552 | __ Dmb(InnerShareable, type); |
| 1553 | } |
| 1554 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1555 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1556 | HBasicBlock* successor) { |
| 1557 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1558 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1559 | if (slow_path == nullptr) { |
| 1560 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1561 | instruction->SetSlowPath(slow_path); |
| 1562 | codegen_->AddSlowPath(slow_path); |
| 1563 | if (successor != nullptr) { |
| 1564 | DCHECK(successor->IsLoopHeader()); |
| 1565 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1566 | } |
| 1567 | } else { |
| 1568 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1569 | } |
| 1570 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1571 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1572 | Register temp = temps.AcquireW(); |
| 1573 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1574 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1575 | if (successor == nullptr) { |
| 1576 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1577 | __ Bind(slow_path->GetReturnLabel()); |
| 1578 | } else { |
| 1579 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1580 | __ B(slow_path->GetEntryLabel()); |
| 1581 | // slow_path will return to GetLabelOf(successor). |
| 1582 | } |
| 1583 | } |
| 1584 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1585 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1586 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1587 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1588 | assembler_(codegen->GetAssembler()), |
| 1589 | codegen_(codegen) {} |
| 1590 | |
| 1591 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1592 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1593 | |
| 1594 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1595 | |
| 1596 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1597 | // Using a base helps identify when we hit such breakpoints. |
| 1598 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1599 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1600 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1601 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1602 | }; |
| 1603 | |
| 1604 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1605 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1606 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1607 | } \ |
| 1608 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1609 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1610 | locations->SetOut(Location::Any()); \ |
| 1611 | } |
| 1612 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1613 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1614 | |
| 1615 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1616 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1617 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1618 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1619 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1620 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1621 | Primitive::Type type = instr->GetResultType(); |
| 1622 | switch (type) { |
| 1623 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1624 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1625 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1626 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1627 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1628 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1629 | |
| 1630 | case Primitive::kPrimFloat: |
| 1631 | case Primitive::kPrimDouble: |
| 1632 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1633 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1634 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1635 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1636 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1637 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1638 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1642 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1643 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1644 | |
| 1645 | bool object_field_get_with_read_barrier = |
| 1646 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1647 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1648 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1649 | object_field_get_with_read_barrier ? |
| 1650 | LocationSummary::kCallOnSlowPath : |
| 1651 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1652 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1653 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1654 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1655 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1656 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1657 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1658 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1659 | // The output overlaps for an object field get when read barriers |
| 1660 | // are enabled: we do not want the load to overwrite the object's |
| 1661 | // location, as we need it to emit the read barrier. |
| 1662 | locations->SetOut( |
| 1663 | Location::RequiresRegister(), |
| 1664 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1669 | const FieldInfo& field_info) { |
| 1670 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1671 | LocationSummary* locations = instruction->GetLocations(); |
| 1672 | Location base_loc = locations->InAt(0); |
| 1673 | Location out = locations->Out(); |
| 1674 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1675 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1676 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1677 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1678 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1679 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1680 | // Object FieldGet with Baker's read barrier case. |
| 1681 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1682 | UseScratchRegisterScope temps(masm); |
| 1683 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1684 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1685 | Register temp = temps.AcquireW(); |
| 1686 | // Note that potential implicit null checks are handled in this |
| 1687 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1688 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1689 | instruction, |
| 1690 | out, |
| 1691 | base, |
| 1692 | offset, |
| 1693 | temp, |
| 1694 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1695 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1696 | } else { |
| 1697 | // General case. |
| 1698 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1699 | // Note that a potential implicit null check is handled in this |
| 1700 | // CodeGeneratorARM64::LoadAcquire call. |
| 1701 | // NB: LoadAcquire will record the pc info if needed. |
| 1702 | codegen_->LoadAcquire( |
| 1703 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1704 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1705 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1706 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1707 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1708 | if (field_type == Primitive::kPrimNot) { |
| 1709 | // If read barriers are enabled, emit read barriers other than |
| 1710 | // Baker's using a slow path (and also unpoison the loaded |
| 1711 | // reference, if heap poisoning is enabled). |
| 1712 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1713 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1714 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1718 | LocationSummary* locations = |
| 1719 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1720 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1721 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 1722 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 1723 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1724 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1725 | } else { |
| 1726 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1731 | const FieldInfo& field_info, |
| 1732 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1733 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1734 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1735 | |
| 1736 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1737 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1738 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1739 | Offset offset = field_info.GetFieldOffset(); |
| 1740 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1741 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1742 | { |
| 1743 | // We use a block to end the scratch scope before the write barrier, thus |
| 1744 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1745 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1746 | |
| 1747 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1748 | DCHECK(value.IsW()); |
| 1749 | Register temp = temps.AcquireW(); |
| 1750 | __ Mov(temp, value.W()); |
| 1751 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1752 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1753 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1754 | |
| 1755 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1756 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1757 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1758 | } else { |
| 1759 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1760 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1761 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1765 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1769 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1770 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1771 | |
| 1772 | switch (type) { |
| 1773 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1774 | case Primitive::kPrimLong: { |
| 1775 | Register dst = OutputRegister(instr); |
| 1776 | Register lhs = InputRegisterAt(instr, 0); |
| 1777 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1778 | if (instr->IsAdd()) { |
| 1779 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1780 | } else if (instr->IsAnd()) { |
| 1781 | __ And(dst, lhs, rhs); |
| 1782 | } else if (instr->IsOr()) { |
| 1783 | __ Orr(dst, lhs, rhs); |
| 1784 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1785 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1786 | } else if (instr->IsRor()) { |
| 1787 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1788 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1789 | __ Ror(dst, lhs, shift); |
| 1790 | } else { |
| 1791 | // Ensure shift distance is in the same size register as the result. If |
| 1792 | // we are rotating a long and the shift comes in a w register originally, |
| 1793 | // we don't need to sxtw for use as an x since the shift distances are |
| 1794 | // all & reg_bits - 1. |
| 1795 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1796 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1797 | } else { |
| 1798 | DCHECK(instr->IsXor()); |
| 1799 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1800 | } |
| 1801 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1802 | } |
| 1803 | case Primitive::kPrimFloat: |
| 1804 | case Primitive::kPrimDouble: { |
| 1805 | FPRegister dst = OutputFPRegister(instr); |
| 1806 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1807 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1808 | if (instr->IsAdd()) { |
| 1809 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1810 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1811 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1812 | } else { |
| 1813 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1814 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1815 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1816 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1817 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1818 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1819 | } |
| 1820 | } |
| 1821 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1822 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1823 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1824 | |
| 1825 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1826 | Primitive::Type type = instr->GetResultType(); |
| 1827 | switch (type) { |
| 1828 | case Primitive::kPrimInt: |
| 1829 | case Primitive::kPrimLong: { |
| 1830 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1831 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1832 | locations->SetOut(Location::RequiresRegister()); |
| 1833 | break; |
| 1834 | } |
| 1835 | default: |
| 1836 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1841 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1842 | |
| 1843 | Primitive::Type type = instr->GetType(); |
| 1844 | switch (type) { |
| 1845 | case Primitive::kPrimInt: |
| 1846 | case Primitive::kPrimLong: { |
| 1847 | Register dst = OutputRegister(instr); |
| 1848 | Register lhs = InputRegisterAt(instr, 0); |
| 1849 | Operand rhs = InputOperandAt(instr, 1); |
| 1850 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1851 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1852 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1853 | if (instr->IsShl()) { |
| 1854 | __ Lsl(dst, lhs, shift_value); |
| 1855 | } else if (instr->IsShr()) { |
| 1856 | __ Asr(dst, lhs, shift_value); |
| 1857 | } else { |
| 1858 | __ Lsr(dst, lhs, shift_value); |
| 1859 | } |
| 1860 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1861 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1862 | |
| 1863 | if (instr->IsShl()) { |
| 1864 | __ Lsl(dst, lhs, rhs_reg); |
| 1865 | } else if (instr->IsShr()) { |
| 1866 | __ Asr(dst, lhs, rhs_reg); |
| 1867 | } else { |
| 1868 | __ Lsr(dst, lhs, rhs_reg); |
| 1869 | } |
| 1870 | } |
| 1871 | break; |
| 1872 | } |
| 1873 | default: |
| 1874 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1875 | } |
| 1876 | } |
| 1877 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1878 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1879 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1883 | HandleBinaryOp(instruction); |
| 1884 | } |
| 1885 | |
| 1886 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1887 | HandleBinaryOp(instruction); |
| 1888 | } |
| 1889 | |
| 1890 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1891 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1894 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1895 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 1896 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1898 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 1899 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1900 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1901 | } |
| 1902 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1903 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1904 | Register dst = OutputRegister(instr); |
| 1905 | Register lhs = InputRegisterAt(instr, 0); |
| 1906 | Register rhs = InputRegisterAt(instr, 1); |
| 1907 | |
| 1908 | switch (instr->GetOpKind()) { |
| 1909 | case HInstruction::kAnd: |
| 1910 | __ Bic(dst, lhs, rhs); |
| 1911 | break; |
| 1912 | case HInstruction::kOr: |
| 1913 | __ Orn(dst, lhs, rhs); |
| 1914 | break; |
| 1915 | case HInstruction::kXor: |
| 1916 | __ Eon(dst, lhs, rhs); |
| 1917 | break; |
| 1918 | default: |
| 1919 | LOG(FATAL) << "Unreachable"; |
| 1920 | } |
| 1921 | } |
| 1922 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1923 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 1924 | HArm64DataProcWithShifterOp* instruction) { |
| 1925 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 1926 | instruction->GetType() == Primitive::kPrimLong); |
| 1927 | LocationSummary* locations = |
| 1928 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1929 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 1930 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 1931 | } else { |
| 1932 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1933 | } |
| 1934 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1935 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1936 | } |
| 1937 | |
| 1938 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 1939 | HArm64DataProcWithShifterOp* instruction) { |
| 1940 | Primitive::Type type = instruction->GetType(); |
| 1941 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1942 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1943 | Register out = OutputRegister(instruction); |
| 1944 | Register left; |
| 1945 | if (kind != HInstruction::kNeg) { |
| 1946 | left = InputRegisterAt(instruction, 0); |
| 1947 | } |
| 1948 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 1949 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 1950 | // conversion) can have a different type from the current instruction's type, |
| 1951 | // so we manually indicate the type. |
| 1952 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1953 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 1954 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1955 | |
| 1956 | Operand right_operand(0); |
| 1957 | |
| 1958 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 1959 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 1960 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 1961 | } else { |
| 1962 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 1963 | } |
| 1964 | |
| 1965 | // Logical binary operations do not support extension operations in the |
| 1966 | // operand. Note that VIXL would still manage if it was passed by generating |
| 1967 | // the extension as a separate instruction. |
| 1968 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 1969 | DCHECK(!right_operand.IsExtendedRegister() || |
| 1970 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 1971 | kind != HInstruction::kNeg)); |
| 1972 | switch (kind) { |
| 1973 | case HInstruction::kAdd: |
| 1974 | __ Add(out, left, right_operand); |
| 1975 | break; |
| 1976 | case HInstruction::kAnd: |
| 1977 | __ And(out, left, right_operand); |
| 1978 | break; |
| 1979 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1980 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1981 | __ Neg(out, right_operand); |
| 1982 | break; |
| 1983 | case HInstruction::kOr: |
| 1984 | __ Orr(out, left, right_operand); |
| 1985 | break; |
| 1986 | case HInstruction::kSub: |
| 1987 | __ Sub(out, left, right_operand); |
| 1988 | break; |
| 1989 | case HInstruction::kXor: |
| 1990 | __ Eor(out, left, right_operand); |
| 1991 | break; |
| 1992 | default: |
| 1993 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 1994 | UNREACHABLE(); |
| 1995 | } |
| 1996 | } |
| 1997 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1998 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 1999 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2000 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2001 | LocationSummary* locations = |
| 2002 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2003 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2004 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 2005 | locations->SetOut(Location::RequiresRegister()); |
| 2006 | } |
| 2007 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2008 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress( |
| 2009 | HIntermediateAddress* instruction) { |
| 2010 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2011 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2012 | __ Add(OutputRegister(instruction), |
| 2013 | InputRegisterAt(instruction, 0), |
| 2014 | Operand(InputOperandAt(instruction, 1))); |
| 2015 | } |
| 2016 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2017 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2018 | LocationSummary* locations = |
| 2019 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2020 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2021 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2022 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2023 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2024 | // Don't allocate register for Mneg instruction. |
| 2025 | } else { |
| 2026 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2027 | Location::RequiresRegister()); |
| 2028 | } |
| 2029 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2030 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2032 | } |
| 2033 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2034 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2035 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2036 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2037 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2038 | |
| 2039 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2040 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2041 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2042 | if (instr->GetType() == Primitive::kPrimLong && |
| 2043 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2044 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2045 | vixl::aarch64::Instruction* prev = |
| 2046 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2047 | if (prev->IsLoadOrStore()) { |
| 2048 | // Make sure we emit only exactly one nop. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2049 | vixl::aarch64::CodeBufferCheckScope scope(masm, |
| 2050 | kInstructionSize, |
| 2051 | vixl::aarch64::CodeBufferCheckScope::kCheck, |
| 2052 | vixl::aarch64::CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2053 | __ nop(); |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2058 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2059 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2060 | } else { |
| 2061 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2062 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2063 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2064 | __ Mneg(res, mul_left, mul_right); |
| 2065 | } else { |
| 2066 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2067 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2068 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2072 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2073 | bool object_array_get_with_read_barrier = |
| 2074 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2075 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2076 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2077 | object_array_get_with_read_barrier ? |
| 2078 | LocationSummary::kCallOnSlowPath : |
| 2079 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2080 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2081 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2082 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2083 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2084 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2085 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2086 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2087 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2088 | // The output overlaps in the case of an object array get with |
| 2089 | // read barriers enabled: we do not want the move to overwrite the |
| 2090 | // array's location, as we need it to emit the read barrier. |
| 2091 | locations->SetOut( |
| 2092 | Location::RequiresRegister(), |
| 2093 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2094 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2098 | Primitive::Type type = instruction->GetType(); |
| 2099 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2100 | LocationSummary* locations = instruction->GetLocations(); |
| 2101 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2102 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2103 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2104 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2105 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2106 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2107 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2108 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2109 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2110 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2111 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2112 | // Object ArrayGet with Baker's read barrier case. |
| 2113 | Register temp = temps.AcquireW(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2114 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2115 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2116 | // Note that a potential implicit null check is handled in the |
| 2117 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2118 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2119 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2120 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2121 | // General case. |
| 2122 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2123 | Register length; |
| 2124 | if (maybe_compressed_char_at) { |
| 2125 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2126 | length = temps.AcquireW(); |
| 2127 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2128 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2129 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2130 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2131 | if (maybe_compressed_char_at) { |
| 2132 | vixl::aarch64::Label uncompressed_load, done; |
| 2133 | __ Tbz(length.W(), kWRegSize - 1, &uncompressed_load); |
| 2134 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2135 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2136 | __ B(&done); |
| 2137 | __ Bind(&uncompressed_load); |
| 2138 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2139 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2140 | __ Bind(&done); |
| 2141 | } else { |
| 2142 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2143 | source = HeapOperand(obj, offset); |
| 2144 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2145 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2146 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2147 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2148 | // The read barrier instrumentation does not support the |
| 2149 | // HIntermediateAddress instruction yet. |
| 2150 | DCHECK(!kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2151 | // We do not need to compute the intermediate address from the array: the |
| 2152 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2153 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2154 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2155 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2156 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2157 | } |
| 2158 | temp = obj; |
| 2159 | } else { |
| 2160 | __ Add(temp, obj, offset); |
| 2161 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2162 | if (maybe_compressed_char_at) { |
| 2163 | vixl::aarch64::Label uncompressed_load, done; |
| 2164 | __ Tbz(length.W(), kWRegSize - 1, &uncompressed_load); |
| 2165 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2166 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2167 | __ B(&done); |
| 2168 | __ Bind(&uncompressed_load); |
| 2169 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2170 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2171 | __ Bind(&done); |
| 2172 | } else { |
| 2173 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2174 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2175 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2176 | if (!maybe_compressed_char_at) { |
| 2177 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2178 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2179 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2180 | |
| 2181 | if (type == Primitive::kPrimNot) { |
| 2182 | static_assert( |
| 2183 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2184 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2185 | Location obj_loc = locations->InAt(0); |
| 2186 | if (index.IsConstant()) { |
| 2187 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2188 | } else { |
| 2189 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2190 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2191 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2192 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2195 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2196 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2197 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2198 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2202 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2203 | vixl::aarch64::Register out = OutputRegister(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2204 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2205 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2206 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame^] | 2207 | // Mask out compression flag from String's array length. |
| 2208 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2209 | __ And(out.W(), out.W(), Operand(static_cast<int32_t>(INT32_MAX))); |
| 2210 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2211 | } |
| 2212 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2213 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2214 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2215 | |
| 2216 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2217 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2218 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2219 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2220 | LocationSummary::kCallOnSlowPath : |
| 2221 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2223 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2224 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2225 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2226 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2227 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2228 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2229 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2234 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2235 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2236 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2237 | bool needs_write_barrier = |
| 2238 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2239 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2240 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2241 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2242 | CPURegister source = value; |
| 2243 | Location index = locations->InAt(1); |
| 2244 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2245 | MemOperand destination = HeapOperand(array); |
| 2246 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2247 | BlockPoolsScope block_pools(masm); |
| 2248 | |
| 2249 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2250 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2251 | if (index.IsConstant()) { |
| 2252 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2253 | destination = HeapOperand(array, offset); |
| 2254 | } else { |
| 2255 | UseScratchRegisterScope temps(masm); |
| 2256 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2257 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2258 | // The read barrier instrumentation does not support the |
| 2259 | // HIntermediateAddress instruction yet. |
| 2260 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2261 | // We do not need to compute the intermediate address from the array: the |
| 2262 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2263 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2264 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2265 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2266 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2267 | } |
| 2268 | temp = array; |
| 2269 | } else { |
| 2270 | __ Add(temp, array, offset); |
| 2271 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2272 | destination = HeapOperand(temp, |
| 2273 | XRegisterFrom(index), |
| 2274 | LSL, |
| 2275 | Primitive::ComponentSizeShift(value_type)); |
| 2276 | } |
| 2277 | codegen_->Store(value_type, value, destination); |
| 2278 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2279 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2280 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2281 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2282 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2283 | { |
| 2284 | // We use a block to end the scratch scope before the write barrier, thus |
| 2285 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2286 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2287 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2288 | if (index.IsConstant()) { |
| 2289 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2290 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2291 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2292 | destination = HeapOperand(temp, |
| 2293 | XRegisterFrom(index), |
| 2294 | LSL, |
| 2295 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2296 | } |
| 2297 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2298 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2299 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2300 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2301 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2302 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2303 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2304 | codegen_->AddSlowPath(slow_path); |
| 2305 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2306 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2307 | __ Cbnz(Register(value), &non_zero); |
| 2308 | if (!index.IsConstant()) { |
| 2309 | __ Add(temp, array, offset); |
| 2310 | } |
| 2311 | __ Str(wzr, destination); |
| 2312 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2313 | __ B(&done); |
| 2314 | __ Bind(&non_zero); |
| 2315 | } |
| 2316 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2317 | // Note that when Baker read barriers are enabled, the type |
| 2318 | // checks are performed without read barriers. This is fine, |
| 2319 | // even in the case where a class object is in the from-space |
| 2320 | // after the flip, as a comparison involving such a type would |
| 2321 | // not produce a false positive; it may of course produce a |
| 2322 | // false negative, in which case we would take the ArraySet |
| 2323 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2324 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2325 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2326 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2327 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2328 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2329 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2330 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2331 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2332 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2333 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2334 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2335 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2336 | // nor `temp2`, as we are comparing two poisoned references. |
| 2337 | __ Cmp(temp, temp2); |
| 2338 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2339 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2340 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2341 | vixl::aarch64::Label do_put; |
| 2342 | __ B(eq, &do_put); |
| 2343 | // If heap poisoning is enabled, the `temp` reference has |
| 2344 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2345 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2346 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2347 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2348 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2349 | // If heap poisoning is enabled, no need to unpoison |
| 2350 | // `temp`, as we are comparing against null below. |
| 2351 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2352 | __ Bind(&do_put); |
| 2353 | } else { |
| 2354 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2359 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2360 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2361 | __ Mov(temp2, value.W()); |
| 2362 | GetAssembler()->PoisonHeapReference(temp2); |
| 2363 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | if (!index.IsConstant()) { |
| 2367 | __ Add(temp, array, offset); |
| 2368 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2369 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2370 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2371 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2373 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2374 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2375 | |
| 2376 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2377 | |
| 2378 | if (done.IsLinked()) { |
| 2379 | __ Bind(&done); |
| 2380 | } |
| 2381 | |
| 2382 | if (slow_path != nullptr) { |
| 2383 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2384 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2388 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2389 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2390 | InvokeRuntimeCallingConvention calling_convention; |
| 2391 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2392 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2393 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2394 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2395 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2399 | BoundsCheckSlowPathARM64* slow_path = |
| 2400 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2401 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2402 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2403 | __ B(slow_path->GetEntryLabel(), hs); |
| 2404 | } |
| 2405 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2406 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2407 | LocationSummary* locations = |
| 2408 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2409 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2410 | if (check->HasUses()) { |
| 2411 | locations->SetOut(Location::SameAsFirstInput()); |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2416 | // We assume the class is not null. |
| 2417 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2418 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2419 | codegen_->AddSlowPath(slow_path); |
| 2420 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2421 | } |
| 2422 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2423 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2424 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2425 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2426 | } |
| 2427 | |
| 2428 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2429 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2430 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2431 | if (rhs_loc.IsConstant()) { |
| 2432 | // 0.0 is the only immediate that can be encoded directly in |
| 2433 | // an FCMP instruction. |
| 2434 | // |
| 2435 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2436 | // specify that in a floating-point comparison, positive zero |
| 2437 | // and negative zero are considered equal, so we can use the |
| 2438 | // literal 0.0 for both cases here. |
| 2439 | // |
| 2440 | // Note however that some methods (Float.equal, Float.compare, |
| 2441 | // Float.compareTo, Double.equal, Double.compare, |
| 2442 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2443 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2444 | // -0.0. So if we ever translate calls to these methods into a |
| 2445 | // HCompare instruction, we must handle the -0.0 case with |
| 2446 | // care here. |
| 2447 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2448 | __ Fcmp(lhs_reg, 0.0); |
| 2449 | } else { |
| 2450 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2451 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2454 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2455 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2456 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2457 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2458 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimBoolean: |
| 2460 | case Primitive::kPrimByte: |
| 2461 | case Primitive::kPrimShort: |
| 2462 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2463 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2464 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2465 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2466 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2467 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2468 | break; |
| 2469 | } |
| 2470 | case Primitive::kPrimFloat: |
| 2471 | case Primitive::kPrimDouble: { |
| 2472 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2473 | locations->SetInAt(1, |
| 2474 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2475 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2476 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2477 | locations->SetOut(Location::RequiresRegister()); |
| 2478 | break; |
| 2479 | } |
| 2480 | default: |
| 2481 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2486 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2487 | |
| 2488 | // 0 if: left == right |
| 2489 | // 1 if: left > right |
| 2490 | // -1 if: left < right |
| 2491 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimBoolean: |
| 2493 | case Primitive::kPrimByte: |
| 2494 | case Primitive::kPrimShort: |
| 2495 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2496 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimLong: { |
| 2498 | Register result = OutputRegister(compare); |
| 2499 | Register left = InputRegisterAt(compare, 0); |
| 2500 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2501 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2502 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2503 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2504 | break; |
| 2505 | } |
| 2506 | case Primitive::kPrimFloat: |
| 2507 | case Primitive::kPrimDouble: { |
| 2508 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2509 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2510 | __ Cset(result, ne); |
| 2511 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2512 | break; |
| 2513 | } |
| 2514 | default: |
| 2515 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2516 | } |
| 2517 | } |
| 2518 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2519 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2520 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2521 | |
| 2522 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2523 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2524 | locations->SetInAt(1, |
| 2525 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2526 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2527 | : Location::RequiresFpuRegister()); |
| 2528 | } else { |
| 2529 | // Integer cases. |
| 2530 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2531 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2532 | } |
| 2533 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2534 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2535 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2539 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2540 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2541 | return; |
| 2542 | } |
| 2543 | |
| 2544 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2545 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2546 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2547 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2548 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2549 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2550 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2551 | } else { |
| 2552 | // Integer cases. |
| 2553 | Register lhs = InputRegisterAt(instruction, 0); |
| 2554 | Operand rhs = InputOperandAt(instruction, 1); |
| 2555 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2556 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2557 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2561 | M(Equal) \ |
| 2562 | M(NotEqual) \ |
| 2563 | M(LessThan) \ |
| 2564 | M(LessThanOrEqual) \ |
| 2565 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2566 | M(GreaterThanOrEqual) \ |
| 2567 | M(Below) \ |
| 2568 | M(BelowOrEqual) \ |
| 2569 | M(Above) \ |
| 2570 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2571 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2572 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2573 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2574 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2575 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2576 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2577 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2578 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2579 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2580 | |
| 2581 | LocationSummary* locations = instruction->GetLocations(); |
| 2582 | Location second = locations->InAt(1); |
| 2583 | DCHECK(second.IsConstant()); |
| 2584 | |
| 2585 | Register out = OutputRegister(instruction); |
| 2586 | Register dividend = InputRegisterAt(instruction, 0); |
| 2587 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2588 | DCHECK(imm == 1 || imm == -1); |
| 2589 | |
| 2590 | if (instruction->IsRem()) { |
| 2591 | __ Mov(out, 0); |
| 2592 | } else { |
| 2593 | if (imm == 1) { |
| 2594 | __ Mov(out, dividend); |
| 2595 | } else { |
| 2596 | __ Neg(out, dividend); |
| 2597 | } |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2602 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2603 | |
| 2604 | LocationSummary* locations = instruction->GetLocations(); |
| 2605 | Location second = locations->InAt(1); |
| 2606 | DCHECK(second.IsConstant()); |
| 2607 | |
| 2608 | Register out = OutputRegister(instruction); |
| 2609 | Register dividend = InputRegisterAt(instruction, 0); |
| 2610 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2611 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2612 | int ctz_imm = CTZ(abs_imm); |
| 2613 | |
| 2614 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2615 | Register temp = temps.AcquireSameSizeAs(out); |
| 2616 | |
| 2617 | if (instruction->IsDiv()) { |
| 2618 | __ Add(temp, dividend, abs_imm - 1); |
| 2619 | __ Cmp(dividend, 0); |
| 2620 | __ Csel(out, temp, dividend, lt); |
| 2621 | if (imm > 0) { |
| 2622 | __ Asr(out, out, ctz_imm); |
| 2623 | } else { |
| 2624 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2625 | } |
| 2626 | } else { |
| 2627 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2628 | __ Asr(temp, dividend, bits - 1); |
| 2629 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2630 | __ Add(out, dividend, temp); |
| 2631 | __ And(out, out, abs_imm - 1); |
| 2632 | __ Sub(out, out, temp); |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2637 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2638 | |
| 2639 | LocationSummary* locations = instruction->GetLocations(); |
| 2640 | Location second = locations->InAt(1); |
| 2641 | DCHECK(second.IsConstant()); |
| 2642 | |
| 2643 | Register out = OutputRegister(instruction); |
| 2644 | Register dividend = InputRegisterAt(instruction, 0); |
| 2645 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2646 | |
| 2647 | Primitive::Type type = instruction->GetResultType(); |
| 2648 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2649 | |
| 2650 | int64_t magic; |
| 2651 | int shift; |
| 2652 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2653 | |
| 2654 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2655 | Register temp = temps.AcquireSameSizeAs(out); |
| 2656 | |
| 2657 | // temp = get_high(dividend * magic) |
| 2658 | __ Mov(temp, magic); |
| 2659 | if (type == Primitive::kPrimLong) { |
| 2660 | __ Smulh(temp, dividend, temp); |
| 2661 | } else { |
| 2662 | __ Smull(temp.X(), dividend, temp); |
| 2663 | __ Lsr(temp.X(), temp.X(), 32); |
| 2664 | } |
| 2665 | |
| 2666 | if (imm > 0 && magic < 0) { |
| 2667 | __ Add(temp, temp, dividend); |
| 2668 | } else if (imm < 0 && magic > 0) { |
| 2669 | __ Sub(temp, temp, dividend); |
| 2670 | } |
| 2671 | |
| 2672 | if (shift != 0) { |
| 2673 | __ Asr(temp, temp, shift); |
| 2674 | } |
| 2675 | |
| 2676 | if (instruction->IsDiv()) { |
| 2677 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2678 | } else { |
| 2679 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2680 | // TODO: Strength reduction for msub. |
| 2681 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2682 | __ Mov(temp_imm, imm); |
| 2683 | __ Msub(out, temp, temp_imm, dividend); |
| 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2688 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2689 | Primitive::Type type = instruction->GetResultType(); |
| 2690 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2691 | |
| 2692 | LocationSummary* locations = instruction->GetLocations(); |
| 2693 | Register out = OutputRegister(instruction); |
| 2694 | Location second = locations->InAt(1); |
| 2695 | |
| 2696 | if (second.IsConstant()) { |
| 2697 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2698 | |
| 2699 | if (imm == 0) { |
| 2700 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2701 | } else if (imm == 1 || imm == -1) { |
| 2702 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2703 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2704 | DivRemByPowerOfTwo(instruction); |
| 2705 | } else { |
| 2706 | DCHECK(imm <= -2 || imm >= 2); |
| 2707 | GenerateDivRemWithAnyConstant(instruction); |
| 2708 | } |
| 2709 | } else { |
| 2710 | Register dividend = InputRegisterAt(instruction, 0); |
| 2711 | Register divisor = InputRegisterAt(instruction, 1); |
| 2712 | if (instruction->IsDiv()) { |
| 2713 | __ Sdiv(out, dividend, divisor); |
| 2714 | } else { |
| 2715 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2716 | Register temp = temps.AcquireSameSizeAs(out); |
| 2717 | __ Sdiv(temp, dividend, divisor); |
| 2718 | __ Msub(out, temp, divisor, dividend); |
| 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2723 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2724 | LocationSummary* locations = |
| 2725 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2726 | switch (div->GetResultType()) { |
| 2727 | case Primitive::kPrimInt: |
| 2728 | case Primitive::kPrimLong: |
| 2729 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2730 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2731 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2732 | break; |
| 2733 | |
| 2734 | case Primitive::kPrimFloat: |
| 2735 | case Primitive::kPrimDouble: |
| 2736 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2737 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2738 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2739 | break; |
| 2740 | |
| 2741 | default: |
| 2742 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2747 | Primitive::Type type = div->GetResultType(); |
| 2748 | switch (type) { |
| 2749 | case Primitive::kPrimInt: |
| 2750 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2751 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2752 | break; |
| 2753 | |
| 2754 | case Primitive::kPrimFloat: |
| 2755 | case Primitive::kPrimDouble: |
| 2756 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2757 | break; |
| 2758 | |
| 2759 | default: |
| 2760 | LOG(FATAL) << "Unexpected div type " << type; |
| 2761 | } |
| 2762 | } |
| 2763 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2764 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2765 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2766 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2770 | SlowPathCodeARM64* slow_path = |
| 2771 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2772 | codegen_->AddSlowPath(slow_path); |
| 2773 | Location value = instruction->GetLocations()->InAt(0); |
| 2774 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2775 | Primitive::Type type = instruction->GetType(); |
| 2776 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2777 | if (!Primitive::IsIntegralType(type)) { |
| 2778 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2779 | return; |
| 2780 | } |
| 2781 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2782 | if (value.IsConstant()) { |
| 2783 | int64_t divisor = Int64ConstantFrom(value); |
| 2784 | if (divisor == 0) { |
| 2785 | __ B(slow_path->GetEntryLabel()); |
| 2786 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2787 | // A division by a non-null constant is valid. We don't need to perform |
| 2788 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2789 | } |
| 2790 | } else { |
| 2791 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2792 | } |
| 2793 | } |
| 2794 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2795 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2796 | LocationSummary* locations = |
| 2797 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2798 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2799 | } |
| 2800 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2801 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2802 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2803 | // Will be generated at use site. |
| 2804 | } |
| 2805 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2806 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2807 | exit->SetLocations(nullptr); |
| 2808 | } |
| 2809 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2810 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2811 | } |
| 2812 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2813 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2814 | LocationSummary* locations = |
| 2815 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2816 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2817 | } |
| 2818 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2819 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2820 | // Will be generated at use site. |
| 2821 | } |
| 2822 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2823 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2824 | DCHECK(!successor->IsExitBlock()); |
| 2825 | HBasicBlock* block = got->GetBlock(); |
| 2826 | HInstruction* previous = got->GetPrevious(); |
| 2827 | HLoopInformation* info = block->GetLoopInformation(); |
| 2828 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2829 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2830 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2831 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2832 | return; |
| 2833 | } |
| 2834 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2835 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2836 | } |
| 2837 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2838 | __ B(codegen_->GetLabelOf(successor)); |
| 2839 | } |
| 2840 | } |
| 2841 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2842 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2843 | got->SetLocations(nullptr); |
| 2844 | } |
| 2845 | |
| 2846 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2847 | HandleGoto(got, got->GetSuccessor()); |
| 2848 | } |
| 2849 | |
| 2850 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2851 | try_boundary->SetLocations(nullptr); |
| 2852 | } |
| 2853 | |
| 2854 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2855 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2856 | if (!successor->IsExitBlock()) { |
| 2857 | HandleGoto(try_boundary, successor); |
| 2858 | } |
| 2859 | } |
| 2860 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2861 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2862 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2863 | vixl::aarch64::Label* true_target, |
| 2864 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2865 | // FP branching requires both targets to be explicit. If either of the targets |
| 2866 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2867 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2868 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2869 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2870 | if (true_target == nullptr && false_target == nullptr) { |
| 2871 | // Nothing to do. The code always falls through. |
| 2872 | return; |
| 2873 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2874 | // Constant condition, statically compared against "true" (integer value 1). |
| 2875 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2876 | if (true_target != nullptr) { |
| 2877 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2878 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2879 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2880 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2881 | if (false_target != nullptr) { |
| 2882 | __ B(false_target); |
| 2883 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2884 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2885 | return; |
| 2886 | } |
| 2887 | |
| 2888 | // The following code generates these patterns: |
| 2889 | // (1) true_target == nullptr && false_target != nullptr |
| 2890 | // - opposite condition true => branch to false_target |
| 2891 | // (2) true_target != nullptr && false_target == nullptr |
| 2892 | // - condition true => branch to true_target |
| 2893 | // (3) true_target != nullptr && false_target != nullptr |
| 2894 | // - condition true => branch to true_target |
| 2895 | // - branch to false_target |
| 2896 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2897 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2898 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2899 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2900 | if (true_target == nullptr) { |
| 2901 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 2902 | } else { |
| 2903 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 2904 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2905 | } else { |
| 2906 | // The condition instruction has not been materialized, use its inputs as |
| 2907 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2908 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2909 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2910 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2911 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2912 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2913 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2914 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 2915 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2916 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2917 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2918 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2919 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2920 | // Integer cases. |
| 2921 | Register lhs = InputRegisterAt(condition, 0); |
| 2922 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2923 | |
| 2924 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2925 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2926 | if (true_target == nullptr) { |
| 2927 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 2928 | non_fallthrough_target = false_target; |
| 2929 | } else { |
| 2930 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2931 | non_fallthrough_target = true_target; |
| 2932 | } |
| 2933 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 2934 | 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] | 2935 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2936 | switch (arm64_cond) { |
| 2937 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2938 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2939 | break; |
| 2940 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2941 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2942 | break; |
| 2943 | case lt: |
| 2944 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2945 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2946 | break; |
| 2947 | case ge: |
| 2948 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2949 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2950 | break; |
| 2951 | default: |
| 2952 | // Without the `static_cast` the compiler throws an error for |
| 2953 | // `-Werror=sign-promo`. |
| 2954 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 2955 | } |
| 2956 | } else { |
| 2957 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2958 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2959 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2960 | } |
| 2961 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2962 | |
| 2963 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2964 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2965 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2966 | __ B(false_target); |
| 2967 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (fallthrough_target.IsLinked()) { |
| 2970 | __ Bind(&fallthrough_target); |
| 2971 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2972 | } |
| 2973 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2974 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 2975 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2976 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2982 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2983 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2984 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 2985 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 2986 | true_target = nullptr; |
| 2987 | } |
| 2988 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 2989 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 2990 | false_target = nullptr; |
| 2991 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2992 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2996 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2997 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2998 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2999 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3000 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3005 | SlowPathCodeARM64* slow_path = |
| 3006 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3007 | GenerateTestAndBranch(deoptimize, |
| 3008 | /* condition_input_index */ 0, |
| 3009 | slow_path->GetEntryLabel(), |
| 3010 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3013 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3014 | return condition->IsCondition() && |
| 3015 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3016 | } |
| 3017 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3018 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3019 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3020 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3021 | : ARM64Condition(cond); |
| 3022 | } |
| 3023 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3024 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3025 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3026 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3027 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3028 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3029 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3030 | } else { |
| 3031 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3032 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3033 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3034 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3035 | // Ask VIXL whether we should synthesize constants in registers. |
| 3036 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3037 | Operand true_op = is_true_value_constant ? |
| 3038 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3039 | Operand false_op = is_false_value_constant ? |
| 3040 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3041 | bool true_value_in_register = false; |
| 3042 | bool false_value_in_register = false; |
| 3043 | MacroAssembler::GetCselSynthesisInformation( |
| 3044 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3045 | true_value_in_register |= !is_true_value_constant; |
| 3046 | false_value_in_register |= !is_false_value_constant; |
| 3047 | |
| 3048 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3049 | : Location::ConstantLocation(cst_true_value)); |
| 3050 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3051 | : Location::ConstantLocation(cst_false_value)); |
| 3052 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3053 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3054 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3055 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3056 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3057 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3061 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3062 | Condition csel_cond; |
| 3063 | |
| 3064 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3065 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3066 | // Use the condition flags set by the previous instruction. |
| 3067 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3068 | } else { |
| 3069 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3070 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3071 | } |
| 3072 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3073 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3074 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3075 | } else { |
| 3076 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3077 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3080 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3081 | __ Fcsel(OutputFPRegister(select), |
| 3082 | InputFPRegisterAt(select, 1), |
| 3083 | InputFPRegisterAt(select, 0), |
| 3084 | csel_cond); |
| 3085 | } else { |
| 3086 | __ Csel(OutputRegister(select), |
| 3087 | InputOperandAt(select, 1), |
| 3088 | InputOperandAt(select, 0), |
| 3089 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3090 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3093 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3094 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3095 | } |
| 3096 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3097 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3098 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | void CodeGeneratorARM64::GenerateNop() { |
| 3102 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3105 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3106 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3110 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3114 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3118 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3119 | } |
| 3120 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3121 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 3122 | return kEmitCompilerReadBarrier && |
| 3123 | (kUseBakerReadBarrier || |
| 3124 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3125 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3126 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 3127 | } |
| 3128 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3129 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3130 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3131 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3132 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3133 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3134 | case TypeCheckKind::kExactCheck: |
| 3135 | case TypeCheckKind::kAbstractClassCheck: |
| 3136 | case TypeCheckKind::kClassHierarchyCheck: |
| 3137 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3138 | call_kind = |
| 3139 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3140 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3141 | break; |
| 3142 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3143 | case TypeCheckKind::kUnresolvedCheck: |
| 3144 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3145 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3146 | break; |
| 3147 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3148 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3149 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3150 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3151 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3152 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3154 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3155 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3156 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3157 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3158 | // When read barriers are enabled, we need a temporary register for |
| 3159 | // some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3160 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3161 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3162 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3166 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3167 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3168 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3169 | Register obj = InputRegisterAt(instruction, 0); |
| 3170 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3171 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3172 | Register out = OutputRegister(instruction); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3173 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3174 | locations->GetTemp(0) : |
| 3175 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3176 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3177 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3178 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3179 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3180 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3181 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3182 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3183 | |
| 3184 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3185 | // Avoid null check if we know `obj` is not null. |
| 3186 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3187 | __ Cbz(obj, &zero); |
| 3188 | } |
| 3189 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3190 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3191 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3192 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3193 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3194 | case TypeCheckKind::kExactCheck: { |
| 3195 | __ Cmp(out, cls); |
| 3196 | __ Cset(out, eq); |
| 3197 | if (zero.IsLinked()) { |
| 3198 | __ B(&done); |
| 3199 | } |
| 3200 | break; |
| 3201 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3202 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3203 | case TypeCheckKind::kAbstractClassCheck: { |
| 3204 | // If the class is abstract, we eagerly fetch the super class of the |
| 3205 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3206 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3207 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3208 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3209 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3210 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3211 | __ Cbz(out, &done); |
| 3212 | __ Cmp(out, cls); |
| 3213 | __ B(ne, &loop); |
| 3214 | __ Mov(out, 1); |
| 3215 | if (zero.IsLinked()) { |
| 3216 | __ B(&done); |
| 3217 | } |
| 3218 | break; |
| 3219 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3220 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3221 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3222 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3223 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3224 | __ Bind(&loop); |
| 3225 | __ Cmp(out, cls); |
| 3226 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3227 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3228 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3229 | __ Cbnz(out, &loop); |
| 3230 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3231 | __ B(&done); |
| 3232 | __ Bind(&success); |
| 3233 | __ Mov(out, 1); |
| 3234 | if (zero.IsLinked()) { |
| 3235 | __ B(&done); |
| 3236 | } |
| 3237 | break; |
| 3238 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3239 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3240 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3241 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3242 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3243 | __ Cmp(out, cls); |
| 3244 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3245 | // 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] | 3246 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3247 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3248 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3249 | __ Cbz(out, &done); |
| 3250 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3251 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3252 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3253 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3254 | __ Mov(out, 1); |
| 3255 | __ B(&done); |
| 3256 | break; |
| 3257 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3258 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3259 | case TypeCheckKind::kArrayCheck: { |
| 3260 | __ Cmp(out, cls); |
| 3261 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3262 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3263 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3264 | codegen_->AddSlowPath(slow_path); |
| 3265 | __ B(ne, slow_path->GetEntryLabel()); |
| 3266 | __ Mov(out, 1); |
| 3267 | if (zero.IsLinked()) { |
| 3268 | __ B(&done); |
| 3269 | } |
| 3270 | break; |
| 3271 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3272 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3273 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3274 | case TypeCheckKind::kInterfaceCheck: { |
| 3275 | // Note that we indeed only call on slow path, but we always go |
| 3276 | // into the slow path for the unresolved and interface check |
| 3277 | // cases. |
| 3278 | // |
| 3279 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3280 | // entry point without resorting to a type checking slow path |
| 3281 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3282 | // require to assign fixed registers for the inputs of this |
| 3283 | // HInstanceOf instruction (following the runtime calling |
| 3284 | // convention), which might be cluttered by the potential first |
| 3285 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3286 | // |
| 3287 | // TODO: Introduce a new runtime entry point taking the object |
| 3288 | // to test (instead of its class) as argument, and let it deal |
| 3289 | // with the read barrier issues. This will let us refactor this |
| 3290 | // case of the `switch` code as it was previously (with a direct |
| 3291 | // call to the runtime not using a type checking slow path). |
| 3292 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3293 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3294 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3295 | /* is_fatal */ false); |
| 3296 | codegen_->AddSlowPath(slow_path); |
| 3297 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3298 | if (zero.IsLinked()) { |
| 3299 | __ B(&done); |
| 3300 | } |
| 3301 | break; |
| 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | if (zero.IsLinked()) { |
| 3306 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3307 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | if (done.IsLinked()) { |
| 3311 | __ Bind(&done); |
| 3312 | } |
| 3313 | |
| 3314 | if (slow_path != nullptr) { |
| 3315 | __ Bind(slow_path->GetExitLabel()); |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3320 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3321 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3322 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3323 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3324 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3325 | case TypeCheckKind::kExactCheck: |
| 3326 | case TypeCheckKind::kAbstractClassCheck: |
| 3327 | case TypeCheckKind::kClassHierarchyCheck: |
| 3328 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3329 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3330 | LocationSummary::kCallOnSlowPath : |
| 3331 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3332 | break; |
| 3333 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3334 | case TypeCheckKind::kUnresolvedCheck: |
| 3335 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3336 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3337 | break; |
| 3338 | } |
| 3339 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3340 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3342 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3343 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3344 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3345 | // When read barriers are enabled, we need an additional temporary |
| 3346 | // register for some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3347 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
| 3348 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3349 | } |
| 3350 | } |
| 3351 | |
| 3352 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3353 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3354 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3355 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3356 | Register obj = InputRegisterAt(instruction, 0); |
| 3357 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3358 | Location temp_loc = locations->GetTemp(0); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3359 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3360 | locations->GetTemp(1) : |
| 3361 | Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3362 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3363 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3364 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3365 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3366 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3367 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3368 | bool is_type_check_slow_path_fatal = |
| 3369 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3370 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3371 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3372 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3373 | !instruction->CanThrowIntoCatchBlock(); |
| 3374 | SlowPathCodeARM64* type_check_slow_path = |
| 3375 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3376 | is_type_check_slow_path_fatal); |
| 3377 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3378 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3379 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3380 | // Avoid null check if we know obj is not null. |
| 3381 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3382 | __ Cbz(obj, &done); |
| 3383 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3384 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3385 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3386 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3387 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3388 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3389 | case TypeCheckKind::kExactCheck: |
| 3390 | case TypeCheckKind::kArrayCheck: { |
| 3391 | __ Cmp(temp, cls); |
| 3392 | // Jump to slow path for throwing the exception or doing a |
| 3393 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3394 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3395 | break; |
| 3396 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3397 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3398 | case TypeCheckKind::kAbstractClassCheck: { |
| 3399 | // If the class is abstract, we eagerly fetch the super class of the |
| 3400 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3401 | vixl::aarch64::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3402 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3403 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3404 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3405 | |
| 3406 | // If the class reference currently in `temp` is not null, jump |
| 3407 | // to the `compare_classes` label to compare it with the checked |
| 3408 | // class. |
| 3409 | __ Cbnz(temp, &compare_classes); |
| 3410 | // Otherwise, jump to the slow path to throw the exception. |
| 3411 | // |
| 3412 | // But before, move back the object's class into `temp` before |
| 3413 | // going into the slow path, as it has been overwritten in the |
| 3414 | // meantime. |
| 3415 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3416 | GenerateReferenceLoadTwoRegisters( |
| 3417 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3418 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3419 | |
| 3420 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3421 | __ Cmp(temp, cls); |
| 3422 | __ B(ne, &loop); |
| 3423 | break; |
| 3424 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3425 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3426 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3427 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3428 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3429 | __ Bind(&loop); |
| 3430 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3431 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3432 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3433 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3434 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3435 | |
| 3436 | // If the class reference currently in `temp` is not null, jump |
| 3437 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3438 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3439 | // Otherwise, jump to the slow path to throw the exception. |
| 3440 | // |
| 3441 | // But before, move back the object's class into `temp` before |
| 3442 | // going into the slow path, as it has been overwritten in the |
| 3443 | // meantime. |
| 3444 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3445 | GenerateReferenceLoadTwoRegisters( |
| 3446 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3447 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3448 | break; |
| 3449 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3450 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3451 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3452 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3453 | vixl::aarch64::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3454 | __ Cmp(temp, cls); |
| 3455 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3456 | |
| 3457 | // 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] | 3458 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3459 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3460 | |
| 3461 | // If the component type is not null (i.e. the object is indeed |
| 3462 | // an array), jump to label `check_non_primitive_component_type` |
| 3463 | // to further check that this component type is not a primitive |
| 3464 | // type. |
| 3465 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3466 | // Otherwise, jump to the slow path to throw the exception. |
| 3467 | // |
| 3468 | // But before, move back the object's class into `temp` before |
| 3469 | // going into the slow path, as it has been overwritten in the |
| 3470 | // meantime. |
| 3471 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3472 | GenerateReferenceLoadTwoRegisters( |
| 3473 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3474 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3475 | |
| 3476 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3477 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3478 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3479 | __ Cbz(temp, &done); |
| 3480 | // Same comment as above regarding `temp` and the slow path. |
| 3481 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3482 | GenerateReferenceLoadTwoRegisters( |
| 3483 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3484 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3485 | break; |
| 3486 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3487 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3488 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3489 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3490 | // We always go into the type check slow path for the unresolved |
| 3491 | // and interface check cases. |
| 3492 | // |
| 3493 | // We cannot directly call the CheckCast runtime entry point |
| 3494 | // without resorting to a type checking slow path here (i.e. by |
| 3495 | // calling InvokeRuntime directly), as it would require to |
| 3496 | // assign fixed registers for the inputs of this HInstanceOf |
| 3497 | // instruction (following the runtime calling convention), which |
| 3498 | // might be cluttered by the potential first read barrier |
| 3499 | // emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3500 | // |
| 3501 | // TODO: Introduce a new runtime entry point taking the object |
| 3502 | // to test (instead of its class) as argument, and let it deal |
| 3503 | // with the read barrier issues. This will let us refactor this |
| 3504 | // case of the `switch` code as it was previously (with a direct |
| 3505 | // call to the runtime not using a type checking slow path). |
| 3506 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3507 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3508 | break; |
| 3509 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3510 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3511 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3512 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3515 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3516 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3517 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3518 | } |
| 3519 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3520 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3521 | // Will be generated at use site. |
| 3522 | } |
| 3523 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3524 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3525 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3526 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3527 | } |
| 3528 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3529 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3530 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3531 | } |
| 3532 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3533 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3534 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3535 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3536 | // the method_idx. |
| 3537 | HandleInvoke(invoke); |
| 3538 | } |
| 3539 | |
| 3540 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3541 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3542 | } |
| 3543 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3544 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3545 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3546 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3547 | } |
| 3548 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3549 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3550 | HandleInvoke(invoke); |
| 3551 | } |
| 3552 | |
| 3553 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3554 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3555 | LocationSummary* locations = invoke->GetLocations(); |
| 3556 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3557 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3558 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3559 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3560 | |
| 3561 | // The register ip1 is required to be used for the hidden argument in |
| 3562 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3563 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3564 | UseScratchRegisterScope scratch_scope(masm); |
| 3565 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3566 | scratch_scope.Exclude(ip1); |
| 3567 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3568 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3569 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3570 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3571 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3572 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3573 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3574 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3575 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3576 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3577 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3578 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3579 | // emit a read barrier for the previous class reference load. |
| 3580 | // However this is not required in practice, as this is an |
| 3581 | // intermediate/temporary reference and because the current |
| 3582 | // concurrent copying collector keeps the from-space memory |
| 3583 | // intact/accessible until the end of the marking phase (the |
| 3584 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3585 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3586 | __ Ldr(temp, |
| 3587 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3588 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3589 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3590 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3591 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3592 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3593 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3594 | // lr(); |
| 3595 | __ Blr(lr); |
| 3596 | DCHECK(!codegen_->IsLeafMethod()); |
| 3597 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3598 | } |
| 3599 | |
| 3600 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3601 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3602 | if (intrinsic.TryDispatch(invoke)) { |
| 3603 | return; |
| 3604 | } |
| 3605 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3606 | HandleInvoke(invoke); |
| 3607 | } |
| 3608 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3609 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3610 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3611 | // art::PrepareForRegisterAllocation. |
| 3612 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3613 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3614 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3615 | if (intrinsic.TryDispatch(invoke)) { |
| 3616 | return; |
| 3617 | } |
| 3618 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3619 | HandleInvoke(invoke); |
| 3620 | } |
| 3621 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3622 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3623 | if (invoke->GetLocations()->Intrinsified()) { |
| 3624 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3625 | intrinsic.Dispatch(invoke); |
| 3626 | return true; |
| 3627 | } |
| 3628 | return false; |
| 3629 | } |
| 3630 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3631 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3632 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3633 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3634 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3635 | return desired_dispatch_info; |
| 3636 | } |
| 3637 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3638 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3639 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3640 | bool direct_code_loaded = false; |
| 3641 | switch (invoke->GetCodePtrLocation()) { |
| 3642 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3643 | // LR = code address from literal pool with link-time patch. |
| 3644 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3645 | direct_code_loaded = true; |
| 3646 | break; |
| 3647 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3648 | // LR = invoke->GetDirectCodePtr(); |
| 3649 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3650 | direct_code_loaded = true; |
| 3651 | break; |
| 3652 | default: |
| 3653 | break; |
| 3654 | } |
| 3655 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3656 | // 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] | 3657 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3658 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3659 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 3660 | uint32_t offset = |
| 3661 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3662 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3663 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3664 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3665 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3666 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3667 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3668 | break; |
| 3669 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3670 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3671 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3672 | break; |
| 3673 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3674 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3675 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3676 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3677 | break; |
| 3678 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3679 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3680 | const DexFile& dex_file = invoke->GetDexFile(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3681 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3682 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3683 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3684 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3685 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3686 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3687 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3688 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3689 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3690 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3691 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3692 | Register reg = XRegisterFrom(temp); |
| 3693 | Register method_reg; |
| 3694 | if (current_method.IsRegister()) { |
| 3695 | method_reg = XRegisterFrom(current_method); |
| 3696 | } else { |
| 3697 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3698 | DCHECK(!current_method.IsValid()); |
| 3699 | method_reg = reg; |
| 3700 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3701 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3702 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3703 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3704 | __ Ldr(reg.X(), |
| 3705 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3706 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3707 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3708 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3709 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3710 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3711 | break; |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | switch (invoke->GetCodePtrLocation()) { |
| 3716 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3717 | __ Bl(&frame_entry_label_); |
| 3718 | break; |
| 3719 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3720 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 3721 | invoke->GetTargetMethod().dex_method_index); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3722 | vixl::aarch64::Label* label = &relative_call_patches_.back().label; |
| 3723 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3724 | __ Bind(label); |
| 3725 | __ 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] | 3726 | break; |
| 3727 | } |
| 3728 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3729 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3730 | // LR prepared above for better instruction scheduling. |
| 3731 | DCHECK(direct_code_loaded); |
| 3732 | // lr() |
| 3733 | __ Blr(lr); |
| 3734 | break; |
| 3735 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3736 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3737 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3738 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3739 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3740 | // lr() |
| 3741 | __ Blr(lr); |
| 3742 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3743 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3744 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3745 | DCHECK(!IsLeafMethod()); |
| 3746 | } |
| 3747 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3748 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3749 | // Use the calling convention instead of the location of the receiver, as |
| 3750 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3751 | // slow path, the arguments have been moved to the right place, so here we are |
| 3752 | // guaranteed that the receiver is the first register of the calling convention. |
| 3753 | InvokeDexCallingConvention calling_convention; |
| 3754 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3755 | Register temp = XRegisterFrom(temp_in); |
| 3756 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3757 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3758 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3759 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3760 | |
| 3761 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3762 | |
| 3763 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3764 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3765 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3766 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3767 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3768 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3769 | // intermediate/temporary reference and because the current |
| 3770 | // concurrent copying collector keeps the from-space memory |
| 3771 | // intact/accessible until the end of the marking phase (the |
| 3772 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3773 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3774 | // temp = temp->GetMethodAt(method_offset); |
| 3775 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3776 | // lr = temp->GetEntryPoint(); |
| 3777 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3778 | // lr(); |
| 3779 | __ Blr(lr); |
| 3780 | } |
| 3781 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3782 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 3783 | const DexFile& dex_file, |
| 3784 | uint32_t string_index, |
| 3785 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3786 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 3787 | } |
| 3788 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3789 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 3790 | const DexFile& dex_file, |
| 3791 | uint32_t type_index, |
| 3792 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3793 | return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_); |
| 3794 | } |
| 3795 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3796 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 3797 | const DexFile& dex_file, |
| 3798 | uint32_t element_offset, |
| 3799 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3800 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 3801 | } |
| 3802 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3803 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 3804 | const DexFile& dex_file, |
| 3805 | uint32_t offset_or_index, |
| 3806 | vixl::aarch64::Label* adrp_label, |
| 3807 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3808 | // Add a patch entry and return the label. |
| 3809 | patches->emplace_back(dex_file, offset_or_index); |
| 3810 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3811 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3812 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 3813 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 3814 | return label; |
| 3815 | } |
| 3816 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3817 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3818 | const DexFile& dex_file, uint32_t string_index) { |
| 3819 | return boot_image_string_patches_.GetOrCreate( |
| 3820 | StringReference(&dex_file, string_index), |
| 3821 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3822 | } |
| 3823 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3824 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3825 | const DexFile& dex_file, uint32_t type_index) { |
| 3826 | return boot_image_type_patches_.GetOrCreate( |
| 3827 | TypeReference(&dex_file, type_index), |
| 3828 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3829 | } |
| 3830 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3831 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 3832 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3833 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 3834 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 3835 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 3836 | } |
| 3837 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3838 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral( |
| 3839 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3840 | return DeduplicateUint64Literal(address); |
| 3841 | } |
| 3842 | |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3843 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 3844 | vixl::aarch64::Register reg) { |
| 3845 | DCHECK(reg.IsX()); |
| 3846 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3847 | __ Bind(fixup_label); |
| 3848 | __ adrp(reg, /* offset placeholder */ 0); |
| 3849 | } |
| 3850 | |
| 3851 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 3852 | vixl::aarch64::Register out, |
| 3853 | vixl::aarch64::Register base) { |
| 3854 | DCHECK(out.IsX()); |
| 3855 | DCHECK(base.IsX()); |
| 3856 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3857 | __ Bind(fixup_label); |
| 3858 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 3859 | } |
| 3860 | |
| 3861 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 3862 | vixl::aarch64::Register out, |
| 3863 | vixl::aarch64::Register base) { |
| 3864 | DCHECK(base.IsX()); |
| 3865 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3866 | __ Bind(fixup_label); |
| 3867 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 3868 | } |
| 3869 | |
| 3870 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 3871 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 3872 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 3873 | ArenaVector<LinkerPatch>* linker_patches) { |
| 3874 | for (const PcRelativePatchInfo& info : infos) { |
| 3875 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 3876 | &info.target_dex_file, |
| 3877 | info.pc_insn_label->GetLocation(), |
| 3878 | info.offset_or_index)); |
| 3879 | } |
| 3880 | } |
| 3881 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3882 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3883 | DCHECK(linker_patches->empty()); |
| 3884 | size_t size = |
| 3885 | method_patches_.size() + |
| 3886 | call_patches_.size() + |
| 3887 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3888 | pc_relative_dex_cache_patches_.size() + |
| 3889 | boot_image_string_patches_.size() + |
| 3890 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3891 | boot_image_type_patches_.size() + |
| 3892 | pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3893 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3894 | linker_patches->reserve(size); |
| 3895 | for (const auto& entry : method_patches_) { |
| 3896 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3897 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 3898 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3899 | target_method.dex_file, |
| 3900 | target_method.dex_method_index)); |
| 3901 | } |
| 3902 | for (const auto& entry : call_patches_) { |
| 3903 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3904 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 3905 | linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3906 | target_method.dex_file, |
| 3907 | target_method.dex_method_index)); |
| 3908 | } |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3909 | for (const PatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) { |
| 3910 | linker_patches->push_back( |
| 3911 | LinkerPatch::RelativeCodePatch(info.label.GetLocation(), &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3912 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3913 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3914 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3915 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3916 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3917 | info.offset_or_index)); |
| 3918 | } |
| 3919 | for (const auto& entry : boot_image_string_patches_) { |
| 3920 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3921 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3922 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3923 | target_string.dex_file, |
| 3924 | target_string.string_index)); |
| 3925 | } |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3926 | if (!GetCompilerOptions().IsBootImage()) { |
| 3927 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 3928 | linker_patches); |
| 3929 | } else { |
| 3930 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 3931 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3932 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3933 | for (const auto& entry : boot_image_type_patches_) { |
| 3934 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3935 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3936 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3937 | target_type.dex_file, |
| 3938 | target_type.type_index)); |
| 3939 | } |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 3940 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 3941 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3942 | for (const auto& entry : boot_image_address_patches_) { |
| 3943 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3944 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3945 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3946 | } |
| 3947 | } |
| 3948 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3949 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3950 | Uint32ToLiteralMap* map) { |
| 3951 | return map->GetOrCreate( |
| 3952 | value, |
| 3953 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 3954 | } |
| 3955 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3956 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3957 | return uint64_literals_.GetOrCreate( |
| 3958 | value, |
| 3959 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3962 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3963 | MethodReference target_method, |
| 3964 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3965 | return map->GetOrCreate( |
| 3966 | target_method, |
| 3967 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3970 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3971 | MethodReference target_method) { |
| 3972 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 3973 | } |
| 3974 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3975 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3976 | MethodReference target_method) { |
| 3977 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 3978 | } |
| 3979 | |
| 3980 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3981 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3982 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3983 | // art::PrepareForRegisterAllocation. |
| 3984 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3985 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3986 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3987 | return; |
| 3988 | } |
| 3989 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3990 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3991 | LocationSummary* locations = invoke->GetLocations(); |
| 3992 | codegen_->GenerateStaticOrDirectCall( |
| 3993 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3994 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3998 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3999 | return; |
| 4000 | } |
| 4001 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4002 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4003 | DCHECK(!codegen_->IsLeafMethod()); |
| 4004 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4005 | } |
| 4006 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4007 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4008 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4009 | switch (desired_class_load_kind) { |
| 4010 | case HLoadClass::LoadKind::kReferrersClass: |
| 4011 | break; |
| 4012 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4013 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4014 | break; |
| 4015 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4016 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4017 | break; |
| 4018 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4019 | break; |
| 4020 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 4021 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4022 | break; |
| 4023 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 4024 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4025 | break; |
| 4026 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4027 | break; |
| 4028 | } |
| 4029 | return desired_class_load_kind; |
| 4030 | } |
| 4031 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4032 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4033 | if (cls->NeedsAccessCheck()) { |
| 4034 | InvokeRuntimeCallingConvention calling_convention; |
| 4035 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4036 | cls, |
| 4037 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4038 | LocationFrom(vixl::aarch64::x0), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4039 | /* code_generator_supports_read_barrier */ true); |
| 4040 | return; |
| 4041 | } |
| 4042 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4043 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4044 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4045 | ? LocationSummary::kCallOnSlowPath |
| 4046 | : LocationSummary::kNoCall; |
| 4047 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4048 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4049 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4050 | } |
| 4051 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4052 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4053 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 4054 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4055 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4056 | } |
| 4057 | locations->SetOut(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4061 | if (cls->NeedsAccessCheck()) { |
| 4062 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4063 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4064 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4065 | return; |
| 4066 | } |
| 4067 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4068 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4069 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4070 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4071 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4072 | bool generate_null_check = false; |
| 4073 | switch (cls->GetLoadKind()) { |
| 4074 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4075 | DCHECK(!cls->CanCallRuntime()); |
| 4076 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4077 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4078 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4079 | GenerateGcRootFieldLoad(cls, |
| 4080 | out_loc, |
| 4081 | current_method, |
| 4082 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 4083 | /*fixup_label*/ nullptr, |
| 4084 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4085 | break; |
| 4086 | } |
| 4087 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4088 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4089 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4090 | cls->GetTypeIndex())); |
| 4091 | break; |
| 4092 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4093 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4094 | // Add ADRP with its PC-relative type patch. |
| 4095 | const DexFile& dex_file = cls->GetDexFile(); |
| 4096 | uint32_t type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4097 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4098 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4099 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4100 | vixl::aarch64::Label* add_label = |
| 4101 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4102 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4103 | break; |
| 4104 | } |
| 4105 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4106 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4107 | DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress())); |
| 4108 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress())); |
| 4109 | break; |
| 4110 | } |
| 4111 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 4112 | DCHECK_NE(cls->GetAddress(), 0u); |
| 4113 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4114 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4115 | // multiple types, simply split the dex cache address to a 16KiB aligned base |
| 4116 | // loaded from a literal and the remaining offset embedded in the load. |
| 4117 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 4118 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 4119 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4120 | uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4121 | uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4122 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4123 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4124 | GenerateGcRootFieldLoad(cls, |
| 4125 | out_loc, |
| 4126 | out.X(), |
| 4127 | offset, |
| 4128 | /*fixup_label*/ nullptr, |
| 4129 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4130 | generate_null_check = !cls->IsInDexCache(); |
| 4131 | break; |
| 4132 | } |
| 4133 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 4134 | // Add ADRP with its PC-relative DexCache access patch. |
| 4135 | const DexFile& dex_file = cls->GetDexFile(); |
| 4136 | uint32_t element_offset = cls->GetDexCacheElementOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4137 | vixl::aarch64::Label* adrp_label = |
| 4138 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4139 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4140 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4141 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4142 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4143 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4144 | GenerateGcRootFieldLoad(cls, |
| 4145 | out_loc, |
| 4146 | out.X(), |
| 4147 | /* offset placeholder */ 0, |
| 4148 | ldr_label, |
| 4149 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4150 | generate_null_check = !cls->IsInDexCache(); |
| 4151 | break; |
| 4152 | } |
| 4153 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 4154 | MemberOffset resolved_types_offset = |
| 4155 | ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 4156 | // /* GcRoot<mirror::Class>[] */ out = |
| 4157 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 4158 | Register current_method = InputRegisterAt(cls, 0); |
| 4159 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 4160 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4161 | GenerateGcRootFieldLoad(cls, |
| 4162 | out_loc, |
| 4163 | out.X(), |
| 4164 | CodeGenerator::GetCacheOffset(cls->GetTypeIndex()), |
| 4165 | /*fixup_label*/ nullptr, |
| 4166 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4167 | generate_null_check = !cls->IsInDexCache(); |
| 4168 | break; |
| 4169 | } |
| 4170 | } |
| 4171 | |
| 4172 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 4173 | DCHECK(cls->CanCallRuntime()); |
| 4174 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 4175 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4176 | codegen_->AddSlowPath(slow_path); |
| 4177 | if (generate_null_check) { |
| 4178 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4179 | } |
| 4180 | if (cls->MustGenerateClinitCheck()) { |
| 4181 | GenerateClassInitializationCheck(slow_path, out); |
| 4182 | } else { |
| 4183 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4184 | } |
| 4185 | } |
| 4186 | } |
| 4187 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4188 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4189 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4190 | } |
| 4191 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4192 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4193 | LocationSummary* locations = |
| 4194 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4195 | locations->SetOut(Location::RequiresRegister()); |
| 4196 | } |
| 4197 | |
| 4198 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4199 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4200 | } |
| 4201 | |
| 4202 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4203 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4204 | } |
| 4205 | |
| 4206 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4207 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4208 | } |
| 4209 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4210 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4211 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4212 | switch (desired_string_load_kind) { |
| 4213 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4214 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4215 | break; |
| 4216 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4217 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4218 | break; |
| 4219 | case HLoadString::LoadKind::kBootImageAddress: |
| 4220 | break; |
| 4221 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4222 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4223 | break; |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4224 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4225 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4226 | break; |
| 4227 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4228 | break; |
| 4229 | } |
| 4230 | return desired_string_load_kind; |
| 4231 | } |
| 4232 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4233 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4234 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4235 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 4236 | ? LocationSummary::kCallOnMainOnly |
| 4237 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4238 | : LocationSummary::kNoCall; |
| 4239 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4240 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 4241 | locations->SetInAt(0, Location::RequiresRegister()); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4242 | InvokeRuntimeCallingConvention calling_convention; |
| 4243 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4244 | } else { |
| 4245 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4246 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4250 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4251 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4252 | switch (load->GetLoadKind()) { |
| 4253 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4254 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4255 | load->GetStringIndex())); |
| 4256 | return; // No dex cache slow path. |
| 4257 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4258 | // Add ADRP with its PC-relative String patch. |
| 4259 | const DexFile& dex_file = load->GetDexFile(); |
| 4260 | uint32_t string_index = load->GetStringIndex(); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4261 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4262 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4263 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4264 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4265 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4266 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4267 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4268 | return; // No dex cache slow path. |
| 4269 | } |
| 4270 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4271 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4272 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4273 | return; // No dex cache slow path. |
| 4274 | } |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 4275 | case HLoadString::LoadKind::kBssEntry: { |
| 4276 | // Add ADRP with its PC-relative String .bss entry patch. |
| 4277 | const DexFile& dex_file = load->GetDexFile(); |
| 4278 | uint32_t string_index = load->GetStringIndex(); |
| 4279 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 4280 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 4281 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 4282 | // Add LDR with its PC-relative String patch. |
| 4283 | vixl::aarch64::Label* ldr_label = |
| 4284 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 4285 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4286 | GenerateGcRootFieldLoad(load, |
| 4287 | load->GetLocations()->Out(), |
| 4288 | out.X(), |
| 4289 | /* placeholder */ 0u, |
| 4290 | ldr_label); |
| 4291 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 4292 | codegen_->AddSlowPath(slow_path); |
| 4293 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 4294 | __ Bind(slow_path->GetExitLabel()); |
| 4295 | return; |
| 4296 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4297 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4298 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4299 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4300 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4301 | // 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] | 4302 | InvokeRuntimeCallingConvention calling_convention; |
| 4303 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex()); |
| 4304 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 4305 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4306 | } |
| 4307 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4308 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4309 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4310 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4311 | } |
| 4312 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4313 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4314 | // Will be generated at use site. |
| 4315 | } |
| 4316 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4317 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4318 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4319 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4320 | InvokeRuntimeCallingConvention calling_convention; |
| 4321 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4322 | } |
| 4323 | |
| 4324 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4325 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject: kQuickUnlockObject, |
| 4326 | instruction, |
| 4327 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4328 | if (instruction->IsEnter()) { |
| 4329 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4330 | } else { |
| 4331 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4332 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4333 | } |
| 4334 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4335 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4336 | LocationSummary* locations = |
| 4337 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4338 | switch (mul->GetResultType()) { |
| 4339 | case Primitive::kPrimInt: |
| 4340 | case Primitive::kPrimLong: |
| 4341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4342 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4343 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4344 | break; |
| 4345 | |
| 4346 | case Primitive::kPrimFloat: |
| 4347 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4349 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4350 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4351 | break; |
| 4352 | |
| 4353 | default: |
| 4354 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4359 | switch (mul->GetResultType()) { |
| 4360 | case Primitive::kPrimInt: |
| 4361 | case Primitive::kPrimLong: |
| 4362 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4363 | break; |
| 4364 | |
| 4365 | case Primitive::kPrimFloat: |
| 4366 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4367 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4368 | break; |
| 4369 | |
| 4370 | default: |
| 4371 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4372 | } |
| 4373 | } |
| 4374 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4375 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4376 | LocationSummary* locations = |
| 4377 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4378 | switch (neg->GetResultType()) { |
| 4379 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4380 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4381 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4383 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4384 | |
| 4385 | case Primitive::kPrimFloat: |
| 4386 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4387 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4388 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4389 | break; |
| 4390 | |
| 4391 | default: |
| 4392 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4397 | switch (neg->GetResultType()) { |
| 4398 | case Primitive::kPrimInt: |
| 4399 | case Primitive::kPrimLong: |
| 4400 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4401 | break; |
| 4402 | |
| 4403 | case Primitive::kPrimFloat: |
| 4404 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4405 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4406 | break; |
| 4407 | |
| 4408 | default: |
| 4409 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4414 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4415 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4416 | InvokeRuntimeCallingConvention calling_convention; |
| 4417 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4418 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4419 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4420 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4424 | LocationSummary* locations = instruction->GetLocations(); |
| 4425 | InvokeRuntimeCallingConvention calling_convention; |
| 4426 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4427 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4428 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4429 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4430 | // of poisoning the reference. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4431 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4432 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4435 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4436 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4437 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4438 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4439 | if (instruction->IsStringAlloc()) { |
| 4440 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4441 | } else { |
| 4442 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4443 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4444 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4445 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4446 | } |
| 4447 | |
| 4448 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4449 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4450 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4451 | if (instruction->IsStringAlloc()) { |
| 4452 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4453 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4454 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4455 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4456 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4457 | __ Blr(lr); |
| 4458 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4459 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4460 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4461 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4462 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4463 | } |
| 4464 | |
| 4465 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4466 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4467 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4468 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4472 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4473 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4474 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4475 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4476 | break; |
| 4477 | |
| 4478 | default: |
| 4479 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4480 | } |
| 4481 | } |
| 4482 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4483 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4484 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4486 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4487 | } |
| 4488 | |
| 4489 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4490 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4493 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4494 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4495 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4496 | } |
| 4497 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4498 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4499 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4500 | return; |
| 4501 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4502 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4503 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4504 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4505 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4506 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4507 | } |
| 4508 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4509 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4510 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4511 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4512 | |
| 4513 | LocationSummary* locations = instruction->GetLocations(); |
| 4514 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4515 | |
| 4516 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4519 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4520 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4521 | } |
| 4522 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4523 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4524 | HandleBinaryOp(instruction); |
| 4525 | } |
| 4526 | |
| 4527 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4528 | HandleBinaryOp(instruction); |
| 4529 | } |
| 4530 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4531 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4532 | LOG(FATAL) << "Unreachable"; |
| 4533 | } |
| 4534 | |
| 4535 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4536 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4537 | } |
| 4538 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4539 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4540 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4541 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4542 | if (location.IsStackSlot()) { |
| 4543 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4544 | } else if (location.IsDoubleStackSlot()) { |
| 4545 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4546 | } |
| 4547 | locations->SetOut(location); |
| 4548 | } |
| 4549 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4550 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4551 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4552 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4556 | LocationSummary* locations = |
| 4557 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4558 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4562 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4563 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4567 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4568 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4569 | locations->SetInAt(i, Location::Any()); |
| 4570 | } |
| 4571 | locations->SetOut(Location::Any()); |
| 4572 | } |
| 4573 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4574 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4575 | LOG(FATAL) << "Unreachable"; |
| 4576 | } |
| 4577 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4578 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4579 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4580 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4581 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 4582 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4583 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4584 | |
| 4585 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4586 | case Primitive::kPrimInt: |
| 4587 | case Primitive::kPrimLong: |
| 4588 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4589 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4590 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4591 | break; |
| 4592 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4593 | case Primitive::kPrimFloat: |
| 4594 | case Primitive::kPrimDouble: { |
| 4595 | InvokeRuntimeCallingConvention calling_convention; |
| 4596 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4597 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4598 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4599 | |
| 4600 | break; |
| 4601 | } |
| 4602 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4603 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4604 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4609 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4610 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4611 | switch (type) { |
| 4612 | case Primitive::kPrimInt: |
| 4613 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4614 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4615 | break; |
| 4616 | } |
| 4617 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4618 | case Primitive::kPrimFloat: |
| 4619 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4620 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 4621 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4622 | if (type == Primitive::kPrimFloat) { |
| 4623 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4624 | } else { |
| 4625 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4626 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4627 | break; |
| 4628 | } |
| 4629 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4630 | default: |
| 4631 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4632 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4633 | } |
| 4634 | } |
| 4635 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4636 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4637 | memory_barrier->SetLocations(nullptr); |
| 4638 | } |
| 4639 | |
| 4640 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4641 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4644 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4645 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4646 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4647 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4648 | } |
| 4649 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4650 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4651 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4655 | instruction->SetLocations(nullptr); |
| 4656 | } |
| 4657 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4658 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4659 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4660 | } |
| 4661 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4662 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4663 | HandleBinaryOp(ror); |
| 4664 | } |
| 4665 | |
| 4666 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4667 | HandleBinaryOp(ror); |
| 4668 | } |
| 4669 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4670 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4671 | HandleShift(shl); |
| 4672 | } |
| 4673 | |
| 4674 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4675 | HandleShift(shl); |
| 4676 | } |
| 4677 | |
| 4678 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4679 | HandleShift(shr); |
| 4680 | } |
| 4681 | |
| 4682 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4683 | HandleShift(shr); |
| 4684 | } |
| 4685 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4686 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4687 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4691 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4692 | } |
| 4693 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4694 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4695 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4699 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4703 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4704 | } |
| 4705 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4706 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4707 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4708 | } |
| 4709 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4710 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4711 | HUnresolvedInstanceFieldGet* instruction) { |
| 4712 | FieldAccessCallingConventionARM64 calling_convention; |
| 4713 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4714 | instruction, instruction->GetFieldType(), calling_convention); |
| 4715 | } |
| 4716 | |
| 4717 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4718 | HUnresolvedInstanceFieldGet* instruction) { |
| 4719 | FieldAccessCallingConventionARM64 calling_convention; |
| 4720 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4721 | instruction->GetFieldType(), |
| 4722 | instruction->GetFieldIndex(), |
| 4723 | instruction->GetDexPc(), |
| 4724 | calling_convention); |
| 4725 | } |
| 4726 | |
| 4727 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4728 | HUnresolvedInstanceFieldSet* instruction) { |
| 4729 | FieldAccessCallingConventionARM64 calling_convention; |
| 4730 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4731 | instruction, instruction->GetFieldType(), calling_convention); |
| 4732 | } |
| 4733 | |
| 4734 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4735 | HUnresolvedInstanceFieldSet* instruction) { |
| 4736 | FieldAccessCallingConventionARM64 calling_convention; |
| 4737 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4738 | instruction->GetFieldType(), |
| 4739 | instruction->GetFieldIndex(), |
| 4740 | instruction->GetDexPc(), |
| 4741 | calling_convention); |
| 4742 | } |
| 4743 | |
| 4744 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4745 | HUnresolvedStaticFieldGet* instruction) { |
| 4746 | FieldAccessCallingConventionARM64 calling_convention; |
| 4747 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4748 | instruction, instruction->GetFieldType(), calling_convention); |
| 4749 | } |
| 4750 | |
| 4751 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4752 | HUnresolvedStaticFieldGet* instruction) { |
| 4753 | FieldAccessCallingConventionARM64 calling_convention; |
| 4754 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4755 | instruction->GetFieldType(), |
| 4756 | instruction->GetFieldIndex(), |
| 4757 | instruction->GetDexPc(), |
| 4758 | calling_convention); |
| 4759 | } |
| 4760 | |
| 4761 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4762 | HUnresolvedStaticFieldSet* instruction) { |
| 4763 | FieldAccessCallingConventionARM64 calling_convention; |
| 4764 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4765 | instruction, instruction->GetFieldType(), calling_convention); |
| 4766 | } |
| 4767 | |
| 4768 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4769 | HUnresolvedStaticFieldSet* instruction) { |
| 4770 | FieldAccessCallingConventionARM64 calling_convention; |
| 4771 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4772 | instruction->GetFieldType(), |
| 4773 | instruction->GetFieldIndex(), |
| 4774 | instruction->GetDexPc(), |
| 4775 | calling_convention); |
| 4776 | } |
| 4777 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4778 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4779 | LocationSummary* locations = |
| 4780 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4781 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4785 | HBasicBlock* block = instruction->GetBlock(); |
| 4786 | if (block->GetLoopInformation() != nullptr) { |
| 4787 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4788 | // The back edge will generate the suspend check. |
| 4789 | return; |
| 4790 | } |
| 4791 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4792 | // The goto will generate the suspend check. |
| 4793 | return; |
| 4794 | } |
| 4795 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4796 | } |
| 4797 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4798 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 4799 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4800 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4801 | InvokeRuntimeCallingConvention calling_convention; |
| 4802 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4803 | } |
| 4804 | |
| 4805 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4806 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4807 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4811 | LocationSummary* locations = |
| 4812 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 4813 | Primitive::Type input_type = conversion->GetInputType(); |
| 4814 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 4815 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4816 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4817 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4818 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4819 | } |
| 4820 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4821 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4822 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4823 | } else { |
| 4824 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4825 | } |
| 4826 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4827 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4828 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4829 | } else { |
| 4830 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4835 | Primitive::Type result_type = conversion->GetResultType(); |
| 4836 | Primitive::Type input_type = conversion->GetInputType(); |
| 4837 | |
| 4838 | DCHECK_NE(input_type, result_type); |
| 4839 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4840 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4841 | int result_size = Primitive::ComponentSize(result_type); |
| 4842 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4843 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4844 | Register output = OutputRegister(conversion); |
| 4845 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4846 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 4847 | // 'int' values are used directly as W registers, discarding the top |
| 4848 | // bits, so we don't need to sign-extend and can just perform a move. |
| 4849 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 4850 | // top 32 bits of the target register. We theoretically could leave those |
| 4851 | // bits unchanged, but we would have to make sure that no code uses a |
| 4852 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 4853 | // zero. |
| 4854 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4855 | } else if (result_type == Primitive::kPrimChar || |
| 4856 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 4857 | __ Ubfx(output, |
| 4858 | output.IsX() ? source.X() : source.W(), |
| 4859 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4860 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4861 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4862 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4863 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4864 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4865 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4866 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4867 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4868 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4869 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4870 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 4871 | } else { |
| 4872 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4873 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4874 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4875 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4876 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4877 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 4878 | HandleShift(ushr); |
| 4879 | } |
| 4880 | |
| 4881 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 4882 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 4886 | HandleBinaryOp(instruction); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 4890 | HandleBinaryOp(instruction); |
| 4891 | } |
| 4892 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4893 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4894 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4895 | LOG(FATAL) << "Unreachable"; |
| 4896 | } |
| 4897 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4898 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4899 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4900 | LOG(FATAL) << "Unreachable"; |
| 4901 | } |
| 4902 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4903 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4904 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4905 | LocationSummary* locations = |
| 4906 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4908 | } |
| 4909 | |
| 4910 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4911 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4912 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4913 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 4914 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4915 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4916 | // 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] | 4917 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4918 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 4919 | // make sure we don't emit it if the target may run out of range. |
| 4920 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 4921 | // ranges and emit the tables only as required. |
| 4922 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4923 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4924 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4925 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 4926 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 4927 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4928 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4929 | Register temp = temps.AcquireW(); |
| 4930 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 4931 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4932 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4933 | // Jump to successors[0] if value == lower_bound. |
| 4934 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 4935 | int32_t last_index = 0; |
| 4936 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4937 | __ Subs(temp, temp, Operand(2)); |
| 4938 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4939 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4940 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4941 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4942 | } |
| 4943 | if (num_entries - last_index == 2) { |
| 4944 | // The last missing case_value. |
| 4945 | __ Cmp(temp, Operand(1)); |
| 4946 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | // And the default for any other value. |
| 4950 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4951 | __ B(codegen_->GetLabelOf(default_block)); |
| 4952 | } |
| 4953 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 4954 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4955 | |
| 4956 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4957 | |
| 4958 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 4959 | // registers, we are free to block one. |
| 4960 | Register temp_w = temps.AcquireW(); |
| 4961 | Register index; |
| 4962 | // Remove the bias. |
| 4963 | if (lower_bound != 0) { |
| 4964 | index = temp_w; |
| 4965 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 4966 | } else { |
| 4967 | index = value_reg; |
| 4968 | } |
| 4969 | |
| 4970 | // Jump to default block if index is out of the range. |
| 4971 | __ Cmp(index, Operand(num_entries)); |
| 4972 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 4973 | |
| 4974 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 4975 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 4976 | // register pressure. |
| 4977 | Register table_base = temps.AcquireX(); |
| 4978 | // Load jump offset from the table. |
| 4979 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 4980 | Register jump_offset = temp_w; |
| 4981 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 4982 | |
| 4983 | // Jump to target block by branching to table_base(pc related) + offset. |
| 4984 | Register target_address = table_base; |
| 4985 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 4986 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4987 | } |
| 4988 | } |
| 4989 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4990 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 4991 | Location out, |
| 4992 | uint32_t offset, |
| 4993 | Location maybe_temp) { |
| 4994 | Primitive::Type type = Primitive::kPrimNot; |
| 4995 | Register out_reg = RegisterFrom(out, type); |
| 4996 | if (kEmitCompilerReadBarrier) { |
| 4997 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4998 | if (kUseBakerReadBarrier) { |
| 4999 | // Load with fast path based Baker's read barrier. |
| 5000 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5001 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5002 | out, |
| 5003 | out_reg, |
| 5004 | offset, |
| 5005 | temp_reg, |
| 5006 | /* needs_null_check */ false, |
| 5007 | /* use_load_acquire */ false); |
| 5008 | } else { |
| 5009 | // Load with slow path based read barrier. |
| 5010 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5011 | // in the following move operation, as we will need it for the |
| 5012 | // read barrier below. |
| 5013 | __ Mov(temp_reg, out_reg); |
| 5014 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5015 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5016 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5017 | } |
| 5018 | } else { |
| 5019 | // Plain load with no read barrier. |
| 5020 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5021 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5022 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 5027 | Location out, |
| 5028 | Location obj, |
| 5029 | uint32_t offset, |
| 5030 | Location maybe_temp) { |
| 5031 | Primitive::Type type = Primitive::kPrimNot; |
| 5032 | Register out_reg = RegisterFrom(out, type); |
| 5033 | Register obj_reg = RegisterFrom(obj, type); |
| 5034 | if (kEmitCompilerReadBarrier) { |
| 5035 | if (kUseBakerReadBarrier) { |
| 5036 | // Load with fast path based Baker's read barrier. |
| 5037 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5038 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5039 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5040 | out, |
| 5041 | obj_reg, |
| 5042 | offset, |
| 5043 | temp_reg, |
| 5044 | /* needs_null_check */ false, |
| 5045 | /* use_load_acquire */ false); |
| 5046 | } else { |
| 5047 | // Load with slow path based read barrier. |
| 5048 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5049 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5050 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5051 | } |
| 5052 | } else { |
| 5053 | // Plain load with no read barrier. |
| 5054 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5055 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5056 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5061 | Location root, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5062 | Register obj, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5063 | uint32_t offset, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5064 | vixl::aarch64::Label* fixup_label, |
| 5065 | bool requires_read_barrier) { |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 5066 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5067 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5068 | if (requires_read_barrier) { |
| 5069 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5070 | if (kUseBakerReadBarrier) { |
| 5071 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5072 | // Baker's read barrier are used: |
| 5073 | // |
| 5074 | // root = obj.field; |
| 5075 | // if (Thread::Current()->GetIsGcMarking()) { |
| 5076 | // root = ReadBarrier::Mark(root) |
| 5077 | // } |
| 5078 | |
| 5079 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5080 | if (fixup_label == nullptr) { |
| 5081 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5082 | } else { |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 5083 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5084 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5085 | static_assert( |
| 5086 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5087 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5088 | "have different sizes."); |
| 5089 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5090 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5091 | "have different sizes."); |
| 5092 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5093 | // Slow path marking the GC root `root`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5094 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5095 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5096 | codegen_->AddSlowPath(slow_path); |
| 5097 | |
| 5098 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5099 | UseScratchRegisterScope temps(masm); |
| 5100 | Register temp = temps.AcquireW(); |
| 5101 | // temp = Thread::Current()->GetIsGcMarking() |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5102 | __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5103 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5104 | __ Bind(slow_path->GetExitLabel()); |
| 5105 | } else { |
| 5106 | // GC root loaded through a slow path for read barriers other |
| 5107 | // than Baker's. |
| 5108 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5109 | if (fixup_label == nullptr) { |
| 5110 | __ Add(root_reg.X(), obj.X(), offset); |
| 5111 | } else { |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 5112 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5113 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5114 | // /* mirror::Object* */ root = root->Read() |
| 5115 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5116 | } |
| 5117 | } else { |
| 5118 | // Plain GC root load with no read barrier. |
| 5119 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5120 | if (fixup_label == nullptr) { |
| 5121 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5122 | } else { |
Vladimir Marko | 63dccbb | 2016-09-21 13:51:10 +0100 | [diff] [blame] | 5123 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5124 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5125 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5126 | // do not have to unpoison `root_reg` here. |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5131 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5132 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5133 | uint32_t offset, |
| 5134 | Register temp, |
| 5135 | bool needs_null_check, |
| 5136 | bool use_load_acquire) { |
| 5137 | DCHECK(kEmitCompilerReadBarrier); |
| 5138 | DCHECK(kUseBakerReadBarrier); |
| 5139 | |
| 5140 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5141 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5142 | size_t no_scale_factor = 0U; |
| 5143 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5144 | ref, |
| 5145 | obj, |
| 5146 | offset, |
| 5147 | no_index, |
| 5148 | no_scale_factor, |
| 5149 | temp, |
| 5150 | needs_null_check, |
| 5151 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5155 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5156 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5157 | uint32_t data_offset, |
| 5158 | Location index, |
| 5159 | Register temp, |
| 5160 | bool needs_null_check) { |
| 5161 | DCHECK(kEmitCompilerReadBarrier); |
| 5162 | DCHECK(kUseBakerReadBarrier); |
| 5163 | |
| 5164 | // Array cells are never volatile variables, therefore array loads |
| 5165 | // never use Load-Acquire instructions on ARM64. |
| 5166 | const bool use_load_acquire = false; |
| 5167 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5168 | static_assert( |
| 5169 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5170 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5171 | // /* HeapReference<Object> */ ref = |
| 5172 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5173 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5174 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5175 | ref, |
| 5176 | obj, |
| 5177 | data_offset, |
| 5178 | index, |
| 5179 | scale_factor, |
| 5180 | temp, |
| 5181 | needs_null_check, |
| 5182 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5186 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5187 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5188 | uint32_t offset, |
| 5189 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5190 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5191 | Register temp, |
| 5192 | bool needs_null_check, |
| 5193 | bool use_load_acquire) { |
| 5194 | DCHECK(kEmitCompilerReadBarrier); |
| 5195 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5196 | // If we are emitting an array load, we should not be using a |
| 5197 | // Load Acquire instruction. In other words: |
| 5198 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5199 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5200 | |
| 5201 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5202 | UseScratchRegisterScope temps(masm); |
| 5203 | |
| 5204 | // In slow path based read barriers, the read barrier call is |
| 5205 | // inserted after the original load. However, in fast path based |
| 5206 | // Baker's read barriers, we need to perform the load of |
| 5207 | // mirror::Object::monitor_ *before* the original reference load. |
| 5208 | // This load-load ordering is required by the read barrier. |
| 5209 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5210 | // |
| 5211 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5212 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5213 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5214 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 5215 | // if (is_gray) { |
| 5216 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5217 | // } |
| 5218 | // |
| 5219 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5220 | // slightly more complex as it performs additional checks that we do |
| 5221 | // not do here for performance reasons. |
| 5222 | |
| 5223 | Primitive::Type type = Primitive::kPrimNot; |
| 5224 | Register ref_reg = RegisterFrom(ref, type); |
| 5225 | DCHECK(obj.IsW()); |
| 5226 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5227 | |
| 5228 | // /* int32_t */ monitor = obj->monitor_ |
| 5229 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5230 | if (needs_null_check) { |
| 5231 | MaybeRecordImplicitNullCheck(instruction); |
| 5232 | } |
| 5233 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5234 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5235 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5236 | |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5237 | // Introduce a dependency on the lock_word including rb_state, |
| 5238 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5239 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5240 | // `obj` is unchanged by this operation, but its value now depends |
| 5241 | // on `temp`. |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5242 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5243 | |
| 5244 | // The actual reference load. |
| 5245 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5246 | // Load types involving an "index". |
| 5247 | if (use_load_acquire) { |
| 5248 | // UnsafeGetObjectVolatile intrinsic case. |
| 5249 | // Register `index` is not an index in an object array, but an |
| 5250 | // offset to an object reference field within object `obj`. |
| 5251 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5252 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5253 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5254 | << instruction->AsInvoke()->GetIntrinsic(); |
| 5255 | DCHECK_EQ(offset, 0U); |
| 5256 | DCHECK_EQ(scale_factor, 0U); |
| 5257 | DCHECK_EQ(needs_null_check, 0U); |
| 5258 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5259 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5260 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5261 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5262 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5263 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5264 | if (index.IsConstant()) { |
| 5265 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5266 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5267 | } else { |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5268 | Register temp2 = temps.AcquireW(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5269 | __ Add(temp2, obj, offset); |
| 5270 | Load(type, ref_reg, HeapOperand(temp2, XRegisterFrom(index), LSL, scale_factor)); |
| 5271 | temps.Release(temp2); |
| 5272 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5273 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5274 | } else { |
| 5275 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5276 | MemOperand field = HeapOperand(obj, offset); |
| 5277 | if (use_load_acquire) { |
| 5278 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5279 | } else { |
| 5280 | Load(type, ref_reg, field); |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5285 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5286 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5287 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5288 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5289 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5290 | AddSlowPath(slow_path); |
| 5291 | |
| 5292 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 5293 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5294 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 5295 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 5296 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 5297 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 5298 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5299 | __ Bind(slow_path->GetExitLabel()); |
| 5300 | } |
| 5301 | |
| 5302 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5303 | Location out, |
| 5304 | Location ref, |
| 5305 | Location obj, |
| 5306 | uint32_t offset, |
| 5307 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5308 | DCHECK(kEmitCompilerReadBarrier); |
| 5309 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5310 | // Insert a slow path based read barrier *after* the reference load. |
| 5311 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5312 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5313 | // reference will be carried out by the runtime within the slow |
| 5314 | // path. |
| 5315 | // |
| 5316 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5317 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5318 | // not used by the artReadBarrierSlow entry point. |
| 5319 | // |
| 5320 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5321 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5322 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5323 | AddSlowPath(slow_path); |
| 5324 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5325 | __ B(slow_path->GetEntryLabel()); |
| 5326 | __ Bind(slow_path->GetExitLabel()); |
| 5327 | } |
| 5328 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5329 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5330 | Location out, |
| 5331 | Location ref, |
| 5332 | Location obj, |
| 5333 | uint32_t offset, |
| 5334 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5335 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5336 | // Baker's read barriers shall be handled by the fast path |
| 5337 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5338 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5339 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5340 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5341 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5342 | } else if (kPoisonHeapReferences) { |
| 5343 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5344 | } |
| 5345 | } |
| 5346 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5347 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5348 | Location out, |
| 5349 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5350 | DCHECK(kEmitCompilerReadBarrier); |
| 5351 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5352 | // Insert a slow path based read barrier *after* the GC root load. |
| 5353 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5354 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5355 | // not need to do anything special for this here. |
| 5356 | SlowPathCodeARM64* slow_path = |
| 5357 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5358 | AddSlowPath(slow_path); |
| 5359 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5360 | __ B(slow_path->GetEntryLabel()); |
| 5361 | __ Bind(slow_path->GetExitLabel()); |
| 5362 | } |
| 5363 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5364 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5365 | LocationSummary* locations = |
| 5366 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5367 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5368 | locations->SetOut(Location::RequiresRegister()); |
| 5369 | } |
| 5370 | |
| 5371 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5372 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5373 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5374 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5375 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5376 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5377 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5378 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5379 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5380 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5381 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5382 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5383 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5384 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5385 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | |
| 5389 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5390 | #undef __ |
| 5391 | #undef QUICK_ENTRY_POINT |
| 5392 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5393 | } // namespace arm64 |
| 5394 | } // namespace art |