Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 19 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 30 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 31 | #include "thread.h" |
| 32 | #include "utils/arm64/assembler_arm64.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/stack_checks.h" |
| 35 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 36 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 37 | |
| 38 | #ifdef __ |
| 39 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 40 | #endif |
| 41 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 42 | namespace art { |
| 43 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | namespace arm64 { |
| 48 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 49 | using helpers::ARM64EncodableConstantOrRegister; |
| 50 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 51 | using helpers::CPURegisterFrom; |
| 52 | using helpers::DRegisterFrom; |
| 53 | using helpers::FPRegisterFrom; |
| 54 | using helpers::HeapOperand; |
| 55 | using helpers::HeapOperandFrom; |
| 56 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 57 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 58 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 59 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 61 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 62 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 63 | using helpers::LocationFrom; |
| 64 | using helpers::OperandFromMemOperand; |
| 65 | using helpers::OutputCPURegister; |
| 66 | using helpers::OutputFPRegister; |
| 67 | using helpers::OutputRegister; |
| 68 | using helpers::RegisterFrom; |
| 69 | using helpers::StackOperandFrom; |
| 70 | using helpers::VIXLRegCodeFromART; |
| 71 | using helpers::WRegisterFrom; |
| 72 | using helpers::XRegisterFrom; |
| 73 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 74 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 75 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 76 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 77 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 78 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 79 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 80 | inline Condition ARM64Condition(IfCondition cond) { |
| 81 | switch (cond) { |
| 82 | case kCondEQ: return eq; |
| 83 | case kCondNE: return ne; |
| 84 | case kCondLT: return lt; |
| 85 | case kCondLE: return le; |
| 86 | case kCondGT: return gt; |
| 87 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 88 | case kCondB: return lo; |
| 89 | case kCondBE: return ls; |
| 90 | case kCondA: return hi; |
| 91 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 92 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 93 | LOG(FATAL) << "Unreachable"; |
| 94 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 97 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 98 | // The ARM64 condition codes can express all the necessary branches, see the |
| 99 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 100 | // There is no dex instruction or HIR that would need the missing conditions |
| 101 | // "equal or unordered" or "not equal". |
| 102 | switch (cond) { |
| 103 | case kCondEQ: return eq; |
| 104 | case kCondNE: return ne /* unordered */; |
| 105 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 106 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 107 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 108 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 109 | default: |
| 110 | LOG(FATAL) << "UNREACHABLE"; |
| 111 | UNREACHABLE(); |
| 112 | } |
| 113 | } |
| 114 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 115 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 116 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 117 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 118 | // but we use the exact registers for clarity. |
| 119 | if (return_type == Primitive::kPrimFloat) { |
| 120 | return LocationFrom(s0); |
| 121 | } else if (return_type == Primitive::kPrimDouble) { |
| 122 | return LocationFrom(d0); |
| 123 | } else if (return_type == Primitive::kPrimLong) { |
| 124 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 125 | } else if (return_type == Primitive::kPrimVoid) { |
| 126 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 127 | } else { |
| 128 | return LocationFrom(w0); |
| 129 | } |
| 130 | } |
| 131 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 132 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 133 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 136 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 137 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 138 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 139 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 140 | // Calculate memory accessing operand for save/restore live registers. |
| 141 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 142 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 143 | int64_t spill_offset, |
| 144 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 145 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 146 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 147 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 148 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 149 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 150 | codegen->GetNumberOfFloatingPointRegisters())); |
| 151 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 152 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
| 153 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 154 | |
| 155 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 156 | UseScratchRegisterScope temps(masm); |
| 157 | |
| 158 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 159 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 160 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 161 | int64_t reg_size = kXRegSizeInBytes; |
| 162 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 163 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 164 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 165 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 166 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 167 | // to compute the base address(float point registers spill base address). |
| 168 | Register new_base = temps.AcquireSameSizeAs(base); |
| 169 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 170 | base = new_base; |
| 171 | spill_offset = -core_spill_size; |
| 172 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 173 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 174 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 175 | } |
| 176 | |
| 177 | if (is_save) { |
| 178 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 179 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 180 | } else { |
| 181 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 182 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 187 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 188 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 189 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 190 | // If the register holds an object, update the stack mask. |
| 191 | if (locations->RegisterContainsObject(i)) { |
| 192 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 193 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_core_stack_offsets_[i] = stack_offset; |
| 197 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | } |
| 199 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 200 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 201 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 202 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 203 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 204 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 205 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 206 | } |
| 207 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 208 | SaveRestoreLiveRegistersHelper(codegen, |
| 209 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 210 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 211 | } |
| 212 | |
| 213 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 214 | SaveRestoreLiveRegistersHelper(codegen, |
| 215 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 216 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 217 | } |
| 218 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 219 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 220 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 221 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 222 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 223 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 224 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 225 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 226 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 227 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 228 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 229 | // Live registers will be restored in the catch block if caught. |
| 230 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 231 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 232 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 233 | // move resolver. |
| 234 | InvokeRuntimeCallingConvention calling_convention; |
| 235 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 236 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 237 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 238 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 239 | ? kQuickThrowStringBounds |
| 240 | : kQuickThrowArrayBounds; |
| 241 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 242 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 243 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 246 | bool IsFatal() const OVERRIDE { return true; } |
| 247 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 248 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 249 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 252 | }; |
| 253 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 254 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 255 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 256 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 257 | |
| 258 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 259 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 260 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 261 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 262 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 265 | bool IsFatal() const OVERRIDE { return true; } |
| 266 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 267 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 268 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 270 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 271 | }; |
| 272 | |
| 273 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 274 | public: |
| 275 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 276 | HInstruction* at, |
| 277 | uint32_t dex_pc, |
| 278 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 279 | : SlowPathCodeARM64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 280 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 281 | } |
| 282 | |
| 283 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 284 | LocationSummary* locations = at_->GetLocations(); |
| 285 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 286 | |
| 287 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 288 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 289 | |
| 290 | InvokeRuntimeCallingConvention calling_convention; |
| 291 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 292 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 293 | : kQuickInitializeType; |
| 294 | arm64_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 295 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 296 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 297 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 298 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 299 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | |
| 301 | // Move the class to the desired location. |
| 302 | Location out = locations->Out(); |
| 303 | if (out.IsValid()) { |
| 304 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 305 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 306 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 309 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | __ B(GetExitLabel()); |
| 311 | } |
| 312 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 313 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 314 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 315 | private: |
| 316 | // The class this slow path will load. |
| 317 | HLoadClass* const cls_; |
| 318 | |
| 319 | // The instruction where this slow path is happening. |
| 320 | // (Might be the load class or an initialization check). |
| 321 | HInstruction* const at_; |
| 322 | |
| 323 | // The dex PC of `at_`. |
| 324 | const uint32_t dex_pc_; |
| 325 | |
| 326 | // Whether to initialize the class. |
| 327 | const bool do_clinit_; |
| 328 | |
| 329 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 330 | }; |
| 331 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 332 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 333 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 334 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 335 | : SlowPathCodeARM64(instruction), |
| 336 | temp_(temp), |
| 337 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 338 | |
| 339 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 340 | LocationSummary* locations = instruction_->GetLocations(); |
| 341 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 342 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 343 | |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 344 | // temp_ is a scratch register. Make sure it's not used for saving/restoring registers. |
| 345 | UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler()); |
| 346 | temps.Exclude(temp_); |
| 347 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 348 | __ Bind(GetEntryLabel()); |
| 349 | SaveLiveRegisters(codegen, locations); |
| 350 | |
| 351 | InvokeRuntimeCallingConvention calling_convention; |
| 352 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 353 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
| 354 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 355 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 356 | Primitive::Type type = instruction_->GetType(); |
| 357 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 358 | |
| 359 | RestoreLiveRegisters(codegen, locations); |
| 360 | |
| 361 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 362 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 363 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 364 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 365 | } else { |
| 366 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 367 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 368 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 369 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 370 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 371 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 372 | { |
| 373 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 374 | __ Bind(strp_label); |
| 375 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 376 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | __ B(GetExitLabel()); |
| 380 | } |
| 381 | |
| 382 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 383 | |
| 384 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 385 | const Register temp_; |
| 386 | vixl::aarch64::Label* adrp_label_; |
| 387 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 388 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 389 | }; |
| 390 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 391 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 392 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 394 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 395 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 396 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 397 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 398 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 399 | // Live registers will be restored in the catch block if caught. |
| 400 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 401 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 402 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 403 | instruction_, |
| 404 | instruction_->GetDexPc(), |
| 405 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 406 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 409 | bool IsFatal() const OVERRIDE { return true; } |
| 410 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 411 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 412 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 413 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 414 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 415 | }; |
| 416 | |
| 417 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 418 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 419 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 420 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 421 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 422 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 423 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 425 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 426 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 427 | if (successor_ == nullptr) { |
| 428 | __ B(GetReturnLabel()); |
| 429 | } else { |
| 430 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 431 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 434 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 435 | DCHECK(successor_ == nullptr); |
| 436 | return &return_label_; |
| 437 | } |
| 438 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 439 | HBasicBlock* GetSuccessor() const { |
| 440 | return successor_; |
| 441 | } |
| 442 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 443 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 444 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 445 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 446 | // If not null, the block to branch to after the suspend check. |
| 447 | HBasicBlock* const successor_; |
| 448 | |
| 449 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 450 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 451 | |
| 452 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 453 | }; |
| 454 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 455 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 456 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 457 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 458 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 459 | |
| 460 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 461 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 462 | Location class_to_check = locations->InAt(1); |
| 463 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 464 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 465 | DCHECK(instruction_->IsCheckCast() |
| 466 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 467 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 468 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 469 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 470 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 471 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 472 | if (!is_fatal_) { |
| 473 | SaveLiveRegisters(codegen, locations); |
| 474 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 | |
| 476 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 477 | // move resolver. |
| 478 | InvokeRuntimeCallingConvention calling_convention; |
| 479 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 480 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 481 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 482 | |
| 483 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 484 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 485 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 486 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 487 | Primitive::Type ret_type = instruction_->GetType(); |
| 488 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 489 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 490 | } else { |
| 491 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 492 | arm64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 493 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 496 | if (!is_fatal_) { |
| 497 | RestoreLiveRegisters(codegen, locations); |
| 498 | __ B(GetExitLabel()); |
| 499 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 502 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 503 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 504 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 505 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 506 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 507 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 508 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 509 | }; |
| 510 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 511 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 512 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 513 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 514 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 515 | |
| 516 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 517 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 518 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 519 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 520 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 523 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 524 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 526 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 527 | }; |
| 528 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 529 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 530 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 531 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 532 | |
| 533 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 534 | LocationSummary* locations = instruction_->GetLocations(); |
| 535 | __ Bind(GetEntryLabel()); |
| 536 | SaveLiveRegisters(codegen, locations); |
| 537 | |
| 538 | InvokeRuntimeCallingConvention calling_convention; |
| 539 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 540 | parallel_move.AddMove( |
| 541 | locations->InAt(0), |
| 542 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 543 | Primitive::kPrimNot, |
| 544 | nullptr); |
| 545 | parallel_move.AddMove( |
| 546 | locations->InAt(1), |
| 547 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 548 | Primitive::kPrimInt, |
| 549 | nullptr); |
| 550 | parallel_move.AddMove( |
| 551 | locations->InAt(2), |
| 552 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 553 | Primitive::kPrimNot, |
| 554 | nullptr); |
| 555 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 556 | |
| 557 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 558 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 559 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 560 | RestoreLiveRegisters(codegen, locations); |
| 561 | __ B(GetExitLabel()); |
| 562 | } |
| 563 | |
| 564 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 565 | |
| 566 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 567 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 568 | }; |
| 569 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 570 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 571 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 572 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 573 | |
| 574 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 575 | // underlying code buffer and we have generated the jump table with right size. |
| 576 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 577 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 578 | |
| 579 | __ Bind(&table_start_); |
| 580 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 581 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 582 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 583 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 584 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 585 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 586 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 587 | Literal<int32_t> literal(jump_offset); |
| 588 | __ place(&literal); |
| 589 | } |
| 590 | } |
| 591 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 592 | // Slow path marking an object reference `ref` during a read |
| 593 | // barrier. The field `obj.field` in the object `obj` holding this |
| 594 | // reference does not get updated by this slow path after marking (see |
| 595 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 below for that). |
| 596 | // |
| 597 | // This means that after the execution of this slow path, `ref` will |
| 598 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 599 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 600 | // probably still be a from-space reference (unless it gets updated by |
| 601 | // another thread, or if another thread installed another object |
| 602 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 603 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 604 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 605 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location ref) |
| 606 | : SlowPathCodeARM64(instruction), ref_(ref) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 607 | DCHECK(kEmitCompilerReadBarrier); |
| 608 | } |
| 609 | |
| 610 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 611 | |
| 612 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 613 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 614 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 615 | DCHECK(ref_.IsRegister()) << ref_; |
| 616 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 617 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 618 | instruction_->IsStaticFieldGet() || |
| 619 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 620 | instruction_->IsArraySet() || |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 621 | instruction_->IsLoadClass() || |
| 622 | instruction_->IsLoadString() || |
| 623 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 624 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 625 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 626 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 627 | << "Unexpected instruction in read barrier marking slow path: " |
| 628 | << instruction_->DebugName(); |
| 629 | |
| 630 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 631 | // No need to save live registers; it's taken care of by the |
| 632 | // entrypoint. Also, there is no need to update the stack mask, |
| 633 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 634 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 635 | DCHECK_NE(ref_.reg(), LR); |
| 636 | DCHECK_NE(ref_.reg(), WSP); |
| 637 | DCHECK_NE(ref_.reg(), WZR); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 638 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 639 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 640 | DCHECK_NE(ref_.reg(), IP0); |
| 641 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 642 | // "Compact" slow path, saving two moves. |
| 643 | // |
| 644 | // Instead of using the standard runtime calling convention (input |
| 645 | // and output in W0): |
| 646 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 647 | // W0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 648 | // W0 <- ReadBarrierMark(W0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 649 | // ref <- W0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 650 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 651 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 652 | // of a dedicated entrypoint: |
| 653 | // |
| 654 | // rX <- ReadBarrierMarkRegX(rX) |
| 655 | // |
| 656 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 657 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 658 | // This runtime call does not require a stack map. |
| 659 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 660 | __ B(GetExitLabel()); |
| 661 | } |
| 662 | |
| 663 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 664 | // The location (register) of the marked object reference. |
| 665 | const Location ref_; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 666 | |
| 667 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 668 | }; |
| 669 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 670 | // Slow path marking an object reference `ref` during a read barrier, |
| 671 | // and if needed, atomically updating the field `obj.field` in the |
| 672 | // object `obj` holding this reference after marking (contrary to |
| 673 | // ReadBarrierMarkSlowPathARM64 above, which never tries to update |
| 674 | // `obj.field`). |
| 675 | // |
| 676 | // This means that after the execution of this slow path, both `ref` |
| 677 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 678 | // hold the same to-space reference (unless another thread installed |
| 679 | // another object reference (different from `ref`) in `obj.field`). |
| 680 | class ReadBarrierMarkAndUpdateFieldSlowPathARM64 : public SlowPathCodeARM64 { |
| 681 | public: |
| 682 | ReadBarrierMarkAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 683 | Location ref, |
| 684 | Register obj, |
| 685 | Location field_offset, |
| 686 | Register temp) |
| 687 | : SlowPathCodeARM64(instruction), |
| 688 | ref_(ref), |
| 689 | obj_(obj), |
| 690 | field_offset_(field_offset), |
| 691 | temp_(temp) { |
| 692 | DCHECK(kEmitCompilerReadBarrier); |
| 693 | } |
| 694 | |
| 695 | const char* GetDescription() const OVERRIDE { |
| 696 | return "ReadBarrierMarkAndUpdateFieldSlowPathARM64"; |
| 697 | } |
| 698 | |
| 699 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 700 | LocationSummary* locations = instruction_->GetLocations(); |
| 701 | Register ref_reg = WRegisterFrom(ref_); |
| 702 | DCHECK(locations->CanCall()); |
| 703 | DCHECK(ref_.IsRegister()) << ref_; |
| 704 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 705 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 706 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 707 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 708 | << instruction_->DebugName(); |
| 709 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 710 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 711 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 712 | |
| 713 | __ Bind(GetEntryLabel()); |
| 714 | |
| 715 | // Save the old reference. |
| 716 | // Note that we cannot use IP to save the old reference, as IP is |
| 717 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 718 | // need the old reference after the call to that entry point. |
| 719 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 720 | __ Mov(temp_.W(), ref_reg); |
| 721 | |
| 722 | // No need to save live registers; it's taken care of by the |
| 723 | // entrypoint. Also, there is no need to update the stack mask, |
| 724 | // as this runtime call will not trigger a garbage collection. |
| 725 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 726 | DCHECK_NE(ref_.reg(), LR); |
| 727 | DCHECK_NE(ref_.reg(), WSP); |
| 728 | DCHECK_NE(ref_.reg(), WZR); |
| 729 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 730 | // as a temporary, it cannot be the entry point's input/output. |
| 731 | DCHECK_NE(ref_.reg(), IP0); |
| 732 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 733 | // "Compact" slow path, saving two moves. |
| 734 | // |
| 735 | // Instead of using the standard runtime calling convention (input |
| 736 | // and output in W0): |
| 737 | // |
| 738 | // W0 <- ref |
| 739 | // W0 <- ReadBarrierMark(W0) |
| 740 | // ref <- W0 |
| 741 | // |
| 742 | // we just use rX (the register containing `ref`) as input and output |
| 743 | // of a dedicated entrypoint: |
| 744 | // |
| 745 | // rX <- ReadBarrierMarkRegX(rX) |
| 746 | // |
| 747 | int32_t entry_point_offset = |
| 748 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 749 | // This runtime call does not require a stack map. |
| 750 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 751 | |
| 752 | // If the new reference is different from the old reference, |
| 753 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 754 | // |
| 755 | // Note that this field could also hold a different object, if |
| 756 | // another thread had concurrently changed it. In that case, the |
| 757 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 758 | // (CAS) operation below would abort the CAS, leaving the field |
| 759 | // as-is. |
| 760 | vixl::aarch64::Label done; |
| 761 | __ Cmp(temp_.W(), ref_reg); |
| 762 | __ B(eq, &done); |
| 763 | |
| 764 | // Update the the holder's field atomically. This may fail if |
| 765 | // mutator updates before us, but it's OK. This is achieved |
| 766 | // using a strong compare-and-set (CAS) operation with relaxed |
| 767 | // memory synchronization ordering, where the expected value is |
| 768 | // the old reference and the desired value is the new reference. |
| 769 | |
| 770 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 771 | UseScratchRegisterScope temps(masm); |
| 772 | |
| 773 | // Convenience aliases. |
| 774 | Register base = obj_.W(); |
| 775 | Register offset = XRegisterFrom(field_offset_); |
| 776 | Register expected = temp_.W(); |
| 777 | Register value = ref_reg; |
| 778 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 779 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 780 | |
| 781 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 782 | |
| 783 | if (kPoisonHeapReferences) { |
| 784 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 785 | if (value.Is(expected)) { |
| 786 | // Do not poison `value`, as it is the same register as |
| 787 | // `expected`, which has just been poisoned. |
| 788 | } else { |
| 789 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | // do { |
| 794 | // tmp_value = [tmp_ptr] - expected; |
| 795 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 796 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 797 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 798 | __ Bind(&loop_head); |
| 799 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 800 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 801 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 802 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 803 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 804 | __ B(&exit_loop); |
| 805 | __ Bind(&comparison_failed); |
| 806 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 807 | __ Bind(&exit_loop); |
| 808 | |
| 809 | if (kPoisonHeapReferences) { |
| 810 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 811 | if (value.Is(expected)) { |
| 812 | // Do not unpoison `value`, as it is the same register as |
| 813 | // `expected`, which has just been unpoisoned. |
| 814 | } else { |
| 815 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | __ Bind(&done); |
| 820 | __ B(GetExitLabel()); |
| 821 | } |
| 822 | |
| 823 | private: |
| 824 | // The location (register) of the marked object reference. |
| 825 | const Location ref_; |
| 826 | // The register containing the object holding the marked object reference field. |
| 827 | const Register obj_; |
| 828 | // The location of the offset of the marked reference field within `obj_`. |
| 829 | Location field_offset_; |
| 830 | |
| 831 | const Register temp_; |
| 832 | |
| 833 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM64); |
| 834 | }; |
| 835 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 836 | // Slow path generating a read barrier for a heap reference. |
| 837 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 838 | public: |
| 839 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 840 | Location out, |
| 841 | Location ref, |
| 842 | Location obj, |
| 843 | uint32_t offset, |
| 844 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 845 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 846 | out_(out), |
| 847 | ref_(ref), |
| 848 | obj_(obj), |
| 849 | offset_(offset), |
| 850 | index_(index) { |
| 851 | DCHECK(kEmitCompilerReadBarrier); |
| 852 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 853 | // has been overwritten by (or after) the heap object reference load |
| 854 | // to be instrumented, e.g.: |
| 855 | // |
| 856 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 857 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 858 | // |
| 859 | // In that case, we have lost the information about the original |
| 860 | // object, and the emitted read barrier cannot work properly. |
| 861 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 862 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 863 | } |
| 864 | |
| 865 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 866 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 867 | LocationSummary* locations = instruction_->GetLocations(); |
| 868 | Primitive::Type type = Primitive::kPrimNot; |
| 869 | DCHECK(locations->CanCall()); |
| 870 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 871 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 872 | instruction_->IsStaticFieldGet() || |
| 873 | instruction_->IsArrayGet() || |
| 874 | instruction_->IsInstanceOf() || |
| 875 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 876 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 877 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 878 | << instruction_->DebugName(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 879 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 880 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 881 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 882 | |
| 883 | __ Bind(GetEntryLabel()); |
| 884 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 885 | SaveLiveRegisters(codegen, locations); |
| 886 | |
| 887 | // We may have to change the index's value, but as `index_` is a |
| 888 | // constant member (like other "inputs" of this slow path), |
| 889 | // introduce a copy of it, `index`. |
| 890 | Location index = index_; |
| 891 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 892 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 893 | if (instruction_->IsArrayGet()) { |
| 894 | // Compute the actual memory offset and store it in `index`. |
| 895 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 896 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 897 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 898 | // We are about to change the value of `index_reg` (see the |
| 899 | // calls to vixl::MacroAssembler::Lsl and |
| 900 | // vixl::MacroAssembler::Mov below), but it has |
| 901 | // not been saved by the previous call to |
| 902 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 903 | // callee-save register -- |
| 904 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 905 | // callee-save registers, as it has been designed with the |
| 906 | // assumption that callee-save registers are supposed to be |
| 907 | // handled by the called function. So, as a callee-save |
| 908 | // register, `index_reg` _would_ eventually be saved onto |
| 909 | // the stack, but it would be too late: we would have |
| 910 | // changed its value earlier. Therefore, we manually save |
| 911 | // it here into another freely available register, |
| 912 | // `free_reg`, chosen of course among the caller-save |
| 913 | // registers (as a callee-save `free_reg` register would |
| 914 | // exhibit the same problem). |
| 915 | // |
| 916 | // Note we could have requested a temporary register from |
| 917 | // the register allocator instead; but we prefer not to, as |
| 918 | // this is a slow path, and we know we can find a |
| 919 | // caller-save register that is available. |
| 920 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 921 | __ Mov(free_reg.W(), index_reg); |
| 922 | index_reg = free_reg; |
| 923 | index = LocationFrom(index_reg); |
| 924 | } else { |
| 925 | // The initial register stored in `index_` has already been |
| 926 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 927 | // (as it is not a callee-save register), so we can freely |
| 928 | // use it. |
| 929 | } |
| 930 | // Shifting the index value contained in `index_reg` by the scale |
| 931 | // factor (2) cannot overflow in practice, as the runtime is |
| 932 | // unable to allocate object arrays with a size larger than |
| 933 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 934 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 935 | static_assert( |
| 936 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 937 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 938 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 939 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 940 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 941 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 942 | // (as in the case of ArrayGet), as it is actually an offset |
| 943 | // to an object field within an object. |
| 944 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 945 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 946 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 947 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 948 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 949 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 950 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
| 954 | // We're moving two or three locations to locations that could |
| 955 | // overlap, so we need a parallel move resolver. |
| 956 | InvokeRuntimeCallingConvention calling_convention; |
| 957 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 958 | parallel_move.AddMove(ref_, |
| 959 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 960 | type, |
| 961 | nullptr); |
| 962 | parallel_move.AddMove(obj_, |
| 963 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 964 | type, |
| 965 | nullptr); |
| 966 | if (index.IsValid()) { |
| 967 | parallel_move.AddMove(index, |
| 968 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 969 | Primitive::kPrimInt, |
| 970 | nullptr); |
| 971 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 972 | } else { |
| 973 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 974 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 975 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 976 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 977 | instruction_, |
| 978 | instruction_->GetDexPc(), |
| 979 | this); |
| 980 | CheckEntrypointTypes< |
| 981 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 982 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 983 | |
| 984 | RestoreLiveRegisters(codegen, locations); |
| 985 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 986 | __ B(GetExitLabel()); |
| 987 | } |
| 988 | |
| 989 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 990 | |
| 991 | private: |
| 992 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 993 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 994 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 995 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 996 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 997 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 998 | } |
| 999 | } |
| 1000 | // We shall never fail to find a free caller-save register, as |
| 1001 | // there are more than two core caller-save registers on ARM64 |
| 1002 | // (meaning it is possible to find one which is different from |
| 1003 | // `ref` and `obj`). |
| 1004 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1005 | LOG(FATAL) << "Could not find a free register"; |
| 1006 | UNREACHABLE(); |
| 1007 | } |
| 1008 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1009 | const Location out_; |
| 1010 | const Location ref_; |
| 1011 | const Location obj_; |
| 1012 | const uint32_t offset_; |
| 1013 | // An additional location containing an index to an array. |
| 1014 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1015 | // UnsafeGetObjectVolatile intrinsics. |
| 1016 | const Location index_; |
| 1017 | |
| 1018 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1019 | }; |
| 1020 | |
| 1021 | // Slow path generating a read barrier for a GC root. |
| 1022 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1023 | public: |
| 1024 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1025 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1026 | DCHECK(kEmitCompilerReadBarrier); |
| 1027 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1028 | |
| 1029 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1030 | LocationSummary* locations = instruction_->GetLocations(); |
| 1031 | Primitive::Type type = Primitive::kPrimNot; |
| 1032 | DCHECK(locations->CanCall()); |
| 1033 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1034 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1035 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1036 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1037 | |
| 1038 | __ Bind(GetEntryLabel()); |
| 1039 | SaveLiveRegisters(codegen, locations); |
| 1040 | |
| 1041 | InvokeRuntimeCallingConvention calling_convention; |
| 1042 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1043 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1044 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1045 | // thus we need a 64-bit move here, and we cannot use |
| 1046 | // |
| 1047 | // arm64_codegen->MoveLocation( |
| 1048 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1049 | // root_, |
| 1050 | // type); |
| 1051 | // |
| 1052 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1053 | // reference type (`Primitive::kPrimNot`). |
| 1054 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1055 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1056 | instruction_, |
| 1057 | instruction_->GetDexPc(), |
| 1058 | this); |
| 1059 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1060 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1061 | |
| 1062 | RestoreLiveRegisters(codegen, locations); |
| 1063 | __ B(GetExitLabel()); |
| 1064 | } |
| 1065 | |
| 1066 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1067 | |
| 1068 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1069 | const Location out_; |
| 1070 | const Location root_; |
| 1071 | |
| 1072 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1073 | }; |
| 1074 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1075 | #undef __ |
| 1076 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1077 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1078 | Location next_location; |
| 1079 | if (type == Primitive::kPrimVoid) { |
| 1080 | LOG(FATAL) << "Unreachable type " << type; |
| 1081 | } |
| 1082 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1083 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1084 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 1085 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1086 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1087 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1088 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1089 | } else { |
| 1090 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1091 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1092 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1095 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1096 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1097 | return next_location; |
| 1098 | } |
| 1099 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1100 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1101 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1104 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1105 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1106 | const CompilerOptions& compiler_options, |
| 1107 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1108 | : CodeGenerator(graph, |
| 1109 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1110 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1111 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1112 | callee_saved_core_registers.GetList(), |
| 1113 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1114 | compiler_options, |
| 1115 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1116 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1117 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1118 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1119 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1120 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1121 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1122 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1123 | uint32_literals_(std::less<uint32_t>(), |
| 1124 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1125 | uint64_literals_(std::less<uint64_t>(), |
| 1126 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1127 | method_patches_(MethodReferenceComparator(), |
| 1128 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1129 | call_patches_(MethodReferenceComparator(), |
| 1130 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1131 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1132 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1133 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1134 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1135 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1136 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1137 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1138 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1139 | boot_image_address_patches_(std::less<uint32_t>(), |
| 1140 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1141 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1142 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1143 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1144 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1145 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1146 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1147 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1148 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1149 | jump_table->EmitTable(this); |
| 1150 | } |
| 1151 | } |
| 1152 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1153 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1154 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1155 | // Ensure we emit the literal pool. |
| 1156 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1157 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1158 | CodeGenerator::Finalize(allocator); |
| 1159 | } |
| 1160 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1161 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1162 | // Note: There are 6 kinds of moves: |
| 1163 | // 1. constant -> GPR/FPR (non-cycle) |
| 1164 | // 2. constant -> stack (non-cycle) |
| 1165 | // 3. GPR/FPR -> GPR/FPR |
| 1166 | // 4. GPR/FPR -> stack |
| 1167 | // 5. stack -> GPR/FPR |
| 1168 | // 6. stack -> stack (non-cycle) |
| 1169 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1170 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1171 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1172 | // dependency. |
| 1173 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1174 | } |
| 1175 | |
| 1176 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1177 | vixl_temps_.Close(); |
| 1178 | } |
| 1179 | |
| 1180 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 1181 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 1182 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 1183 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 1184 | Location scratch = GetScratchLocation(kind); |
| 1185 | if (!scratch.Equals(Location::NoLocation())) { |
| 1186 | return scratch; |
| 1187 | } |
| 1188 | // Allocate from VIXL temp registers. |
| 1189 | if (kind == Location::kRegister) { |
| 1190 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1191 | } else { |
| 1192 | DCHECK(kind == Location::kFpuRegister); |
| 1193 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1194 | } |
| 1195 | AddScratchLocation(scratch); |
| 1196 | return scratch; |
| 1197 | } |
| 1198 | |
| 1199 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1200 | if (loc.IsRegister()) { |
| 1201 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1202 | } else { |
| 1203 | DCHECK(loc.IsFpuRegister()); |
| 1204 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1205 | } |
| 1206 | RemoveScratchLocation(loc); |
| 1207 | } |
| 1208 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1209 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1210 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1211 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1214 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1215 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1216 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1217 | __ Bind(&frame_entry_label_); |
| 1218 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1219 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1220 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1221 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1222 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1223 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1224 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1225 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1226 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1227 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1228 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1229 | if (!HasEmptyFrame()) { |
| 1230 | int frame_size = GetFrameSize(); |
| 1231 | // Stack layout: |
| 1232 | // sp[frame_size - 8] : lr. |
| 1233 | // ... : other preserved core registers. |
| 1234 | // ... : other preserved fp registers. |
| 1235 | // ... : reserved frame space. |
| 1236 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1237 | |
| 1238 | // Save the current method if we need it. Note that we do not |
| 1239 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1240 | // in the SSA graph. |
| 1241 | if (RequiresCurrentMethod()) { |
| 1242 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1243 | } else { |
| 1244 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1245 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1246 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1247 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1248 | frame_size - GetCoreSpillSize()); |
| 1249 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1250 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1251 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1255 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1256 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1257 | if (!HasEmptyFrame()) { |
| 1258 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1259 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1260 | frame_size - FrameEntrySpillSize()); |
| 1261 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1262 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1263 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1264 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1265 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1266 | __ Ret(); |
| 1267 | GetAssembler()->cfi().RestoreState(); |
| 1268 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1269 | } |
| 1270 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1271 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1272 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1273 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1274 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1277 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1278 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1279 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1280 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1281 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1282 | } |
| 1283 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1284 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1285 | __ Bind(GetLabelOf(block)); |
| 1286 | } |
| 1287 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1288 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1289 | DCHECK(location.IsRegister()); |
| 1290 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1291 | } |
| 1292 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1293 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1294 | if (location.IsRegister()) { |
| 1295 | locations->AddTemp(location); |
| 1296 | } else { |
| 1297 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1298 | } |
| 1299 | } |
| 1300 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1301 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1302 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1303 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1304 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1305 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1306 | if (value_can_be_null) { |
| 1307 | __ Cbz(value, &done); |
| 1308 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1309 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1310 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1311 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1312 | if (value_can_be_null) { |
| 1313 | __ Bind(&done); |
| 1314 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1317 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1318 | // Blocked core registers: |
| 1319 | // lr : Runtime reserved. |
| 1320 | // tr : Runtime reserved. |
| 1321 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1322 | // ip1 : VIXL core temp. |
| 1323 | // ip0 : VIXL core temp. |
| 1324 | // |
| 1325 | // Blocked fp registers: |
| 1326 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1327 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1328 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1329 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1330 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1331 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1332 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1333 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1334 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1335 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1336 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1337 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1338 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1339 | // Stubs do not save callee-save floating point registers. If the graph |
| 1340 | // is debuggable, we need to deal with these registers differently. For |
| 1341 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1342 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1343 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1344 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1345 | } |
| 1346 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1349 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1350 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1351 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1352 | return kArm64WordSize; |
| 1353 | } |
| 1354 | |
| 1355 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1356 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1357 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1358 | return kArm64WordSize; |
| 1359 | } |
| 1360 | |
| 1361 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1362 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1363 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1364 | return kArm64WordSize; |
| 1365 | } |
| 1366 | |
| 1367 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1368 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1369 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1370 | return kArm64WordSize; |
| 1371 | } |
| 1372 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1373 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1374 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1378 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1381 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1382 | if (constant->IsIntConstant()) { |
| 1383 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1384 | } else if (constant->IsLongConstant()) { |
| 1385 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1386 | } else if (constant->IsNullConstant()) { |
| 1387 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1388 | } else if (constant->IsFloatConstant()) { |
| 1389 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1390 | } else { |
| 1391 | DCHECK(constant->IsDoubleConstant()); |
| 1392 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1393 | } |
| 1394 | } |
| 1395 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1396 | |
| 1397 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1398 | DCHECK(constant.IsConstant()); |
| 1399 | HConstant* cst = constant.GetConstant(); |
| 1400 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1401 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1402 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1403 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1404 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1405 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1406 | } |
| 1407 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1408 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1409 | Location source, |
| 1410 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1411 | if (source.Equals(destination)) { |
| 1412 | return; |
| 1413 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1414 | |
| 1415 | // A valid move can always be inferred from the destination and source |
| 1416 | // locations. When moving from and to a register, the argument type can be |
| 1417 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1418 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1419 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1420 | |
| 1421 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1422 | if (unspecified_type) { |
| 1423 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1424 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1425 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1426 | || src_cst->IsFloatConstant() |
| 1427 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1428 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1429 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1430 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1431 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1432 | // type is appropriate. Else the source is a register, and since the |
| 1433 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1434 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1435 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1436 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1437 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1438 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1439 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1440 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1441 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1442 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1443 | __ Ldr(dst, StackOperandFrom(source)); |
| 1444 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1445 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1446 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1447 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1448 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1449 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1450 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1451 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1452 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1453 | ? Primitive::kPrimLong |
| 1454 | : Primitive::kPrimInt; |
| 1455 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1456 | } |
| 1457 | } else { |
| 1458 | DCHECK(source.IsFpuRegister()); |
| 1459 | if (destination.IsRegister()) { |
| 1460 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1461 | ? Primitive::kPrimDouble |
| 1462 | : Primitive::kPrimFloat; |
| 1463 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1464 | } else { |
| 1465 | DCHECK(destination.IsFpuRegister()); |
| 1466 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1467 | } |
| 1468 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1469 | } else { // The destination is not a register. It must be a stack slot. |
| 1470 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1471 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1472 | if (unspecified_type) { |
| 1473 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1474 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1475 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1476 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1477 | } |
| 1478 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1479 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1480 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1481 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1482 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1483 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1484 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1485 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1486 | HConstant* src_cst = source.GetConstant(); |
| 1487 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1488 | if (src_cst->IsZeroBitPattern()) { |
| 1489 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1490 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1491 | if (src_cst->IsIntConstant()) { |
| 1492 | temp = temps.AcquireW(); |
| 1493 | } else if (src_cst->IsLongConstant()) { |
| 1494 | temp = temps.AcquireX(); |
| 1495 | } else if (src_cst->IsFloatConstant()) { |
| 1496 | temp = temps.AcquireS(); |
| 1497 | } else { |
| 1498 | DCHECK(src_cst->IsDoubleConstant()); |
| 1499 | temp = temps.AcquireD(); |
| 1500 | } |
| 1501 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1502 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1503 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1504 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1505 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1506 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1507 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1508 | // There is generally less pressure on FP registers. |
| 1509 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1510 | __ Ldr(temp, StackOperandFrom(source)); |
| 1511 | __ Str(temp, StackOperandFrom(destination)); |
| 1512 | } |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1517 | CPURegister dst, |
| 1518 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1519 | switch (type) { |
| 1520 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1521 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1522 | break; |
| 1523 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1524 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1525 | break; |
| 1526 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1527 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1530 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1531 | break; |
| 1532 | case Primitive::kPrimInt: |
| 1533 | case Primitive::kPrimNot: |
| 1534 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1535 | case Primitive::kPrimFloat: |
| 1536 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1537 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1538 | __ Ldr(dst, src); |
| 1539 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1540 | case Primitive::kPrimVoid: |
| 1541 | LOG(FATAL) << "Unreachable type " << type; |
| 1542 | } |
| 1543 | } |
| 1544 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1545 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1546 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1547 | const MemOperand& src, |
| 1548 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1549 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1550 | BlockPoolsScope block_pools(masm); |
| 1551 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1552 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1553 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1554 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1555 | DCHECK(!src.IsPreIndex()); |
| 1556 | DCHECK(!src.IsPostIndex()); |
| 1557 | |
| 1558 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1559 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1560 | MemOperand base = MemOperand(temp_base); |
| 1561 | switch (type) { |
| 1562 | case Primitive::kPrimBoolean: |
| 1563 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1564 | if (needs_null_check) { |
| 1565 | MaybeRecordImplicitNullCheck(instruction); |
| 1566 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1567 | break; |
| 1568 | case Primitive::kPrimByte: |
| 1569 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1570 | if (needs_null_check) { |
| 1571 | MaybeRecordImplicitNullCheck(instruction); |
| 1572 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1573 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1574 | break; |
| 1575 | case Primitive::kPrimChar: |
| 1576 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1577 | if (needs_null_check) { |
| 1578 | MaybeRecordImplicitNullCheck(instruction); |
| 1579 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1580 | break; |
| 1581 | case Primitive::kPrimShort: |
| 1582 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1583 | if (needs_null_check) { |
| 1584 | MaybeRecordImplicitNullCheck(instruction); |
| 1585 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1586 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1587 | break; |
| 1588 | case Primitive::kPrimInt: |
| 1589 | case Primitive::kPrimNot: |
| 1590 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1591 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1592 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1593 | if (needs_null_check) { |
| 1594 | MaybeRecordImplicitNullCheck(instruction); |
| 1595 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | case Primitive::kPrimFloat: |
| 1598 | case Primitive::kPrimDouble: { |
| 1599 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1600 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1601 | |
| 1602 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1603 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1604 | if (needs_null_check) { |
| 1605 | MaybeRecordImplicitNullCheck(instruction); |
| 1606 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1607 | __ Fmov(FPRegister(dst), temp); |
| 1608 | break; |
| 1609 | } |
| 1610 | case Primitive::kPrimVoid: |
| 1611 | LOG(FATAL) << "Unreachable type " << type; |
| 1612 | } |
| 1613 | } |
| 1614 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1615 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1616 | CPURegister src, |
| 1617 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1618 | switch (type) { |
| 1619 | case Primitive::kPrimBoolean: |
| 1620 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1621 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1622 | break; |
| 1623 | case Primitive::kPrimChar: |
| 1624 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1625 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1626 | break; |
| 1627 | case Primitive::kPrimInt: |
| 1628 | case Primitive::kPrimNot: |
| 1629 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1630 | case Primitive::kPrimFloat: |
| 1631 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1632 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1633 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1634 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1635 | case Primitive::kPrimVoid: |
| 1636 | LOG(FATAL) << "Unreachable type " << type; |
| 1637 | } |
| 1638 | } |
| 1639 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1640 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1641 | CPURegister src, |
| 1642 | const MemOperand& dst) { |
| 1643 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1644 | Register temp_base = temps.AcquireX(); |
| 1645 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1646 | DCHECK(!dst.IsPreIndex()); |
| 1647 | DCHECK(!dst.IsPostIndex()); |
| 1648 | |
| 1649 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1650 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1651 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1652 | MemOperand base = MemOperand(temp_base); |
| 1653 | switch (type) { |
| 1654 | case Primitive::kPrimBoolean: |
| 1655 | case Primitive::kPrimByte: |
| 1656 | __ Stlrb(Register(src), base); |
| 1657 | break; |
| 1658 | case Primitive::kPrimChar: |
| 1659 | case Primitive::kPrimShort: |
| 1660 | __ Stlrh(Register(src), base); |
| 1661 | break; |
| 1662 | case Primitive::kPrimInt: |
| 1663 | case Primitive::kPrimNot: |
| 1664 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1665 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1666 | __ Stlr(Register(src), base); |
| 1667 | break; |
| 1668 | case Primitive::kPrimFloat: |
| 1669 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1670 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1671 | Register temp_src; |
| 1672 | if (src.IsZero()) { |
| 1673 | // The zero register is used to avoid synthesizing zero constants. |
| 1674 | temp_src = Register(src); |
| 1675 | } else { |
| 1676 | DCHECK(src.IsFPRegister()); |
| 1677 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1678 | __ Fmov(temp_src, FPRegister(src)); |
| 1679 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1680 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1681 | __ Stlr(temp_src, base); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1682 | break; |
| 1683 | } |
| 1684 | case Primitive::kPrimVoid: |
| 1685 | LOG(FATAL) << "Unreachable type " << type; |
| 1686 | } |
| 1687 | } |
| 1688 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1689 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1690 | HInstruction* instruction, |
| 1691 | uint32_t dex_pc, |
| 1692 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1693 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1694 | GenerateInvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1695 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1696 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1697 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1700 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1701 | HInstruction* instruction, |
| 1702 | SlowPathCode* slow_path) { |
| 1703 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1704 | GenerateInvokeRuntime(entry_point_offset); |
| 1705 | } |
| 1706 | |
| 1707 | void CodeGeneratorARM64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1708 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 1709 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1710 | __ Blr(lr); |
| 1711 | } |
| 1712 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1713 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1714 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1715 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1716 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1717 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1718 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1719 | // 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] | 1720 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1721 | __ Add(temp, class_reg, status_offset); |
| 1722 | __ Ldar(temp, HeapOperand(temp)); |
| 1723 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1724 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1725 | __ Bind(slow_path->GetExitLabel()); |
| 1726 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1727 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1728 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1729 | BarrierType type = BarrierAll; |
| 1730 | |
| 1731 | switch (kind) { |
| 1732 | case MemBarrierKind::kAnyAny: |
| 1733 | case MemBarrierKind::kAnyStore: { |
| 1734 | type = BarrierAll; |
| 1735 | break; |
| 1736 | } |
| 1737 | case MemBarrierKind::kLoadAny: { |
| 1738 | type = BarrierReads; |
| 1739 | break; |
| 1740 | } |
| 1741 | case MemBarrierKind::kStoreStore: { |
| 1742 | type = BarrierWrites; |
| 1743 | break; |
| 1744 | } |
| 1745 | default: |
| 1746 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1747 | } |
| 1748 | __ Dmb(InnerShareable, type); |
| 1749 | } |
| 1750 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1751 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1752 | HBasicBlock* successor) { |
| 1753 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1754 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1755 | if (slow_path == nullptr) { |
| 1756 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1757 | instruction->SetSlowPath(slow_path); |
| 1758 | codegen_->AddSlowPath(slow_path); |
| 1759 | if (successor != nullptr) { |
| 1760 | DCHECK(successor->IsLoopHeader()); |
| 1761 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1762 | } |
| 1763 | } else { |
| 1764 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1765 | } |
| 1766 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1767 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1768 | Register temp = temps.AcquireW(); |
| 1769 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1770 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1771 | if (successor == nullptr) { |
| 1772 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1773 | __ Bind(slow_path->GetReturnLabel()); |
| 1774 | } else { |
| 1775 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1776 | __ B(slow_path->GetEntryLabel()); |
| 1777 | // slow_path will return to GetLabelOf(successor). |
| 1778 | } |
| 1779 | } |
| 1780 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1781 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1782 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1783 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1784 | assembler_(codegen->GetAssembler()), |
| 1785 | codegen_(codegen) {} |
| 1786 | |
| 1787 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1788 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1789 | |
| 1790 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1791 | |
| 1792 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1793 | // Using a base helps identify when we hit such breakpoints. |
| 1794 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1795 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1796 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1797 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1798 | }; |
| 1799 | |
| 1800 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1801 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1802 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1803 | } \ |
| 1804 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1805 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1806 | locations->SetOut(Location::Any()); \ |
| 1807 | } |
| 1808 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1809 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1810 | |
| 1811 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1812 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1813 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1814 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1815 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1816 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1817 | Primitive::Type type = instr->GetResultType(); |
| 1818 | switch (type) { |
| 1819 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1820 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1821 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1822 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1823 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1824 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1825 | |
| 1826 | case Primitive::kPrimFloat: |
| 1827 | case Primitive::kPrimDouble: |
| 1828 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1829 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1830 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1831 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1832 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1833 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1834 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1835 | } |
| 1836 | } |
| 1837 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1838 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1839 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1840 | |
| 1841 | bool object_field_get_with_read_barrier = |
| 1842 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1843 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1844 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1845 | object_field_get_with_read_barrier ? |
| 1846 | LocationSummary::kCallOnSlowPath : |
| 1847 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1848 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1849 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1850 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1851 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1852 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1853 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1854 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1855 | // The output overlaps for an object field get when read barriers |
| 1856 | // are enabled: we do not want the load to overwrite the object's |
| 1857 | // location, as we need it to emit the read barrier. |
| 1858 | locations->SetOut( |
| 1859 | Location::RequiresRegister(), |
| 1860 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1865 | const FieldInfo& field_info) { |
| 1866 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1867 | LocationSummary* locations = instruction->GetLocations(); |
| 1868 | Location base_loc = locations->InAt(0); |
| 1869 | Location out = locations->Out(); |
| 1870 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1871 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1872 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1873 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1874 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1875 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1876 | // Object FieldGet with Baker's read barrier case. |
| 1877 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1878 | UseScratchRegisterScope temps(masm); |
| 1879 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1880 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1881 | Register temp = temps.AcquireW(); |
| 1882 | // Note that potential implicit null checks are handled in this |
| 1883 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1884 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1885 | instruction, |
| 1886 | out, |
| 1887 | base, |
| 1888 | offset, |
| 1889 | temp, |
| 1890 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1891 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1892 | } else { |
| 1893 | // General case. |
| 1894 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1895 | // Note that a potential implicit null check is handled in this |
| 1896 | // CodeGeneratorARM64::LoadAcquire call. |
| 1897 | // NB: LoadAcquire will record the pc info if needed. |
| 1898 | codegen_->LoadAcquire( |
| 1899 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1900 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1901 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1902 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1903 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1904 | if (field_type == Primitive::kPrimNot) { |
| 1905 | // If read barriers are enabled, emit read barriers other than |
| 1906 | // Baker's using a slow path (and also unpoison the loaded |
| 1907 | // reference, if heap poisoning is enabled). |
| 1908 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1909 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1910 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1914 | LocationSummary* locations = |
| 1915 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1916 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1917 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 1918 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 1919 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1920 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1921 | } else { |
| 1922 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1927 | const FieldInfo& field_info, |
| 1928 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1929 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1930 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1931 | |
| 1932 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1933 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1934 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1935 | Offset offset = field_info.GetFieldOffset(); |
| 1936 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1937 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1938 | { |
| 1939 | // We use a block to end the scratch scope before the write barrier, thus |
| 1940 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1941 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1942 | |
| 1943 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1944 | DCHECK(value.IsW()); |
| 1945 | Register temp = temps.AcquireW(); |
| 1946 | __ Mov(temp, value.W()); |
| 1947 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1948 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1949 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1950 | |
| 1951 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1952 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1953 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1954 | } else { |
| 1955 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1956 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1957 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1961 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1965 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1966 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1967 | |
| 1968 | switch (type) { |
| 1969 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1970 | case Primitive::kPrimLong: { |
| 1971 | Register dst = OutputRegister(instr); |
| 1972 | Register lhs = InputRegisterAt(instr, 0); |
| 1973 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1974 | if (instr->IsAdd()) { |
| 1975 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1976 | } else if (instr->IsAnd()) { |
| 1977 | __ And(dst, lhs, rhs); |
| 1978 | } else if (instr->IsOr()) { |
| 1979 | __ Orr(dst, lhs, rhs); |
| 1980 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1981 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1982 | } else if (instr->IsRor()) { |
| 1983 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1984 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1985 | __ Ror(dst, lhs, shift); |
| 1986 | } else { |
| 1987 | // Ensure shift distance is in the same size register as the result. If |
| 1988 | // we are rotating a long and the shift comes in a w register originally, |
| 1989 | // we don't need to sxtw for use as an x since the shift distances are |
| 1990 | // all & reg_bits - 1. |
| 1991 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1992 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1993 | } else { |
| 1994 | DCHECK(instr->IsXor()); |
| 1995 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1996 | } |
| 1997 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1998 | } |
| 1999 | case Primitive::kPrimFloat: |
| 2000 | case Primitive::kPrimDouble: { |
| 2001 | FPRegister dst = OutputFPRegister(instr); |
| 2002 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2003 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2004 | if (instr->IsAdd()) { |
| 2005 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2006 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2007 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2008 | } else { |
| 2009 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2010 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2011 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2012 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2013 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2014 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2018 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2019 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2020 | |
| 2021 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2022 | Primitive::Type type = instr->GetResultType(); |
| 2023 | switch (type) { |
| 2024 | case Primitive::kPrimInt: |
| 2025 | case Primitive::kPrimLong: { |
| 2026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2027 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2028 | locations->SetOut(Location::RequiresRegister()); |
| 2029 | break; |
| 2030 | } |
| 2031 | default: |
| 2032 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2037 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2038 | |
| 2039 | Primitive::Type type = instr->GetType(); |
| 2040 | switch (type) { |
| 2041 | case Primitive::kPrimInt: |
| 2042 | case Primitive::kPrimLong: { |
| 2043 | Register dst = OutputRegister(instr); |
| 2044 | Register lhs = InputRegisterAt(instr, 0); |
| 2045 | Operand rhs = InputOperandAt(instr, 1); |
| 2046 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2047 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2048 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2049 | if (instr->IsShl()) { |
| 2050 | __ Lsl(dst, lhs, shift_value); |
| 2051 | } else if (instr->IsShr()) { |
| 2052 | __ Asr(dst, lhs, shift_value); |
| 2053 | } else { |
| 2054 | __ Lsr(dst, lhs, shift_value); |
| 2055 | } |
| 2056 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2057 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2058 | |
| 2059 | if (instr->IsShl()) { |
| 2060 | __ Lsl(dst, lhs, rhs_reg); |
| 2061 | } else if (instr->IsShr()) { |
| 2062 | __ Asr(dst, lhs, rhs_reg); |
| 2063 | } else { |
| 2064 | __ Lsr(dst, lhs, rhs_reg); |
| 2065 | } |
| 2066 | } |
| 2067 | break; |
| 2068 | } |
| 2069 | default: |
| 2070 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2071 | } |
| 2072 | } |
| 2073 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2074 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2075 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2079 | HandleBinaryOp(instruction); |
| 2080 | } |
| 2081 | |
| 2082 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2083 | HandleBinaryOp(instruction); |
| 2084 | } |
| 2085 | |
| 2086 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2087 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2088 | } |
| 2089 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2090 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2091 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2092 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2093 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2094 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2095 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2096 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2097 | } |
| 2098 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2099 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2100 | Register dst = OutputRegister(instr); |
| 2101 | Register lhs = InputRegisterAt(instr, 0); |
| 2102 | Register rhs = InputRegisterAt(instr, 1); |
| 2103 | |
| 2104 | switch (instr->GetOpKind()) { |
| 2105 | case HInstruction::kAnd: |
| 2106 | __ Bic(dst, lhs, rhs); |
| 2107 | break; |
| 2108 | case HInstruction::kOr: |
| 2109 | __ Orn(dst, lhs, rhs); |
| 2110 | break; |
| 2111 | case HInstruction::kXor: |
| 2112 | __ Eon(dst, lhs, rhs); |
| 2113 | break; |
| 2114 | default: |
| 2115 | LOG(FATAL) << "Unreachable"; |
| 2116 | } |
| 2117 | } |
| 2118 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2119 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 2120 | HArm64DataProcWithShifterOp* instruction) { |
| 2121 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2122 | instruction->GetType() == Primitive::kPrimLong); |
| 2123 | LocationSummary* locations = |
| 2124 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2125 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2126 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2127 | } else { |
| 2128 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2129 | } |
| 2130 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2131 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2132 | } |
| 2133 | |
| 2134 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 2135 | HArm64DataProcWithShifterOp* instruction) { |
| 2136 | Primitive::Type type = instruction->GetType(); |
| 2137 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2138 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2139 | Register out = OutputRegister(instruction); |
| 2140 | Register left; |
| 2141 | if (kind != HInstruction::kNeg) { |
| 2142 | left = InputRegisterAt(instruction, 0); |
| 2143 | } |
| 2144 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 2145 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2146 | // conversion) can have a different type from the current instruction's type, |
| 2147 | // so we manually indicate the type. |
| 2148 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2149 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 2150 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2151 | |
| 2152 | Operand right_operand(0); |
| 2153 | |
| 2154 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2155 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 2156 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2157 | } else { |
| 2158 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 2159 | } |
| 2160 | |
| 2161 | // Logical binary operations do not support extension operations in the |
| 2162 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2163 | // the extension as a separate instruction. |
| 2164 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2165 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2166 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2167 | kind != HInstruction::kNeg)); |
| 2168 | switch (kind) { |
| 2169 | case HInstruction::kAdd: |
| 2170 | __ Add(out, left, right_operand); |
| 2171 | break; |
| 2172 | case HInstruction::kAnd: |
| 2173 | __ And(out, left, right_operand); |
| 2174 | break; |
| 2175 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2176 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2177 | __ Neg(out, right_operand); |
| 2178 | break; |
| 2179 | case HInstruction::kOr: |
| 2180 | __ Orr(out, left, right_operand); |
| 2181 | break; |
| 2182 | case HInstruction::kSub: |
| 2183 | __ Sub(out, left, right_operand); |
| 2184 | break; |
| 2185 | case HInstruction::kXor: |
| 2186 | __ Eor(out, left, right_operand); |
| 2187 | break; |
| 2188 | default: |
| 2189 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2190 | UNREACHABLE(); |
| 2191 | } |
| 2192 | } |
| 2193 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2194 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2195 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2196 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2197 | LocationSummary* locations = |
| 2198 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2200 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 2201 | locations->SetOut(Location::RequiresRegister()); |
| 2202 | } |
| 2203 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2204 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress( |
| 2205 | HIntermediateAddress* instruction) { |
| 2206 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2207 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2208 | __ Add(OutputRegister(instruction), |
| 2209 | InputRegisterAt(instruction, 0), |
| 2210 | Operand(InputOperandAt(instruction, 1))); |
| 2211 | } |
| 2212 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2213 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2214 | LocationSummary* locations = |
| 2215 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2216 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2217 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2218 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2219 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2220 | // Don't allocate register for Mneg instruction. |
| 2221 | } else { |
| 2222 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2223 | Location::RequiresRegister()); |
| 2224 | } |
| 2225 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2226 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2227 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2228 | } |
| 2229 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2230 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2231 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2232 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2233 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2234 | |
| 2235 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2236 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2237 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2238 | if (instr->GetType() == Primitive::kPrimLong && |
| 2239 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2240 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2241 | vixl::aarch64::Instruction* prev = |
| 2242 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2243 | if (prev->IsLoadOrStore()) { |
| 2244 | // Make sure we emit only exactly one nop. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2245 | vixl::aarch64::CodeBufferCheckScope scope(masm, |
| 2246 | kInstructionSize, |
| 2247 | vixl::aarch64::CodeBufferCheckScope::kCheck, |
| 2248 | vixl::aarch64::CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2249 | __ nop(); |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2254 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2255 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2256 | } else { |
| 2257 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2258 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2259 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2260 | __ Mneg(res, mul_left, mul_right); |
| 2261 | } else { |
| 2262 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2263 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2264 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2268 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2269 | bool object_array_get_with_read_barrier = |
| 2270 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2271 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2272 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2273 | object_array_get_with_read_barrier ? |
| 2274 | LocationSummary::kCallOnSlowPath : |
| 2275 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2276 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2277 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2278 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2280 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2281 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2282 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2283 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2284 | // The output overlaps in the case of an object array get with |
| 2285 | // read barriers enabled: we do not want the move to overwrite the |
| 2286 | // array's location, as we need it to emit the read barrier. |
| 2287 | locations->SetOut( |
| 2288 | Location::RequiresRegister(), |
| 2289 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2290 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2294 | Primitive::Type type = instruction->GetType(); |
| 2295 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2296 | LocationSummary* locations = instruction->GetLocations(); |
| 2297 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2298 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2299 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2300 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2301 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2302 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2303 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2304 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2305 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2306 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2307 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2308 | // Object ArrayGet with Baker's read barrier case. |
| 2309 | Register temp = temps.AcquireW(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2310 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2311 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2312 | // Note that a potential implicit null check is handled in the |
| 2313 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2314 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2315 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2316 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2317 | // General case. |
| 2318 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2319 | Register length; |
| 2320 | if (maybe_compressed_char_at) { |
| 2321 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2322 | length = temps.AcquireW(); |
| 2323 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2325 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2326 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2327 | if (maybe_compressed_char_at) { |
| 2328 | vixl::aarch64::Label uncompressed_load, done; |
| 2329 | __ Tbz(length.W(), kWRegSize - 1, &uncompressed_load); |
| 2330 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2331 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2332 | __ B(&done); |
| 2333 | __ Bind(&uncompressed_load); |
| 2334 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2335 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2336 | __ Bind(&done); |
| 2337 | } else { |
| 2338 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2339 | source = HeapOperand(obj, offset); |
| 2340 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2341 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2342 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2343 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2344 | // The read barrier instrumentation does not support the |
| 2345 | // HIntermediateAddress instruction yet. |
| 2346 | DCHECK(!kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2347 | // We do not need to compute the intermediate address from the array: the |
| 2348 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2349 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2350 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2351 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2352 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2353 | } |
| 2354 | temp = obj; |
| 2355 | } else { |
| 2356 | __ Add(temp, obj, offset); |
| 2357 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2358 | if (maybe_compressed_char_at) { |
| 2359 | vixl::aarch64::Label uncompressed_load, done; |
| 2360 | __ Tbz(length.W(), kWRegSize - 1, &uncompressed_load); |
| 2361 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2362 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2363 | __ B(&done); |
| 2364 | __ Bind(&uncompressed_load); |
| 2365 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2366 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2367 | __ Bind(&done); |
| 2368 | } else { |
| 2369 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2370 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2371 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2372 | if (!maybe_compressed_char_at) { |
| 2373 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2374 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2375 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2376 | |
| 2377 | if (type == Primitive::kPrimNot) { |
| 2378 | static_assert( |
| 2379 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2380 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2381 | Location obj_loc = locations->InAt(0); |
| 2382 | if (index.IsConstant()) { |
| 2383 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2384 | } else { |
| 2385 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2386 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2387 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2388 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2391 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2392 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2393 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2394 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2398 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2399 | vixl::aarch64::Register out = OutputRegister(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2400 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2401 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2403 | // Mask out compression flag from String's array length. |
| 2404 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2405 | __ And(out.W(), out.W(), Operand(static_cast<int32_t>(INT32_MAX))); |
| 2406 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2407 | } |
| 2408 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2409 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2410 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2411 | |
| 2412 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2413 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2414 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2415 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2416 | LocationSummary::kCallOnSlowPath : |
| 2417 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2419 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2420 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2421 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2422 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2423 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2424 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2425 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2430 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2431 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2432 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2433 | bool needs_write_barrier = |
| 2434 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2435 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2436 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2437 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2438 | CPURegister source = value; |
| 2439 | Location index = locations->InAt(1); |
| 2440 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2441 | MemOperand destination = HeapOperand(array); |
| 2442 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2443 | BlockPoolsScope block_pools(masm); |
| 2444 | |
| 2445 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2446 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2447 | if (index.IsConstant()) { |
| 2448 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2449 | destination = HeapOperand(array, offset); |
| 2450 | } else { |
| 2451 | UseScratchRegisterScope temps(masm); |
| 2452 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2453 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2454 | // The read barrier instrumentation does not support the |
| 2455 | // HIntermediateAddress instruction yet. |
| 2456 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2457 | // We do not need to compute the intermediate address from the array: the |
| 2458 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2459 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2460 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2461 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2462 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2463 | } |
| 2464 | temp = array; |
| 2465 | } else { |
| 2466 | __ Add(temp, array, offset); |
| 2467 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2468 | destination = HeapOperand(temp, |
| 2469 | XRegisterFrom(index), |
| 2470 | LSL, |
| 2471 | Primitive::ComponentSizeShift(value_type)); |
| 2472 | } |
| 2473 | codegen_->Store(value_type, value, destination); |
| 2474 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2475 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2476 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2477 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2478 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2479 | { |
| 2480 | // We use a block to end the scratch scope before the write barrier, thus |
| 2481 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2482 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2483 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2484 | if (index.IsConstant()) { |
| 2485 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2486 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2487 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2488 | destination = HeapOperand(temp, |
| 2489 | XRegisterFrom(index), |
| 2490 | LSL, |
| 2491 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2492 | } |
| 2493 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2494 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2495 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2496 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2497 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2498 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2499 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2500 | codegen_->AddSlowPath(slow_path); |
| 2501 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2502 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2503 | __ Cbnz(Register(value), &non_zero); |
| 2504 | if (!index.IsConstant()) { |
| 2505 | __ Add(temp, array, offset); |
| 2506 | } |
| 2507 | __ Str(wzr, destination); |
| 2508 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2509 | __ B(&done); |
| 2510 | __ Bind(&non_zero); |
| 2511 | } |
| 2512 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2513 | // Note that when Baker read barriers are enabled, the type |
| 2514 | // checks are performed without read barriers. This is fine, |
| 2515 | // even in the case where a class object is in the from-space |
| 2516 | // after the flip, as a comparison involving such a type would |
| 2517 | // not produce a false positive; it may of course produce a |
| 2518 | // false negative, in which case we would take the ArraySet |
| 2519 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2520 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2521 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2522 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2523 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2524 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2525 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2526 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2527 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2528 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2529 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2530 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2531 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2532 | // nor `temp2`, as we are comparing two poisoned references. |
| 2533 | __ Cmp(temp, temp2); |
| 2534 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2535 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2536 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2537 | vixl::aarch64::Label do_put; |
| 2538 | __ B(eq, &do_put); |
| 2539 | // If heap poisoning is enabled, the `temp` reference has |
| 2540 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2541 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2542 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2543 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2544 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2545 | // If heap poisoning is enabled, no need to unpoison |
| 2546 | // `temp`, as we are comparing against null below. |
| 2547 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2548 | __ Bind(&do_put); |
| 2549 | } else { |
| 2550 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2555 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2556 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2557 | __ Mov(temp2, value.W()); |
| 2558 | GetAssembler()->PoisonHeapReference(temp2); |
| 2559 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | if (!index.IsConstant()) { |
| 2563 | __ Add(temp, array, offset); |
| 2564 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2565 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2566 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2567 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2568 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2569 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2570 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2571 | |
| 2572 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2573 | |
| 2574 | if (done.IsLinked()) { |
| 2575 | __ Bind(&done); |
| 2576 | } |
| 2577 | |
| 2578 | if (slow_path != nullptr) { |
| 2579 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2580 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2584 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2585 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2586 | InvokeRuntimeCallingConvention calling_convention; |
| 2587 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2588 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2589 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2590 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2591 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2595 | BoundsCheckSlowPathARM64* slow_path = |
| 2596 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2597 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2598 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2599 | __ B(slow_path->GetEntryLabel(), hs); |
| 2600 | } |
| 2601 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2602 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2603 | LocationSummary* locations = |
| 2604 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2606 | if (check->HasUses()) { |
| 2607 | locations->SetOut(Location::SameAsFirstInput()); |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2612 | // We assume the class is not null. |
| 2613 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2614 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2615 | codegen_->AddSlowPath(slow_path); |
| 2616 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2617 | } |
| 2618 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2619 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2620 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2621 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2622 | } |
| 2623 | |
| 2624 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2625 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2626 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2627 | if (rhs_loc.IsConstant()) { |
| 2628 | // 0.0 is the only immediate that can be encoded directly in |
| 2629 | // an FCMP instruction. |
| 2630 | // |
| 2631 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2632 | // specify that in a floating-point comparison, positive zero |
| 2633 | // and negative zero are considered equal, so we can use the |
| 2634 | // literal 0.0 for both cases here. |
| 2635 | // |
| 2636 | // Note however that some methods (Float.equal, Float.compare, |
| 2637 | // Float.compareTo, Double.equal, Double.compare, |
| 2638 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2639 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2640 | // -0.0. So if we ever translate calls to these methods into a |
| 2641 | // HCompare instruction, we must handle the -0.0 case with |
| 2642 | // care here. |
| 2643 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2644 | __ Fcmp(lhs_reg, 0.0); |
| 2645 | } else { |
| 2646 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2647 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2650 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2651 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2652 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2653 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2654 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimBoolean: |
| 2656 | case Primitive::kPrimByte: |
| 2657 | case Primitive::kPrimShort: |
| 2658 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2659 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2660 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2661 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2662 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2663 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2664 | break; |
| 2665 | } |
| 2666 | case Primitive::kPrimFloat: |
| 2667 | case Primitive::kPrimDouble: { |
| 2668 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2669 | locations->SetInAt(1, |
| 2670 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2671 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2672 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2673 | locations->SetOut(Location::RequiresRegister()); |
| 2674 | break; |
| 2675 | } |
| 2676 | default: |
| 2677 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2682 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2683 | |
| 2684 | // 0 if: left == right |
| 2685 | // 1 if: left > right |
| 2686 | // -1 if: left < right |
| 2687 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimBoolean: |
| 2689 | case Primitive::kPrimByte: |
| 2690 | case Primitive::kPrimShort: |
| 2691 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2692 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2693 | case Primitive::kPrimLong: { |
| 2694 | Register result = OutputRegister(compare); |
| 2695 | Register left = InputRegisterAt(compare, 0); |
| 2696 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2697 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2698 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2699 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | } |
| 2702 | case Primitive::kPrimFloat: |
| 2703 | case Primitive::kPrimDouble: { |
| 2704 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2705 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2706 | __ Cset(result, ne); |
| 2707 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2708 | break; |
| 2709 | } |
| 2710 | default: |
| 2711 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2712 | } |
| 2713 | } |
| 2714 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2715 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2716 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2717 | |
| 2718 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2719 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2720 | locations->SetInAt(1, |
| 2721 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2722 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2723 | : Location::RequiresFpuRegister()); |
| 2724 | } else { |
| 2725 | // Integer cases. |
| 2726 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2727 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2728 | } |
| 2729 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2730 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2731 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2732 | } |
| 2733 | } |
| 2734 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2735 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2736 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2737 | return; |
| 2738 | } |
| 2739 | |
| 2740 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2741 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2742 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2743 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2744 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2745 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2746 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2747 | } else { |
| 2748 | // Integer cases. |
| 2749 | Register lhs = InputRegisterAt(instruction, 0); |
| 2750 | Operand rhs = InputOperandAt(instruction, 1); |
| 2751 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2752 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2753 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2757 | M(Equal) \ |
| 2758 | M(NotEqual) \ |
| 2759 | M(LessThan) \ |
| 2760 | M(LessThanOrEqual) \ |
| 2761 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2762 | M(GreaterThanOrEqual) \ |
| 2763 | M(Below) \ |
| 2764 | M(BelowOrEqual) \ |
| 2765 | M(Above) \ |
| 2766 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2767 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2768 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2769 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2770 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2771 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2772 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2773 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2774 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2775 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2776 | |
| 2777 | LocationSummary* locations = instruction->GetLocations(); |
| 2778 | Location second = locations->InAt(1); |
| 2779 | DCHECK(second.IsConstant()); |
| 2780 | |
| 2781 | Register out = OutputRegister(instruction); |
| 2782 | Register dividend = InputRegisterAt(instruction, 0); |
| 2783 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2784 | DCHECK(imm == 1 || imm == -1); |
| 2785 | |
| 2786 | if (instruction->IsRem()) { |
| 2787 | __ Mov(out, 0); |
| 2788 | } else { |
| 2789 | if (imm == 1) { |
| 2790 | __ Mov(out, dividend); |
| 2791 | } else { |
| 2792 | __ Neg(out, dividend); |
| 2793 | } |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2798 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2799 | |
| 2800 | LocationSummary* locations = instruction->GetLocations(); |
| 2801 | Location second = locations->InAt(1); |
| 2802 | DCHECK(second.IsConstant()); |
| 2803 | |
| 2804 | Register out = OutputRegister(instruction); |
| 2805 | Register dividend = InputRegisterAt(instruction, 0); |
| 2806 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2807 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2808 | int ctz_imm = CTZ(abs_imm); |
| 2809 | |
| 2810 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2811 | Register temp = temps.AcquireSameSizeAs(out); |
| 2812 | |
| 2813 | if (instruction->IsDiv()) { |
| 2814 | __ Add(temp, dividend, abs_imm - 1); |
| 2815 | __ Cmp(dividend, 0); |
| 2816 | __ Csel(out, temp, dividend, lt); |
| 2817 | if (imm > 0) { |
| 2818 | __ Asr(out, out, ctz_imm); |
| 2819 | } else { |
| 2820 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2821 | } |
| 2822 | } else { |
| 2823 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2824 | __ Asr(temp, dividend, bits - 1); |
| 2825 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2826 | __ Add(out, dividend, temp); |
| 2827 | __ And(out, out, abs_imm - 1); |
| 2828 | __ Sub(out, out, temp); |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2833 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2834 | |
| 2835 | LocationSummary* locations = instruction->GetLocations(); |
| 2836 | Location second = locations->InAt(1); |
| 2837 | DCHECK(second.IsConstant()); |
| 2838 | |
| 2839 | Register out = OutputRegister(instruction); |
| 2840 | Register dividend = InputRegisterAt(instruction, 0); |
| 2841 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2842 | |
| 2843 | Primitive::Type type = instruction->GetResultType(); |
| 2844 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2845 | |
| 2846 | int64_t magic; |
| 2847 | int shift; |
| 2848 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2849 | |
| 2850 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2851 | Register temp = temps.AcquireSameSizeAs(out); |
| 2852 | |
| 2853 | // temp = get_high(dividend * magic) |
| 2854 | __ Mov(temp, magic); |
| 2855 | if (type == Primitive::kPrimLong) { |
| 2856 | __ Smulh(temp, dividend, temp); |
| 2857 | } else { |
| 2858 | __ Smull(temp.X(), dividend, temp); |
| 2859 | __ Lsr(temp.X(), temp.X(), 32); |
| 2860 | } |
| 2861 | |
| 2862 | if (imm > 0 && magic < 0) { |
| 2863 | __ Add(temp, temp, dividend); |
| 2864 | } else if (imm < 0 && magic > 0) { |
| 2865 | __ Sub(temp, temp, dividend); |
| 2866 | } |
| 2867 | |
| 2868 | if (shift != 0) { |
| 2869 | __ Asr(temp, temp, shift); |
| 2870 | } |
| 2871 | |
| 2872 | if (instruction->IsDiv()) { |
| 2873 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2874 | } else { |
| 2875 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2876 | // TODO: Strength reduction for msub. |
| 2877 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2878 | __ Mov(temp_imm, imm); |
| 2879 | __ Msub(out, temp, temp_imm, dividend); |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2884 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2885 | Primitive::Type type = instruction->GetResultType(); |
| 2886 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2887 | |
| 2888 | LocationSummary* locations = instruction->GetLocations(); |
| 2889 | Register out = OutputRegister(instruction); |
| 2890 | Location second = locations->InAt(1); |
| 2891 | |
| 2892 | if (second.IsConstant()) { |
| 2893 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2894 | |
| 2895 | if (imm == 0) { |
| 2896 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2897 | } else if (imm == 1 || imm == -1) { |
| 2898 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2899 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2900 | DivRemByPowerOfTwo(instruction); |
| 2901 | } else { |
| 2902 | DCHECK(imm <= -2 || imm >= 2); |
| 2903 | GenerateDivRemWithAnyConstant(instruction); |
| 2904 | } |
| 2905 | } else { |
| 2906 | Register dividend = InputRegisterAt(instruction, 0); |
| 2907 | Register divisor = InputRegisterAt(instruction, 1); |
| 2908 | if (instruction->IsDiv()) { |
| 2909 | __ Sdiv(out, dividend, divisor); |
| 2910 | } else { |
| 2911 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2912 | Register temp = temps.AcquireSameSizeAs(out); |
| 2913 | __ Sdiv(temp, dividend, divisor); |
| 2914 | __ Msub(out, temp, divisor, dividend); |
| 2915 | } |
| 2916 | } |
| 2917 | } |
| 2918 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2919 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2920 | LocationSummary* locations = |
| 2921 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2922 | switch (div->GetResultType()) { |
| 2923 | case Primitive::kPrimInt: |
| 2924 | case Primitive::kPrimLong: |
| 2925 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2926 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2927 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2928 | break; |
| 2929 | |
| 2930 | case Primitive::kPrimFloat: |
| 2931 | case Primitive::kPrimDouble: |
| 2932 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2933 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2934 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2935 | break; |
| 2936 | |
| 2937 | default: |
| 2938 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2943 | Primitive::Type type = div->GetResultType(); |
| 2944 | switch (type) { |
| 2945 | case Primitive::kPrimInt: |
| 2946 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2947 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | |
| 2950 | case Primitive::kPrimFloat: |
| 2951 | case Primitive::kPrimDouble: |
| 2952 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2953 | break; |
| 2954 | |
| 2955 | default: |
| 2956 | LOG(FATAL) << "Unexpected div type " << type; |
| 2957 | } |
| 2958 | } |
| 2959 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2960 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2961 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2962 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2966 | SlowPathCodeARM64* slow_path = |
| 2967 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2968 | codegen_->AddSlowPath(slow_path); |
| 2969 | Location value = instruction->GetLocations()->InAt(0); |
| 2970 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2971 | Primitive::Type type = instruction->GetType(); |
| 2972 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2973 | if (!Primitive::IsIntegralType(type)) { |
| 2974 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2975 | return; |
| 2976 | } |
| 2977 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2978 | if (value.IsConstant()) { |
| 2979 | int64_t divisor = Int64ConstantFrom(value); |
| 2980 | if (divisor == 0) { |
| 2981 | __ B(slow_path->GetEntryLabel()); |
| 2982 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2983 | // A division by a non-null constant is valid. We don't need to perform |
| 2984 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2985 | } |
| 2986 | } else { |
| 2987 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2988 | } |
| 2989 | } |
| 2990 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2991 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2992 | LocationSummary* locations = |
| 2993 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2994 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2995 | } |
| 2996 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2997 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2998 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2999 | // Will be generated at use site. |
| 3000 | } |
| 3001 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3002 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3003 | exit->SetLocations(nullptr); |
| 3004 | } |
| 3005 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3006 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3007 | } |
| 3008 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3009 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3010 | LocationSummary* locations = |
| 3011 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3012 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3013 | } |
| 3014 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3015 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3016 | // Will be generated at use site. |
| 3017 | } |
| 3018 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3019 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3020 | DCHECK(!successor->IsExitBlock()); |
| 3021 | HBasicBlock* block = got->GetBlock(); |
| 3022 | HInstruction* previous = got->GetPrevious(); |
| 3023 | HLoopInformation* info = block->GetLoopInformation(); |
| 3024 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3025 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3026 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3027 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3028 | return; |
| 3029 | } |
| 3030 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3031 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3032 | } |
| 3033 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3034 | __ B(codegen_->GetLabelOf(successor)); |
| 3035 | } |
| 3036 | } |
| 3037 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3038 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3039 | got->SetLocations(nullptr); |
| 3040 | } |
| 3041 | |
| 3042 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3043 | HandleGoto(got, got->GetSuccessor()); |
| 3044 | } |
| 3045 | |
| 3046 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3047 | try_boundary->SetLocations(nullptr); |
| 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3051 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3052 | if (!successor->IsExitBlock()) { |
| 3053 | HandleGoto(try_boundary, successor); |
| 3054 | } |
| 3055 | } |
| 3056 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3057 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3058 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3059 | vixl::aarch64::Label* true_target, |
| 3060 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3061 | // FP branching requires both targets to be explicit. If either of the targets |
| 3062 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3063 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3064 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3065 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3066 | if (true_target == nullptr && false_target == nullptr) { |
| 3067 | // Nothing to do. The code always falls through. |
| 3068 | return; |
| 3069 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3070 | // Constant condition, statically compared against "true" (integer value 1). |
| 3071 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3072 | if (true_target != nullptr) { |
| 3073 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3074 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3075 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3076 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3077 | if (false_target != nullptr) { |
| 3078 | __ B(false_target); |
| 3079 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3080 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3081 | return; |
| 3082 | } |
| 3083 | |
| 3084 | // The following code generates these patterns: |
| 3085 | // (1) true_target == nullptr && false_target != nullptr |
| 3086 | // - opposite condition true => branch to false_target |
| 3087 | // (2) true_target != nullptr && false_target == nullptr |
| 3088 | // - condition true => branch to true_target |
| 3089 | // (3) true_target != nullptr && false_target != nullptr |
| 3090 | // - condition true => branch to true_target |
| 3091 | // - branch to false_target |
| 3092 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3093 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3094 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3095 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3096 | if (true_target == nullptr) { |
| 3097 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3098 | } else { |
| 3099 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3100 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3101 | } else { |
| 3102 | // The condition instruction has not been materialized, use its inputs as |
| 3103 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3104 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3105 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3106 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3107 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3108 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3109 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3110 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3111 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3112 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3113 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3114 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3115 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3116 | // Integer cases. |
| 3117 | Register lhs = InputRegisterAt(condition, 0); |
| 3118 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3119 | |
| 3120 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3121 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3122 | if (true_target == nullptr) { |
| 3123 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3124 | non_fallthrough_target = false_target; |
| 3125 | } else { |
| 3126 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3127 | non_fallthrough_target = true_target; |
| 3128 | } |
| 3129 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3130 | 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] | 3131 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3132 | switch (arm64_cond) { |
| 3133 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3134 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3135 | break; |
| 3136 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3137 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3138 | break; |
| 3139 | case lt: |
| 3140 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3141 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3142 | break; |
| 3143 | case ge: |
| 3144 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3145 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3146 | break; |
| 3147 | default: |
| 3148 | // Without the `static_cast` the compiler throws an error for |
| 3149 | // `-Werror=sign-promo`. |
| 3150 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3151 | } |
| 3152 | } else { |
| 3153 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3154 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3155 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3156 | } |
| 3157 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3158 | |
| 3159 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3160 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3161 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3162 | __ B(false_target); |
| 3163 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3164 | |
| 3165 | if (fallthrough_target.IsLinked()) { |
| 3166 | __ Bind(&fallthrough_target); |
| 3167 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3170 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3171 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3172 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3174 | } |
| 3175 | } |
| 3176 | |
| 3177 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3178 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3179 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3180 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3181 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3182 | true_target = nullptr; |
| 3183 | } |
| 3184 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3185 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3186 | false_target = nullptr; |
| 3187 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3188 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3192 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3193 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3194 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3195 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3201 | SlowPathCodeARM64* slow_path = |
| 3202 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3203 | GenerateTestAndBranch(deoptimize, |
| 3204 | /* condition_input_index */ 0, |
| 3205 | slow_path->GetEntryLabel(), |
| 3206 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3209 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3210 | return condition->IsCondition() && |
| 3211 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3212 | } |
| 3213 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3214 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3215 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3216 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3217 | : ARM64Condition(cond); |
| 3218 | } |
| 3219 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3220 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3221 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3222 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3223 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3224 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3225 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3226 | } else { |
| 3227 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3228 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3229 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3230 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3231 | // Ask VIXL whether we should synthesize constants in registers. |
| 3232 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3233 | Operand true_op = is_true_value_constant ? |
| 3234 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3235 | Operand false_op = is_false_value_constant ? |
| 3236 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3237 | bool true_value_in_register = false; |
| 3238 | bool false_value_in_register = false; |
| 3239 | MacroAssembler::GetCselSynthesisInformation( |
| 3240 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3241 | true_value_in_register |= !is_true_value_constant; |
| 3242 | false_value_in_register |= !is_false_value_constant; |
| 3243 | |
| 3244 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3245 | : Location::ConstantLocation(cst_true_value)); |
| 3246 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3247 | : Location::ConstantLocation(cst_false_value)); |
| 3248 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3249 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3250 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3251 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3252 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3253 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3257 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3258 | Condition csel_cond; |
| 3259 | |
| 3260 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3261 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3262 | // Use the condition flags set by the previous instruction. |
| 3263 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3264 | } else { |
| 3265 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3266 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3267 | } |
| 3268 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3269 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3270 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3271 | } else { |
| 3272 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3273 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3276 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3277 | __ Fcsel(OutputFPRegister(select), |
| 3278 | InputFPRegisterAt(select, 1), |
| 3279 | InputFPRegisterAt(select, 0), |
| 3280 | csel_cond); |
| 3281 | } else { |
| 3282 | __ Csel(OutputRegister(select), |
| 3283 | InputOperandAt(select, 1), |
| 3284 | InputOperandAt(select, 0), |
| 3285 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3286 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3289 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3290 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3291 | } |
| 3292 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3293 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3294 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | void CodeGeneratorARM64::GenerateNop() { |
| 3298 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3299 | } |
| 3300 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3301 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3302 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3306 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3310 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3314 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3315 | } |
| 3316 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3317 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 3318 | return kEmitCompilerReadBarrier && |
| 3319 | (kUseBakerReadBarrier || |
| 3320 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3321 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3322 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 3323 | } |
| 3324 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3325 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3326 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3327 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3328 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3329 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3330 | case TypeCheckKind::kExactCheck: |
| 3331 | case TypeCheckKind::kAbstractClassCheck: |
| 3332 | case TypeCheckKind::kClassHierarchyCheck: |
| 3333 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3334 | call_kind = |
| 3335 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3336 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3339 | case TypeCheckKind::kUnresolvedCheck: |
| 3340 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3341 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3342 | break; |
| 3343 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3344 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3345 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3346 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3347 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3348 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3350 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3351 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3352 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3353 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3354 | // When read barriers are enabled, we need a temporary register for |
| 3355 | // some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3356 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3357 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3358 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3362 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3363 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3364 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3365 | Register obj = InputRegisterAt(instruction, 0); |
| 3366 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3367 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3368 | Register out = OutputRegister(instruction); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3369 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3370 | locations->GetTemp(0) : |
| 3371 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3372 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3373 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3374 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3375 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3376 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3377 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3378 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3379 | |
| 3380 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3381 | // Avoid null check if we know `obj` is not null. |
| 3382 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3383 | __ Cbz(obj, &zero); |
| 3384 | } |
| 3385 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3386 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3387 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3388 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3389 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3390 | case TypeCheckKind::kExactCheck: { |
| 3391 | __ Cmp(out, cls); |
| 3392 | __ Cset(out, eq); |
| 3393 | if (zero.IsLinked()) { |
| 3394 | __ B(&done); |
| 3395 | } |
| 3396 | break; |
| 3397 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3398 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3399 | case TypeCheckKind::kAbstractClassCheck: { |
| 3400 | // If the class is abstract, we eagerly fetch the super class of the |
| 3401 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3402 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3403 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3404 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3405 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3406 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3407 | __ Cbz(out, &done); |
| 3408 | __ Cmp(out, cls); |
| 3409 | __ B(ne, &loop); |
| 3410 | __ Mov(out, 1); |
| 3411 | if (zero.IsLinked()) { |
| 3412 | __ B(&done); |
| 3413 | } |
| 3414 | break; |
| 3415 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3416 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3417 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3418 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3419 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3420 | __ Bind(&loop); |
| 3421 | __ Cmp(out, cls); |
| 3422 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3423 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3424 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3425 | __ Cbnz(out, &loop); |
| 3426 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3427 | __ B(&done); |
| 3428 | __ Bind(&success); |
| 3429 | __ Mov(out, 1); |
| 3430 | if (zero.IsLinked()) { |
| 3431 | __ B(&done); |
| 3432 | } |
| 3433 | break; |
| 3434 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3435 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3436 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3437 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3438 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3439 | __ Cmp(out, cls); |
| 3440 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3441 | // 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] | 3442 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3443 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3444 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3445 | __ Cbz(out, &done); |
| 3446 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3447 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3448 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3449 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3450 | __ Mov(out, 1); |
| 3451 | __ B(&done); |
| 3452 | break; |
| 3453 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3454 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3455 | case TypeCheckKind::kArrayCheck: { |
| 3456 | __ Cmp(out, cls); |
| 3457 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3458 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3459 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3460 | codegen_->AddSlowPath(slow_path); |
| 3461 | __ B(ne, slow_path->GetEntryLabel()); |
| 3462 | __ Mov(out, 1); |
| 3463 | if (zero.IsLinked()) { |
| 3464 | __ B(&done); |
| 3465 | } |
| 3466 | break; |
| 3467 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3468 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3469 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3470 | case TypeCheckKind::kInterfaceCheck: { |
| 3471 | // Note that we indeed only call on slow path, but we always go |
| 3472 | // into the slow path for the unresolved and interface check |
| 3473 | // cases. |
| 3474 | // |
| 3475 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3476 | // entry point without resorting to a type checking slow path |
| 3477 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3478 | // require to assign fixed registers for the inputs of this |
| 3479 | // HInstanceOf instruction (following the runtime calling |
| 3480 | // convention), which might be cluttered by the potential first |
| 3481 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3482 | // |
| 3483 | // TODO: Introduce a new runtime entry point taking the object |
| 3484 | // to test (instead of its class) as argument, and let it deal |
| 3485 | // with the read barrier issues. This will let us refactor this |
| 3486 | // case of the `switch` code as it was previously (with a direct |
| 3487 | // call to the runtime not using a type checking slow path). |
| 3488 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3489 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3490 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3491 | /* is_fatal */ false); |
| 3492 | codegen_->AddSlowPath(slow_path); |
| 3493 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3494 | if (zero.IsLinked()) { |
| 3495 | __ B(&done); |
| 3496 | } |
| 3497 | break; |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | if (zero.IsLinked()) { |
| 3502 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3503 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | if (done.IsLinked()) { |
| 3507 | __ Bind(&done); |
| 3508 | } |
| 3509 | |
| 3510 | if (slow_path != nullptr) { |
| 3511 | __ Bind(slow_path->GetExitLabel()); |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3516 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3517 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3518 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3519 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3520 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3521 | case TypeCheckKind::kExactCheck: |
| 3522 | case TypeCheckKind::kAbstractClassCheck: |
| 3523 | case TypeCheckKind::kClassHierarchyCheck: |
| 3524 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3525 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3526 | LocationSummary::kCallOnSlowPath : |
| 3527 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3528 | break; |
| 3529 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3530 | case TypeCheckKind::kUnresolvedCheck: |
| 3531 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3532 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3533 | break; |
| 3534 | } |
| 3535 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3536 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3538 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3539 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3540 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3541 | // When read barriers are enabled, we need an additional temporary |
| 3542 | // register for some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3543 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
| 3544 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3549 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3550 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3551 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3552 | Register obj = InputRegisterAt(instruction, 0); |
| 3553 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3554 | Location temp_loc = locations->GetTemp(0); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3555 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3556 | locations->GetTemp(1) : |
| 3557 | Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3558 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3559 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3560 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3561 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3562 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3563 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3564 | bool is_type_check_slow_path_fatal = |
| 3565 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3566 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3567 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3568 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3569 | !instruction->CanThrowIntoCatchBlock(); |
| 3570 | SlowPathCodeARM64* type_check_slow_path = |
| 3571 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3572 | is_type_check_slow_path_fatal); |
| 3573 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3574 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3575 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3576 | // Avoid null check if we know obj is not null. |
| 3577 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3578 | __ Cbz(obj, &done); |
| 3579 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3580 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3581 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3582 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3583 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3584 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3585 | case TypeCheckKind::kExactCheck: |
| 3586 | case TypeCheckKind::kArrayCheck: { |
| 3587 | __ Cmp(temp, cls); |
| 3588 | // Jump to slow path for throwing the exception or doing a |
| 3589 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3590 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3591 | break; |
| 3592 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3593 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3594 | case TypeCheckKind::kAbstractClassCheck: { |
| 3595 | // If the class is abstract, we eagerly fetch the super class of the |
| 3596 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3597 | vixl::aarch64::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3598 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3599 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3600 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3601 | |
| 3602 | // If the class reference currently in `temp` is not null, jump |
| 3603 | // to the `compare_classes` label to compare it with the checked |
| 3604 | // class. |
| 3605 | __ Cbnz(temp, &compare_classes); |
| 3606 | // Otherwise, jump to the slow path to throw the exception. |
| 3607 | // |
| 3608 | // But before, move back the object's class into `temp` before |
| 3609 | // going into the slow path, as it has been overwritten in the |
| 3610 | // meantime. |
| 3611 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3612 | GenerateReferenceLoadTwoRegisters( |
| 3613 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3614 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3615 | |
| 3616 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3617 | __ Cmp(temp, cls); |
| 3618 | __ B(ne, &loop); |
| 3619 | break; |
| 3620 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3621 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3622 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3623 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3624 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3625 | __ Bind(&loop); |
| 3626 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3627 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3628 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3629 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3630 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3631 | |
| 3632 | // If the class reference currently in `temp` is not null, jump |
| 3633 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3634 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3635 | // Otherwise, jump to the slow path to throw the exception. |
| 3636 | // |
| 3637 | // But before, move back the object's class into `temp` before |
| 3638 | // going into the slow path, as it has been overwritten in the |
| 3639 | // meantime. |
| 3640 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3641 | GenerateReferenceLoadTwoRegisters( |
| 3642 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3643 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3644 | break; |
| 3645 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3646 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3647 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3648 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3649 | vixl::aarch64::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3650 | __ Cmp(temp, cls); |
| 3651 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3652 | |
| 3653 | // 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] | 3654 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3655 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3656 | |
| 3657 | // If the component type is not null (i.e. the object is indeed |
| 3658 | // an array), jump to label `check_non_primitive_component_type` |
| 3659 | // to further check that this component type is not a primitive |
| 3660 | // type. |
| 3661 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3662 | // Otherwise, jump to the slow path to throw the exception. |
| 3663 | // |
| 3664 | // But before, move back the object's class into `temp` before |
| 3665 | // going into the slow path, as it has been overwritten in the |
| 3666 | // meantime. |
| 3667 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3668 | GenerateReferenceLoadTwoRegisters( |
| 3669 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3670 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3671 | |
| 3672 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3673 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3674 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3675 | __ Cbz(temp, &done); |
| 3676 | // Same comment as above regarding `temp` and the slow path. |
| 3677 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3678 | GenerateReferenceLoadTwoRegisters( |
| 3679 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3680 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3681 | break; |
| 3682 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3683 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3684 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3685 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3686 | // We always go into the type check slow path for the unresolved |
| 3687 | // and interface check cases. |
| 3688 | // |
| 3689 | // We cannot directly call the CheckCast runtime entry point |
| 3690 | // without resorting to a type checking slow path here (i.e. by |
| 3691 | // calling InvokeRuntime directly), as it would require to |
| 3692 | // assign fixed registers for the inputs of this HInstanceOf |
| 3693 | // instruction (following the runtime calling convention), which |
| 3694 | // might be cluttered by the potential first read barrier |
| 3695 | // emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3696 | // |
| 3697 | // TODO: Introduce a new runtime entry point taking the object |
| 3698 | // to test (instead of its class) as argument, and let it deal |
| 3699 | // with the read barrier issues. This will let us refactor this |
| 3700 | // case of the `switch` code as it was previously (with a direct |
| 3701 | // call to the runtime not using a type checking slow path). |
| 3702 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3703 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3704 | break; |
| 3705 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3706 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3707 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3708 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3711 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3712 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3713 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3714 | } |
| 3715 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3716 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3717 | // Will be generated at use site. |
| 3718 | } |
| 3719 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3720 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3721 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3722 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3723 | } |
| 3724 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3725 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3726 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3729 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3730 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3731 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3732 | // the method_idx. |
| 3733 | HandleInvoke(invoke); |
| 3734 | } |
| 3735 | |
| 3736 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3737 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3738 | } |
| 3739 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3740 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3741 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3742 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3743 | } |
| 3744 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3745 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3746 | HandleInvoke(invoke); |
| 3747 | } |
| 3748 | |
| 3749 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3750 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3751 | LocationSummary* locations = invoke->GetLocations(); |
| 3752 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3753 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3754 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3755 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3756 | |
| 3757 | // The register ip1 is required to be used for the hidden argument in |
| 3758 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3759 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3760 | UseScratchRegisterScope scratch_scope(masm); |
| 3761 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3762 | scratch_scope.Exclude(ip1); |
| 3763 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3764 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3765 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3766 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3767 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3768 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3769 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3770 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3771 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3772 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3773 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3774 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3775 | // emit a read barrier for the previous class reference load. |
| 3776 | // However this is not required in practice, as this is an |
| 3777 | // intermediate/temporary reference and because the current |
| 3778 | // concurrent copying collector keeps the from-space memory |
| 3779 | // intact/accessible until the end of the marking phase (the |
| 3780 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3781 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3782 | __ Ldr(temp, |
| 3783 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3784 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3785 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3786 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3787 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3788 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3789 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3790 | // lr(); |
| 3791 | __ Blr(lr); |
| 3792 | DCHECK(!codegen_->IsLeafMethod()); |
| 3793 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3794 | } |
| 3795 | |
| 3796 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3797 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3798 | if (intrinsic.TryDispatch(invoke)) { |
| 3799 | return; |
| 3800 | } |
| 3801 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3802 | HandleInvoke(invoke); |
| 3803 | } |
| 3804 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3805 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3806 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3807 | // art::PrepareForRegisterAllocation. |
| 3808 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3809 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3810 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3811 | if (intrinsic.TryDispatch(invoke)) { |
| 3812 | return; |
| 3813 | } |
| 3814 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3815 | HandleInvoke(invoke); |
| 3816 | } |
| 3817 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3818 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3819 | if (invoke->GetLocations()->Intrinsified()) { |
| 3820 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3821 | intrinsic.Dispatch(invoke); |
| 3822 | return true; |
| 3823 | } |
| 3824 | return false; |
| 3825 | } |
| 3826 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3827 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3828 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3829 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3830 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3831 | return desired_dispatch_info; |
| 3832 | } |
| 3833 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3834 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3835 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3836 | bool direct_code_loaded = false; |
| 3837 | switch (invoke->GetCodePtrLocation()) { |
| 3838 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3839 | // LR = code address from literal pool with link-time patch. |
| 3840 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3841 | direct_code_loaded = true; |
| 3842 | break; |
| 3843 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3844 | // LR = invoke->GetDirectCodePtr(); |
| 3845 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3846 | direct_code_loaded = true; |
| 3847 | break; |
| 3848 | default: |
| 3849 | break; |
| 3850 | } |
| 3851 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3852 | // 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] | 3853 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3854 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3855 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 3856 | uint32_t offset = |
| 3857 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3858 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3859 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3860 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 3861 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3862 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3863 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3864 | break; |
| 3865 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3866 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3867 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3868 | break; |
| 3869 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3870 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3871 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3872 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3873 | break; |
| 3874 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3875 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3876 | const DexFile& dex_file = invoke->GetDexFile(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3877 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3878 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3879 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3880 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3881 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3882 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3883 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3884 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3885 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3886 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3887 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3888 | Register reg = XRegisterFrom(temp); |
| 3889 | Register method_reg; |
| 3890 | if (current_method.IsRegister()) { |
| 3891 | method_reg = XRegisterFrom(current_method); |
| 3892 | } else { |
| 3893 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3894 | DCHECK(!current_method.IsValid()); |
| 3895 | method_reg = reg; |
| 3896 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3897 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3898 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3899 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3900 | __ Ldr(reg.X(), |
| 3901 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3902 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3903 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3904 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3905 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3906 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3907 | break; |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | switch (invoke->GetCodePtrLocation()) { |
| 3912 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3913 | __ Bl(&frame_entry_label_); |
| 3914 | break; |
| 3915 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 3916 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 3917 | invoke->GetTargetMethod().dex_method_index); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3918 | vixl::aarch64::Label* label = &relative_call_patches_.back().label; |
| 3919 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3920 | __ Bind(label); |
| 3921 | __ 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] | 3922 | break; |
| 3923 | } |
| 3924 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3925 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3926 | // LR prepared above for better instruction scheduling. |
| 3927 | DCHECK(direct_code_loaded); |
| 3928 | // lr() |
| 3929 | __ Blr(lr); |
| 3930 | break; |
| 3931 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3932 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3933 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3934 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3935 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3936 | // lr() |
| 3937 | __ Blr(lr); |
| 3938 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3939 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3940 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3941 | DCHECK(!IsLeafMethod()); |
| 3942 | } |
| 3943 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3944 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3945 | // Use the calling convention instead of the location of the receiver, as |
| 3946 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3947 | // slow path, the arguments have been moved to the right place, so here we are |
| 3948 | // guaranteed that the receiver is the first register of the calling convention. |
| 3949 | InvokeDexCallingConvention calling_convention; |
| 3950 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3951 | Register temp = XRegisterFrom(temp_in); |
| 3952 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3953 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3954 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3955 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3956 | |
| 3957 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3958 | |
| 3959 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3960 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3961 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3962 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3963 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3964 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3965 | // intermediate/temporary reference and because the current |
| 3966 | // concurrent copying collector keeps the from-space memory |
| 3967 | // intact/accessible until the end of the marking phase (the |
| 3968 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3969 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3970 | // temp = temp->GetMethodAt(method_offset); |
| 3971 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3972 | // lr = temp->GetEntryPoint(); |
| 3973 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3974 | // lr(); |
| 3975 | __ Blr(lr); |
| 3976 | } |
| 3977 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3978 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 3979 | const DexFile& dex_file, |
| 3980 | uint32_t string_index, |
| 3981 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3982 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 3983 | } |
| 3984 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3985 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 3986 | const DexFile& dex_file, |
| 3987 | uint32_t type_index, |
| 3988 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3989 | return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_); |
| 3990 | } |
| 3991 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3992 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 3993 | const DexFile& dex_file, |
| 3994 | uint32_t element_offset, |
| 3995 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3996 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 3997 | } |
| 3998 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3999 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4000 | const DexFile& dex_file, |
| 4001 | uint32_t offset_or_index, |
| 4002 | vixl::aarch64::Label* adrp_label, |
| 4003 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4004 | // Add a patch entry and return the label. |
| 4005 | patches->emplace_back(dex_file, offset_or_index); |
| 4006 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4007 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4008 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4009 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4010 | return label; |
| 4011 | } |
| 4012 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4013 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4014 | const DexFile& dex_file, uint32_t string_index) { |
| 4015 | return boot_image_string_patches_.GetOrCreate( |
| 4016 | StringReference(&dex_file, string_index), |
| 4017 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4018 | } |
| 4019 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4020 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4021 | const DexFile& dex_file, uint32_t type_index) { |
| 4022 | return boot_image_type_patches_.GetOrCreate( |
| 4023 | TypeReference(&dex_file, type_index), |
| 4024 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4025 | } |
| 4026 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4027 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4028 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4029 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 4030 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 4031 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 4032 | } |
| 4033 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4034 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral( |
| 4035 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4036 | return DeduplicateUint64Literal(address); |
| 4037 | } |
| 4038 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4039 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4040 | vixl::aarch64::Register reg) { |
| 4041 | DCHECK(reg.IsX()); |
| 4042 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4043 | __ Bind(fixup_label); |
| 4044 | __ adrp(reg, /* offset placeholder */ 0); |
| 4045 | } |
| 4046 | |
| 4047 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4048 | vixl::aarch64::Register out, |
| 4049 | vixl::aarch64::Register base) { |
| 4050 | DCHECK(out.IsX()); |
| 4051 | DCHECK(base.IsX()); |
| 4052 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4053 | __ Bind(fixup_label); |
| 4054 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4055 | } |
| 4056 | |
| 4057 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4058 | vixl::aarch64::Register out, |
| 4059 | vixl::aarch64::Register base) { |
| 4060 | DCHECK(base.IsX()); |
| 4061 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4062 | __ Bind(fixup_label); |
| 4063 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4064 | } |
| 4065 | |
| 4066 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4067 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4068 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4069 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4070 | for (const PcRelativePatchInfo& info : infos) { |
| 4071 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4072 | &info.target_dex_file, |
| 4073 | info.pc_insn_label->GetLocation(), |
| 4074 | info.offset_or_index)); |
| 4075 | } |
| 4076 | } |
| 4077 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4078 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4079 | DCHECK(linker_patches->empty()); |
| 4080 | size_t size = |
| 4081 | method_patches_.size() + |
| 4082 | call_patches_.size() + |
| 4083 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4084 | pc_relative_dex_cache_patches_.size() + |
| 4085 | boot_image_string_patches_.size() + |
| 4086 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4087 | boot_image_type_patches_.size() + |
| 4088 | pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4089 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4090 | linker_patches->reserve(size); |
| 4091 | for (const auto& entry : method_patches_) { |
| 4092 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4093 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 4094 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4095 | target_method.dex_file, |
| 4096 | target_method.dex_method_index)); |
| 4097 | } |
| 4098 | for (const auto& entry : call_patches_) { |
| 4099 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4100 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 4101 | linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4102 | target_method.dex_file, |
| 4103 | target_method.dex_method_index)); |
| 4104 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4105 | for (const PatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) { |
| 4106 | linker_patches->push_back( |
| 4107 | LinkerPatch::RelativeCodePatch(info.label.GetLocation(), &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4108 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4109 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4110 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4111 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4112 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4113 | info.offset_or_index)); |
| 4114 | } |
| 4115 | for (const auto& entry : boot_image_string_patches_) { |
| 4116 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4117 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4118 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4119 | target_string.dex_file, |
| 4120 | target_string.string_index)); |
| 4121 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4122 | if (!GetCompilerOptions().IsBootImage()) { |
| 4123 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4124 | linker_patches); |
| 4125 | } else { |
| 4126 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4127 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4128 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4129 | for (const auto& entry : boot_image_type_patches_) { |
| 4130 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4131 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4132 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4133 | target_type.dex_file, |
| 4134 | target_type.type_index)); |
| 4135 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4136 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4137 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4138 | for (const auto& entry : boot_image_address_patches_) { |
| 4139 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4140 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4141 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4145 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4146 | Uint32ToLiteralMap* map) { |
| 4147 | return map->GetOrCreate( |
| 4148 | value, |
| 4149 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4150 | } |
| 4151 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4152 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4153 | return uint64_literals_.GetOrCreate( |
| 4154 | value, |
| 4155 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4158 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4159 | MethodReference target_method, |
| 4160 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4161 | return map->GetOrCreate( |
| 4162 | target_method, |
| 4163 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4166 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4167 | MethodReference target_method) { |
| 4168 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 4169 | } |
| 4170 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4171 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4172 | MethodReference target_method) { |
| 4173 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 4174 | } |
| 4175 | |
| 4176 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4177 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4178 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4179 | // art::PrepareForRegisterAllocation. |
| 4180 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4181 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4182 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4183 | return; |
| 4184 | } |
| 4185 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4186 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4187 | LocationSummary* locations = invoke->GetLocations(); |
| 4188 | codegen_->GenerateStaticOrDirectCall( |
| 4189 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4190 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4194 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4195 | return; |
| 4196 | } |
| 4197 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4198 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4199 | DCHECK(!codegen_->IsLeafMethod()); |
| 4200 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4201 | } |
| 4202 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4203 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4204 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4205 | switch (desired_class_load_kind) { |
| 4206 | case HLoadClass::LoadKind::kReferrersClass: |
| 4207 | break; |
| 4208 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4209 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4210 | break; |
| 4211 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4212 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4213 | break; |
| 4214 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4215 | break; |
| 4216 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 4217 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4218 | break; |
| 4219 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 4220 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4221 | break; |
| 4222 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4223 | break; |
| 4224 | } |
| 4225 | return desired_class_load_kind; |
| 4226 | } |
| 4227 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4228 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4229 | if (cls->NeedsAccessCheck()) { |
| 4230 | InvokeRuntimeCallingConvention calling_convention; |
| 4231 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4232 | cls, |
| 4233 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4234 | LocationFrom(vixl::aarch64::x0), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4235 | /* code_generator_supports_read_barrier */ true); |
| 4236 | return; |
| 4237 | } |
| 4238 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4239 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4240 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4241 | ? LocationSummary::kCallOnSlowPath |
| 4242 | : LocationSummary::kNoCall; |
| 4243 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4244 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4245 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4246 | } |
| 4247 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4248 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4249 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 4250 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4251 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4252 | } |
| 4253 | locations->SetOut(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4257 | if (cls->NeedsAccessCheck()) { |
| 4258 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4259 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4260 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4261 | return; |
| 4262 | } |
| 4263 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4264 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4265 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4266 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4267 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4268 | bool generate_null_check = false; |
| 4269 | switch (cls->GetLoadKind()) { |
| 4270 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4271 | DCHECK(!cls->CanCallRuntime()); |
| 4272 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4273 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4274 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4275 | GenerateGcRootFieldLoad(cls, |
| 4276 | out_loc, |
| 4277 | current_method, |
| 4278 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4279 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4280 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4281 | break; |
| 4282 | } |
| 4283 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4284 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4285 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4286 | cls->GetTypeIndex())); |
| 4287 | break; |
| 4288 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4289 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4290 | // Add ADRP with its PC-relative type patch. |
| 4291 | const DexFile& dex_file = cls->GetDexFile(); |
| 4292 | uint32_t type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4293 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4294 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4295 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4296 | vixl::aarch64::Label* add_label = |
| 4297 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4298 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4299 | break; |
| 4300 | } |
| 4301 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4302 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4303 | DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress())); |
| 4304 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress())); |
| 4305 | break; |
| 4306 | } |
| 4307 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 4308 | DCHECK_NE(cls->GetAddress(), 0u); |
| 4309 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4310 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4311 | // multiple types, simply split the dex cache address to a 16KiB aligned base |
| 4312 | // loaded from a literal and the remaining offset embedded in the load. |
| 4313 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 4314 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 4315 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4316 | uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4317 | uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4318 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4319 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4320 | GenerateGcRootFieldLoad(cls, |
| 4321 | out_loc, |
| 4322 | out.X(), |
| 4323 | offset, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4324 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4325 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4326 | generate_null_check = !cls->IsInDexCache(); |
| 4327 | break; |
| 4328 | } |
| 4329 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 4330 | // Add ADRP with its PC-relative DexCache access patch. |
| 4331 | const DexFile& dex_file = cls->GetDexFile(); |
| 4332 | uint32_t element_offset = cls->GetDexCacheElementOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4333 | vixl::aarch64::Label* adrp_label = |
| 4334 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4335 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4336 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4337 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4338 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4339 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4340 | GenerateGcRootFieldLoad(cls, |
| 4341 | out_loc, |
| 4342 | out.X(), |
| 4343 | /* offset placeholder */ 0, |
| 4344 | ldr_label, |
| 4345 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4346 | generate_null_check = !cls->IsInDexCache(); |
| 4347 | break; |
| 4348 | } |
| 4349 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 4350 | MemberOffset resolved_types_offset = |
| 4351 | ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 4352 | // /* GcRoot<mirror::Class>[] */ out = |
| 4353 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 4354 | Register current_method = InputRegisterAt(cls, 0); |
| 4355 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 4356 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4357 | GenerateGcRootFieldLoad(cls, |
| 4358 | out_loc, |
| 4359 | out.X(), |
| 4360 | CodeGenerator::GetCacheOffset(cls->GetTypeIndex()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4361 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4362 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4363 | generate_null_check = !cls->IsInDexCache(); |
| 4364 | break; |
| 4365 | } |
| 4366 | } |
| 4367 | |
| 4368 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 4369 | DCHECK(cls->CanCallRuntime()); |
| 4370 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 4371 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4372 | codegen_->AddSlowPath(slow_path); |
| 4373 | if (generate_null_check) { |
| 4374 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4375 | } |
| 4376 | if (cls->MustGenerateClinitCheck()) { |
| 4377 | GenerateClassInitializationCheck(slow_path, out); |
| 4378 | } else { |
| 4379 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | } |
| 4383 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4384 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4385 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4386 | } |
| 4387 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4388 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4389 | LocationSummary* locations = |
| 4390 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4391 | locations->SetOut(Location::RequiresRegister()); |
| 4392 | } |
| 4393 | |
| 4394 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4395 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4396 | } |
| 4397 | |
| 4398 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4399 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4400 | } |
| 4401 | |
| 4402 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4403 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4406 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4407 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4408 | switch (desired_string_load_kind) { |
| 4409 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4410 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4411 | break; |
| 4412 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4413 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4414 | break; |
| 4415 | case HLoadString::LoadKind::kBootImageAddress: |
| 4416 | break; |
| 4417 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4418 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4419 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4420 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4421 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4422 | break; |
| 4423 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4424 | break; |
| 4425 | } |
| 4426 | return desired_string_load_kind; |
| 4427 | } |
| 4428 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4429 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4430 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4431 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 4432 | ? LocationSummary::kCallOnMainOnly |
| 4433 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4434 | : LocationSummary::kNoCall; |
| 4435 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4436 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4437 | InvokeRuntimeCallingConvention calling_convention; |
| 4438 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4439 | } else { |
| 4440 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4441 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4442 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4443 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 4444 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4445 | InvokeRuntimeCallingConvention calling_convention; |
| 4446 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4447 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4448 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4449 | Primitive::kPrimNot).GetCode()); |
| 4450 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4451 | } else { |
| 4452 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4453 | } |
| 4454 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4455 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4459 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4460 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4461 | switch (load->GetLoadKind()) { |
| 4462 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4463 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4464 | load->GetStringIndex())); |
| 4465 | return; // No dex cache slow path. |
| 4466 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4467 | // Add ADRP with its PC-relative String patch. |
| 4468 | const DexFile& dex_file = load->GetDexFile(); |
| 4469 | uint32_t string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4470 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4471 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4472 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4473 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4474 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4475 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4476 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4477 | return; // No dex cache slow path. |
| 4478 | } |
| 4479 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4480 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4481 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4482 | return; // No dex cache slow path. |
| 4483 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4484 | case HLoadString::LoadKind::kBssEntry: { |
| 4485 | // Add ADRP with its PC-relative String .bss entry patch. |
| 4486 | const DexFile& dex_file = load->GetDexFile(); |
| 4487 | uint32_t string_index = load->GetStringIndex(); |
| 4488 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4489 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4490 | Register temp = temps.AcquireX(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4491 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4492 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4493 | // Add LDR with its PC-relative String patch. |
| 4494 | vixl::aarch64::Label* ldr_label = |
| 4495 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 4496 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4497 | GenerateGcRootFieldLoad(load, |
| 4498 | load->GetLocations()->Out(), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4499 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4500 | /* offset placeholder */ 0u, |
| 4501 | ldr_label, |
| 4502 | kEmitCompilerReadBarrier); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4503 | SlowPathCodeARM64* slow_path = |
| 4504 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4505 | codegen_->AddSlowPath(slow_path); |
| 4506 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 4507 | __ Bind(slow_path->GetExitLabel()); |
| 4508 | return; |
| 4509 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4510 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4511 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4512 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4513 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4514 | // 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] | 4515 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4516 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4517 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex()); |
| 4518 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 4519 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4520 | } |
| 4521 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4522 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4523 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4524 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4525 | } |
| 4526 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4527 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4528 | // Will be generated at use site. |
| 4529 | } |
| 4530 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4531 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4532 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4533 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4534 | InvokeRuntimeCallingConvention calling_convention; |
| 4535 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4536 | } |
| 4537 | |
| 4538 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4539 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject: kQuickUnlockObject, |
| 4540 | instruction, |
| 4541 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4542 | if (instruction->IsEnter()) { |
| 4543 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4544 | } else { |
| 4545 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4546 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4549 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4550 | LocationSummary* locations = |
| 4551 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4552 | switch (mul->GetResultType()) { |
| 4553 | case Primitive::kPrimInt: |
| 4554 | case Primitive::kPrimLong: |
| 4555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4556 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4557 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4558 | break; |
| 4559 | |
| 4560 | case Primitive::kPrimFloat: |
| 4561 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4562 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4563 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4564 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4565 | break; |
| 4566 | |
| 4567 | default: |
| 4568 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4573 | switch (mul->GetResultType()) { |
| 4574 | case Primitive::kPrimInt: |
| 4575 | case Primitive::kPrimLong: |
| 4576 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4577 | break; |
| 4578 | |
| 4579 | case Primitive::kPrimFloat: |
| 4580 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4581 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4582 | break; |
| 4583 | |
| 4584 | default: |
| 4585 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4586 | } |
| 4587 | } |
| 4588 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4589 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4590 | LocationSummary* locations = |
| 4591 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4592 | switch (neg->GetResultType()) { |
| 4593 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4594 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4595 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4596 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4597 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4598 | |
| 4599 | case Primitive::kPrimFloat: |
| 4600 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4601 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4602 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4603 | break; |
| 4604 | |
| 4605 | default: |
| 4606 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4611 | switch (neg->GetResultType()) { |
| 4612 | case Primitive::kPrimInt: |
| 4613 | case Primitive::kPrimLong: |
| 4614 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4615 | break; |
| 4616 | |
| 4617 | case Primitive::kPrimFloat: |
| 4618 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4619 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4620 | break; |
| 4621 | |
| 4622 | default: |
| 4623 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4628 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4629 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4630 | InvokeRuntimeCallingConvention calling_convention; |
| 4631 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4632 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4633 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4634 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4638 | LocationSummary* locations = instruction->GetLocations(); |
| 4639 | InvokeRuntimeCallingConvention calling_convention; |
| 4640 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4641 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4642 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4643 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4644 | // of poisoning the reference. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4645 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4646 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4649 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4650 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4651 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4652 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4653 | if (instruction->IsStringAlloc()) { |
| 4654 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4655 | } else { |
| 4656 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4657 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4658 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4659 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4663 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4664 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4665 | if (instruction->IsStringAlloc()) { |
| 4666 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4667 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4668 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4669 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4670 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4671 | __ Blr(lr); |
| 4672 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4673 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4674 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4675 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4676 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4680 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4681 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4682 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4686 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4687 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4688 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4689 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4690 | break; |
| 4691 | |
| 4692 | default: |
| 4693 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4694 | } |
| 4695 | } |
| 4696 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4697 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4698 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4699 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4700 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4701 | } |
| 4702 | |
| 4703 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4704 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4705 | } |
| 4706 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4707 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4708 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4709 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4710 | } |
| 4711 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4712 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4713 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4714 | return; |
| 4715 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4716 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4717 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4718 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4719 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4720 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4723 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4724 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4725 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4726 | |
| 4727 | LocationSummary* locations = instruction->GetLocations(); |
| 4728 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4729 | |
| 4730 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4731 | } |
| 4732 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4733 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4734 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4737 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4738 | HandleBinaryOp(instruction); |
| 4739 | } |
| 4740 | |
| 4741 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4742 | HandleBinaryOp(instruction); |
| 4743 | } |
| 4744 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4745 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4746 | LOG(FATAL) << "Unreachable"; |
| 4747 | } |
| 4748 | |
| 4749 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4750 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4751 | } |
| 4752 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4753 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4754 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4755 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4756 | if (location.IsStackSlot()) { |
| 4757 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4758 | } else if (location.IsDoubleStackSlot()) { |
| 4759 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4760 | } |
| 4761 | locations->SetOut(location); |
| 4762 | } |
| 4763 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4764 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4765 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4766 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4770 | LocationSummary* locations = |
| 4771 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4772 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4776 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4777 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4781 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4782 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4783 | locations->SetInAt(i, Location::Any()); |
| 4784 | } |
| 4785 | locations->SetOut(Location::Any()); |
| 4786 | } |
| 4787 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4788 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4789 | LOG(FATAL) << "Unreachable"; |
| 4790 | } |
| 4791 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4792 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4793 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4794 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4795 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 4796 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4797 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4798 | |
| 4799 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4800 | case Primitive::kPrimInt: |
| 4801 | case Primitive::kPrimLong: |
| 4802 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4803 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4804 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4805 | break; |
| 4806 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4807 | case Primitive::kPrimFloat: |
| 4808 | case Primitive::kPrimDouble: { |
| 4809 | InvokeRuntimeCallingConvention calling_convention; |
| 4810 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4811 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4812 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4813 | |
| 4814 | break; |
| 4815 | } |
| 4816 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4817 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4818 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4823 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4824 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4825 | switch (type) { |
| 4826 | case Primitive::kPrimInt: |
| 4827 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4828 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4829 | break; |
| 4830 | } |
| 4831 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4832 | case Primitive::kPrimFloat: |
| 4833 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4834 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 4835 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4836 | if (type == Primitive::kPrimFloat) { |
| 4837 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4838 | } else { |
| 4839 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4840 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4841 | break; |
| 4842 | } |
| 4843 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4844 | default: |
| 4845 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4846 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4847 | } |
| 4848 | } |
| 4849 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4850 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4851 | memory_barrier->SetLocations(nullptr); |
| 4852 | } |
| 4853 | |
| 4854 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4855 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4856 | } |
| 4857 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4858 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4859 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4860 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4861 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4862 | } |
| 4863 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4864 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4865 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4869 | instruction->SetLocations(nullptr); |
| 4870 | } |
| 4871 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4872 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4873 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4874 | } |
| 4875 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4876 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4877 | HandleBinaryOp(ror); |
| 4878 | } |
| 4879 | |
| 4880 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4881 | HandleBinaryOp(ror); |
| 4882 | } |
| 4883 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4884 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4885 | HandleShift(shl); |
| 4886 | } |
| 4887 | |
| 4888 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4889 | HandleShift(shl); |
| 4890 | } |
| 4891 | |
| 4892 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4893 | HandleShift(shr); |
| 4894 | } |
| 4895 | |
| 4896 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4897 | HandleShift(shr); |
| 4898 | } |
| 4899 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4900 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4901 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4905 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4906 | } |
| 4907 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4908 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4909 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4913 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4917 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4918 | } |
| 4919 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4920 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4921 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4922 | } |
| 4923 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4924 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4925 | HUnresolvedInstanceFieldGet* instruction) { |
| 4926 | FieldAccessCallingConventionARM64 calling_convention; |
| 4927 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4928 | instruction, instruction->GetFieldType(), calling_convention); |
| 4929 | } |
| 4930 | |
| 4931 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4932 | HUnresolvedInstanceFieldGet* instruction) { |
| 4933 | FieldAccessCallingConventionARM64 calling_convention; |
| 4934 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4935 | instruction->GetFieldType(), |
| 4936 | instruction->GetFieldIndex(), |
| 4937 | instruction->GetDexPc(), |
| 4938 | calling_convention); |
| 4939 | } |
| 4940 | |
| 4941 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4942 | HUnresolvedInstanceFieldSet* instruction) { |
| 4943 | FieldAccessCallingConventionARM64 calling_convention; |
| 4944 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4945 | instruction, instruction->GetFieldType(), calling_convention); |
| 4946 | } |
| 4947 | |
| 4948 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4949 | HUnresolvedInstanceFieldSet* instruction) { |
| 4950 | FieldAccessCallingConventionARM64 calling_convention; |
| 4951 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4952 | instruction->GetFieldType(), |
| 4953 | instruction->GetFieldIndex(), |
| 4954 | instruction->GetDexPc(), |
| 4955 | calling_convention); |
| 4956 | } |
| 4957 | |
| 4958 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4959 | HUnresolvedStaticFieldGet* instruction) { |
| 4960 | FieldAccessCallingConventionARM64 calling_convention; |
| 4961 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4962 | instruction, instruction->GetFieldType(), calling_convention); |
| 4963 | } |
| 4964 | |
| 4965 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4966 | HUnresolvedStaticFieldGet* instruction) { |
| 4967 | FieldAccessCallingConventionARM64 calling_convention; |
| 4968 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4969 | instruction->GetFieldType(), |
| 4970 | instruction->GetFieldIndex(), |
| 4971 | instruction->GetDexPc(), |
| 4972 | calling_convention); |
| 4973 | } |
| 4974 | |
| 4975 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4976 | HUnresolvedStaticFieldSet* instruction) { |
| 4977 | FieldAccessCallingConventionARM64 calling_convention; |
| 4978 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4979 | instruction, instruction->GetFieldType(), calling_convention); |
| 4980 | } |
| 4981 | |
| 4982 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4983 | HUnresolvedStaticFieldSet* instruction) { |
| 4984 | FieldAccessCallingConventionARM64 calling_convention; |
| 4985 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4986 | instruction->GetFieldType(), |
| 4987 | instruction->GetFieldIndex(), |
| 4988 | instruction->GetDexPc(), |
| 4989 | calling_convention); |
| 4990 | } |
| 4991 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4992 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4993 | LocationSummary* locations = |
| 4994 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4995 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4999 | HBasicBlock* block = instruction->GetBlock(); |
| 5000 | if (block->GetLoopInformation() != nullptr) { |
| 5001 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5002 | // The back edge will generate the suspend check. |
| 5003 | return; |
| 5004 | } |
| 5005 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5006 | // The goto will generate the suspend check. |
| 5007 | return; |
| 5008 | } |
| 5009 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5012 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5013 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5014 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5015 | InvokeRuntimeCallingConvention calling_convention; |
| 5016 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5017 | } |
| 5018 | |
| 5019 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5020 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5021 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5025 | LocationSummary* locations = |
| 5026 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5027 | Primitive::Type input_type = conversion->GetInputType(); |
| 5028 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5029 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5030 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5031 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5032 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5033 | } |
| 5034 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5035 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5036 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5037 | } else { |
| 5038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5039 | } |
| 5040 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5041 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5042 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5043 | } else { |
| 5044 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5045 | } |
| 5046 | } |
| 5047 | |
| 5048 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5049 | Primitive::Type result_type = conversion->GetResultType(); |
| 5050 | Primitive::Type input_type = conversion->GetInputType(); |
| 5051 | |
| 5052 | DCHECK_NE(input_type, result_type); |
| 5053 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5054 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5055 | int result_size = Primitive::ComponentSize(result_type); |
| 5056 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5057 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5058 | Register output = OutputRegister(conversion); |
| 5059 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5060 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5061 | // 'int' values are used directly as W registers, discarding the top |
| 5062 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5063 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5064 | // top 32 bits of the target register. We theoretically could leave those |
| 5065 | // bits unchanged, but we would have to make sure that no code uses a |
| 5066 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5067 | // zero. |
| 5068 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5069 | } else if (result_type == Primitive::kPrimChar || |
| 5070 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5071 | __ Ubfx(output, |
| 5072 | output.IsX() ? source.X() : source.W(), |
| 5073 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5074 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5075 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5076 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5077 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5078 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5079 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5080 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5081 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5082 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5083 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5084 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5085 | } else { |
| 5086 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5087 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5088 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5089 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5090 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5091 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5092 | HandleShift(ushr); |
| 5093 | } |
| 5094 | |
| 5095 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5096 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5100 | HandleBinaryOp(instruction); |
| 5101 | } |
| 5102 | |
| 5103 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5104 | HandleBinaryOp(instruction); |
| 5105 | } |
| 5106 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5107 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5108 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5109 | LOG(FATAL) << "Unreachable"; |
| 5110 | } |
| 5111 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5112 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5113 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5114 | LOG(FATAL) << "Unreachable"; |
| 5115 | } |
| 5116 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5117 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5118 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5119 | LocationSummary* locations = |
| 5120 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5122 | } |
| 5123 | |
| 5124 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5125 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5126 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5127 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5128 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5129 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5130 | // 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] | 5131 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5132 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5133 | // make sure we don't emit it if the target may run out of range. |
| 5134 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5135 | // ranges and emit the tables only as required. |
| 5136 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5137 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5138 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5139 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5140 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5141 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5142 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5143 | Register temp = temps.AcquireW(); |
| 5144 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5145 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5146 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5147 | // Jump to successors[0] if value == lower_bound. |
| 5148 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5149 | int32_t last_index = 0; |
| 5150 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5151 | __ Subs(temp, temp, Operand(2)); |
| 5152 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5153 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5154 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5155 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5156 | } |
| 5157 | if (num_entries - last_index == 2) { |
| 5158 | // The last missing case_value. |
| 5159 | __ Cmp(temp, Operand(1)); |
| 5160 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | // And the default for any other value. |
| 5164 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5165 | __ B(codegen_->GetLabelOf(default_block)); |
| 5166 | } |
| 5167 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5168 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5169 | |
| 5170 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5171 | |
| 5172 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5173 | // registers, we are free to block one. |
| 5174 | Register temp_w = temps.AcquireW(); |
| 5175 | Register index; |
| 5176 | // Remove the bias. |
| 5177 | if (lower_bound != 0) { |
| 5178 | index = temp_w; |
| 5179 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5180 | } else { |
| 5181 | index = value_reg; |
| 5182 | } |
| 5183 | |
| 5184 | // Jump to default block if index is out of the range. |
| 5185 | __ Cmp(index, Operand(num_entries)); |
| 5186 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5187 | |
| 5188 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5189 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5190 | // register pressure. |
| 5191 | Register table_base = temps.AcquireX(); |
| 5192 | // Load jump offset from the table. |
| 5193 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5194 | Register jump_offset = temp_w; |
| 5195 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5196 | |
| 5197 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5198 | Register target_address = table_base; |
| 5199 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5200 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5204 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 5205 | Location out, |
| 5206 | uint32_t offset, |
| 5207 | Location maybe_temp) { |
| 5208 | Primitive::Type type = Primitive::kPrimNot; |
| 5209 | Register out_reg = RegisterFrom(out, type); |
| 5210 | if (kEmitCompilerReadBarrier) { |
| 5211 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5212 | if (kUseBakerReadBarrier) { |
| 5213 | // Load with fast path based Baker's read barrier. |
| 5214 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5215 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5216 | out, |
| 5217 | out_reg, |
| 5218 | offset, |
| 5219 | temp_reg, |
| 5220 | /* needs_null_check */ false, |
| 5221 | /* use_load_acquire */ false); |
| 5222 | } else { |
| 5223 | // Load with slow path based read barrier. |
| 5224 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5225 | // in the following move operation, as we will need it for the |
| 5226 | // read barrier below. |
| 5227 | __ Mov(temp_reg, out_reg); |
| 5228 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5229 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5230 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5231 | } |
| 5232 | } else { |
| 5233 | // Plain load with no read barrier. |
| 5234 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5235 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5236 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 5241 | Location out, |
| 5242 | Location obj, |
| 5243 | uint32_t offset, |
| 5244 | Location maybe_temp) { |
| 5245 | Primitive::Type type = Primitive::kPrimNot; |
| 5246 | Register out_reg = RegisterFrom(out, type); |
| 5247 | Register obj_reg = RegisterFrom(obj, type); |
| 5248 | if (kEmitCompilerReadBarrier) { |
| 5249 | if (kUseBakerReadBarrier) { |
| 5250 | // Load with fast path based Baker's read barrier. |
| 5251 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5252 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5253 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5254 | out, |
| 5255 | obj_reg, |
| 5256 | offset, |
| 5257 | temp_reg, |
| 5258 | /* needs_null_check */ false, |
| 5259 | /* use_load_acquire */ false); |
| 5260 | } else { |
| 5261 | // Load with slow path based read barrier. |
| 5262 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5263 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5264 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5265 | } |
| 5266 | } else { |
| 5267 | // Plain load with no read barrier. |
| 5268 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5269 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5270 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5275 | Location root, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5276 | Register obj, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5277 | uint32_t offset, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5278 | vixl::aarch64::Label* fixup_label, |
| 5279 | bool requires_read_barrier) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5280 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5281 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5282 | if (requires_read_barrier) { |
| 5283 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5284 | if (kUseBakerReadBarrier) { |
| 5285 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5286 | // Baker's read barrier are used: |
| 5287 | // |
| 5288 | // root = obj.field; |
| 5289 | // if (Thread::Current()->GetIsGcMarking()) { |
| 5290 | // root = ReadBarrier::Mark(root) |
| 5291 | // } |
| 5292 | |
| 5293 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5294 | if (fixup_label == nullptr) { |
| 5295 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5296 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5297 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5298 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5299 | static_assert( |
| 5300 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5301 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5302 | "have different sizes."); |
| 5303 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5304 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5305 | "have different sizes."); |
| 5306 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5307 | // Slow path marking the GC root `root`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5308 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5309 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5310 | codegen_->AddSlowPath(slow_path); |
| 5311 | |
| 5312 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5313 | UseScratchRegisterScope temps(masm); |
| 5314 | Register temp = temps.AcquireW(); |
| 5315 | // temp = Thread::Current()->GetIsGcMarking() |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5316 | __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5317 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5318 | __ Bind(slow_path->GetExitLabel()); |
| 5319 | } else { |
| 5320 | // GC root loaded through a slow path for read barriers other |
| 5321 | // than Baker's. |
| 5322 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5323 | if (fixup_label == nullptr) { |
| 5324 | __ Add(root_reg.X(), obj.X(), offset); |
| 5325 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5326 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5327 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5328 | // /* mirror::Object* */ root = root->Read() |
| 5329 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5330 | } |
| 5331 | } else { |
| 5332 | // Plain GC root load with no read barrier. |
| 5333 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5334 | if (fixup_label == nullptr) { |
| 5335 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5336 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5337 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5338 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5339 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5340 | // do not have to unpoison `root_reg` here. |
| 5341 | } |
| 5342 | } |
| 5343 | |
| 5344 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5345 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5346 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5347 | uint32_t offset, |
| 5348 | Register temp, |
| 5349 | bool needs_null_check, |
| 5350 | bool use_load_acquire) { |
| 5351 | DCHECK(kEmitCompilerReadBarrier); |
| 5352 | DCHECK(kUseBakerReadBarrier); |
| 5353 | |
| 5354 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5355 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5356 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5357 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5358 | ref, |
| 5359 | obj, |
| 5360 | offset, |
| 5361 | no_index, |
| 5362 | no_scale_factor, |
| 5363 | temp, |
| 5364 | needs_null_check, |
| 5365 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5369 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5370 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5371 | uint32_t data_offset, |
| 5372 | Location index, |
| 5373 | Register temp, |
| 5374 | bool needs_null_check) { |
| 5375 | DCHECK(kEmitCompilerReadBarrier); |
| 5376 | DCHECK(kUseBakerReadBarrier); |
| 5377 | |
| 5378 | // Array cells are never volatile variables, therefore array loads |
| 5379 | // never use Load-Acquire instructions on ARM64. |
| 5380 | const bool use_load_acquire = false; |
| 5381 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5382 | static_assert( |
| 5383 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5384 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5385 | // /* HeapReference<Object> */ ref = |
| 5386 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5387 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5388 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5389 | ref, |
| 5390 | obj, |
| 5391 | data_offset, |
| 5392 | index, |
| 5393 | scale_factor, |
| 5394 | temp, |
| 5395 | needs_null_check, |
| 5396 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5400 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5401 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5402 | uint32_t offset, |
| 5403 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5404 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5405 | Register temp, |
| 5406 | bool needs_null_check, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5407 | bool use_load_acquire, |
| 5408 | bool always_update_field) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5409 | DCHECK(kEmitCompilerReadBarrier); |
| 5410 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5411 | // If we are emitting an array load, we should not be using a |
| 5412 | // Load Acquire instruction. In other words: |
| 5413 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5414 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5415 | |
| 5416 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5417 | UseScratchRegisterScope temps(masm); |
| 5418 | |
| 5419 | // In slow path based read barriers, the read barrier call is |
| 5420 | // inserted after the original load. However, in fast path based |
| 5421 | // Baker's read barriers, we need to perform the load of |
| 5422 | // mirror::Object::monitor_ *before* the original reference load. |
| 5423 | // This load-load ordering is required by the read barrier. |
| 5424 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5425 | // |
| 5426 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5427 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5428 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5429 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 5430 | // if (is_gray) { |
| 5431 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5432 | // } |
| 5433 | // |
| 5434 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5435 | // slightly more complex as it performs additional checks that we do |
| 5436 | // not do here for performance reasons. |
| 5437 | |
| 5438 | Primitive::Type type = Primitive::kPrimNot; |
| 5439 | Register ref_reg = RegisterFrom(ref, type); |
| 5440 | DCHECK(obj.IsW()); |
| 5441 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5442 | |
| 5443 | // /* int32_t */ monitor = obj->monitor_ |
| 5444 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5445 | if (needs_null_check) { |
| 5446 | MaybeRecordImplicitNullCheck(instruction); |
| 5447 | } |
| 5448 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5449 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5450 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5451 | |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5452 | // Introduce a dependency on the lock_word including rb_state, |
| 5453 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5454 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5455 | // `obj` is unchanged by this operation, but its value now depends |
| 5456 | // on `temp`. |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5457 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5458 | |
| 5459 | // The actual reference load. |
| 5460 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5461 | // Load types involving an "index": ArrayGet, |
| 5462 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5463 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5464 | if (use_load_acquire) { |
| 5465 | // UnsafeGetObjectVolatile intrinsic case. |
| 5466 | // Register `index` is not an index in an object array, but an |
| 5467 | // offset to an object reference field within object `obj`. |
| 5468 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5469 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5470 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5471 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5472 | DCHECK_EQ(offset, 0u); |
| 5473 | DCHECK_EQ(scale_factor, 0u); |
| 5474 | DCHECK_EQ(needs_null_check, 0u); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5475 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5476 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5477 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5478 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5479 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5480 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5481 | if (index.IsConstant()) { |
| 5482 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5483 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5484 | } else { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5485 | Register temp3 = temps.AcquireW(); |
| 5486 | __ Add(temp3, obj, offset); |
| 5487 | Load(type, ref_reg, HeapOperand(temp3, XRegisterFrom(index), LSL, scale_factor)); |
| 5488 | temps.Release(temp3); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5489 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5490 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5491 | } else { |
| 5492 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5493 | MemOperand field = HeapOperand(obj, offset); |
| 5494 | if (use_load_acquire) { |
| 5495 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5496 | } else { |
| 5497 | Load(type, ref_reg, field); |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5502 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5503 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5504 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5505 | SlowPathCodeARM64* slow_path; |
| 5506 | if (always_update_field) { |
| 5507 | // ReadBarrierMarkAndUpdateFieldSlowPathARM64 only supports |
| 5508 | // address of the form `obj + field_offset`, where `obj` is a |
| 5509 | // register and `field_offset` is a register. Thus `offset` and |
| 5510 | // `scale_factor` above are expected to be null in this code path. |
| 5511 | DCHECK_EQ(offset, 0u); |
| 5512 | DCHECK_EQ(scale_factor, 0u); /* "times 1" */ |
| 5513 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM64( |
| 5514 | instruction, ref, obj, /* field_offset */ index, temp); |
| 5515 | } else { |
| 5516 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
| 5517 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5518 | AddSlowPath(slow_path); |
| 5519 | |
| 5520 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 5521 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5522 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 5523 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 5524 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 5525 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 5526 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5527 | __ Bind(slow_path->GetExitLabel()); |
| 5528 | } |
| 5529 | |
| 5530 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5531 | Location out, |
| 5532 | Location ref, |
| 5533 | Location obj, |
| 5534 | uint32_t offset, |
| 5535 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5536 | DCHECK(kEmitCompilerReadBarrier); |
| 5537 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5538 | // Insert a slow path based read barrier *after* the reference load. |
| 5539 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5540 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5541 | // reference will be carried out by the runtime within the slow |
| 5542 | // path. |
| 5543 | // |
| 5544 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5545 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5546 | // not used by the artReadBarrierSlow entry point. |
| 5547 | // |
| 5548 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5549 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5550 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5551 | AddSlowPath(slow_path); |
| 5552 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5553 | __ B(slow_path->GetEntryLabel()); |
| 5554 | __ Bind(slow_path->GetExitLabel()); |
| 5555 | } |
| 5556 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5557 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5558 | Location out, |
| 5559 | Location ref, |
| 5560 | Location obj, |
| 5561 | uint32_t offset, |
| 5562 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5563 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5564 | // Baker's read barriers shall be handled by the fast path |
| 5565 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5566 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5567 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5568 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5569 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5570 | } else if (kPoisonHeapReferences) { |
| 5571 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5572 | } |
| 5573 | } |
| 5574 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5575 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5576 | Location out, |
| 5577 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5578 | DCHECK(kEmitCompilerReadBarrier); |
| 5579 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5580 | // Insert a slow path based read barrier *after* the GC root load. |
| 5581 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5582 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5583 | // not need to do anything special for this here. |
| 5584 | SlowPathCodeARM64* slow_path = |
| 5585 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5586 | AddSlowPath(slow_path); |
| 5587 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5588 | __ B(slow_path->GetEntryLabel()); |
| 5589 | __ Bind(slow_path->GetExitLabel()); |
| 5590 | } |
| 5591 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5592 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5593 | LocationSummary* locations = |
| 5594 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5595 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5596 | locations->SetOut(Location::RequiresRegister()); |
| 5597 | } |
| 5598 | |
| 5599 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5600 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5601 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5602 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5603 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5604 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5605 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5606 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5607 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5608 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5609 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5610 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5611 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5612 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5613 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | |
| 5617 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5618 | #undef __ |
| 5619 | #undef QUICK_ENTRY_POINT |
| 5620 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5621 | } // namespace arm64 |
| 5622 | } // namespace art |