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 | |
| 36 | |
| 37 | using namespace vixl; // NOLINT(build/namespaces) |
| 38 | |
| 39 | #ifdef __ |
| 40 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 41 | #endif |
| 42 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 43 | namespace art { |
| 44 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 45 | template<class MirrorType> |
| 46 | class GcRoot; |
| 47 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | namespace arm64 { |
| 49 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 50 | using helpers::CPURegisterFrom; |
| 51 | using helpers::DRegisterFrom; |
| 52 | using helpers::FPRegisterFrom; |
| 53 | using helpers::HeapOperand; |
| 54 | using helpers::HeapOperandFrom; |
| 55 | using helpers::InputCPURegisterAt; |
| 56 | using helpers::InputFPRegisterAt; |
| 57 | using helpers::InputRegisterAt; |
| 58 | using helpers::InputOperandAt; |
| 59 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 60 | using helpers::LocationFrom; |
| 61 | using helpers::OperandFromMemOperand; |
| 62 | using helpers::OutputCPURegister; |
| 63 | using helpers::OutputFPRegister; |
| 64 | using helpers::OutputRegister; |
| 65 | using helpers::RegisterFrom; |
| 66 | using helpers::StackOperandFrom; |
| 67 | using helpers::VIXLRegCodeFromART; |
| 68 | using helpers::WRegisterFrom; |
| 69 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 70 | using helpers::ARM64EncodableConstantOrRegister; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 71 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 73 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 74 | // 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] | 75 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 76 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 77 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 78 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 79 | inline Condition ARM64Condition(IfCondition cond) { |
| 80 | switch (cond) { |
| 81 | case kCondEQ: return eq; |
| 82 | case kCondNE: return ne; |
| 83 | case kCondLT: return lt; |
| 84 | case kCondLE: return le; |
| 85 | case kCondGT: return gt; |
| 86 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 87 | case kCondB: return lo; |
| 88 | case kCondBE: return ls; |
| 89 | case kCondA: return hi; |
| 90 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 91 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 92 | LOG(FATAL) << "Unreachable"; |
| 93 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 96 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 97 | // The ARM64 condition codes can express all the necessary branches, see the |
| 98 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 99 | // There is no dex instruction or HIR that would need the missing conditions |
| 100 | // "equal or unordered" or "not equal". |
| 101 | switch (cond) { |
| 102 | case kCondEQ: return eq; |
| 103 | case kCondNE: return ne /* unordered */; |
| 104 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 105 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 106 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 107 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 108 | default: |
| 109 | LOG(FATAL) << "UNREACHABLE"; |
| 110 | UNREACHABLE(); |
| 111 | } |
| 112 | } |
| 113 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 114 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 115 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 116 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 117 | // but we use the exact registers for clarity. |
| 118 | if (return_type == Primitive::kPrimFloat) { |
| 119 | return LocationFrom(s0); |
| 120 | } else if (return_type == Primitive::kPrimDouble) { |
| 121 | return LocationFrom(d0); |
| 122 | } else if (return_type == Primitive::kPrimLong) { |
| 123 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 124 | } else if (return_type == Primitive::kPrimVoid) { |
| 125 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 126 | } else { |
| 127 | return LocationFrom(w0); |
| 128 | } |
| 129 | } |
| 130 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 131 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 132 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 135 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> |
| 136 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 137 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 138 | // Calculate memory accessing operand for save/restore live registers. |
| 139 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| 140 | RegisterSet* register_set, |
| 141 | int64_t spill_offset, |
| 142 | bool is_save) { |
| 143 | DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(), |
| 144 | codegen->GetNumberOfCoreRegisters(), |
| 145 | register_set->GetFloatingPointRegisters(), |
| 146 | codegen->GetNumberOfFloatingPointRegisters())); |
| 147 | |
| 148 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, |
| 149 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.list())); |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 150 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 151 | register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.list())); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 152 | |
| 153 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 154 | UseScratchRegisterScope temps(masm); |
| 155 | |
| 156 | Register base = masm->StackPointer(); |
| 157 | int64_t core_spill_size = core_list.TotalSizeInBytes(); |
| 158 | int64_t fp_spill_size = fp_list.TotalSizeInBytes(); |
| 159 | int64_t reg_size = kXRegSizeInBytes; |
| 160 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 161 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| 162 | if (((core_list.Count() > 1) || (fp_list.Count() > 1)) && |
| 163 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 164 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 165 | // to compute the base address(float point registers spill base address). |
| 166 | Register new_base = temps.AcquireSameSizeAs(base); |
| 167 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 168 | base = new_base; |
| 169 | spill_offset = -core_spill_size; |
| 170 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 171 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 172 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 173 | } |
| 174 | |
| 175 | if (is_save) { |
| 176 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 177 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 178 | } else { |
| 179 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 180 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 185 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 186 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 187 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 188 | if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) { |
| 189 | // If the register holds an object, update the stack mask. |
| 190 | if (locations->RegisterContainsObject(i)) { |
| 191 | locations->SetStackBit(stack_offset / kVRegSize); |
| 192 | } |
| 193 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 194 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 195 | saved_core_stack_offsets_[i] = stack_offset; |
| 196 | stack_offset += kXRegSizeInBytes; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 201 | if (!codegen->IsFloatingPointCalleeSaveRegister(i) && |
| 202 | register_set->ContainsFloatingPointRegister(i)) { |
| 203 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 204 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 205 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 206 | stack_offset += kDRegSizeInBytes; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 211 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 212 | } |
| 213 | |
| 214 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 215 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 216 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 217 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 218 | } |
| 219 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 220 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 221 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 222 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 223 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 224 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 225 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 226 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 227 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 228 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 229 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 230 | // Live registers will be restored in the catch block if caught. |
| 231 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 232 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 233 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 234 | // move resolver. |
| 235 | InvokeRuntimeCallingConvention calling_convention; |
| 236 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 237 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 238 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 239 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 240 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 241 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 244 | bool IsFatal() const OVERRIDE { return true; } |
| 245 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 246 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 247 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 248 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 250 | }; |
| 251 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 252 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 253 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 254 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 255 | |
| 256 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 257 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 258 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 259 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 260 | // Live registers will be restored in the catch block if caught. |
| 261 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 262 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 263 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 264 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 265 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 268 | bool IsFatal() const OVERRIDE { return true; } |
| 269 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 270 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 271 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 272 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 273 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 274 | }; |
| 275 | |
| 276 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 277 | public: |
| 278 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 279 | HInstruction* at, |
| 280 | uint32_t dex_pc, |
| 281 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 282 | : 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] | 283 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 284 | } |
| 285 | |
| 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 287 | LocationSummary* locations = at_->GetLocations(); |
| 288 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 289 | |
| 290 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 291 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | |
| 293 | InvokeRuntimeCallingConvention calling_convention; |
| 294 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 296 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 297 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 298 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 300 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 301 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 302 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 303 | |
| 304 | // Move the class to the desired location. |
| 305 | Location out = locations->Out(); |
| 306 | if (out.IsValid()) { |
| 307 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 308 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 309 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 312 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 313 | __ B(GetExitLabel()); |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 317 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 318 | private: |
| 319 | // The class this slow path will load. |
| 320 | HLoadClass* const cls_; |
| 321 | |
| 322 | // The instruction where this slow path is happening. |
| 323 | // (Might be the load class or an initialization check). |
| 324 | HInstruction* const at_; |
| 325 | |
| 326 | // The dex PC of `at_`. |
| 327 | const uint32_t dex_pc_; |
| 328 | |
| 329 | // Whether to initialize the class. |
| 330 | const bool do_clinit_; |
| 331 | |
| 332 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 333 | }; |
| 334 | |
| 335 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 336 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 337 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +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 | |
| 344 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 345 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 346 | |
| 347 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 348 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 349 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 350 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 351 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 352 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 353 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 354 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 356 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 357 | __ B(GetExitLabel()); |
| 358 | } |
| 359 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 360 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 361 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 362 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 363 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 364 | }; |
| 365 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 366 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 367 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 368 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 369 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 370 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 371 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 372 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 373 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 374 | // Live registers will be restored in the catch block if caught. |
| 375 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 376 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 377 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 378 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 379 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 382 | bool IsFatal() const OVERRIDE { return true; } |
| 383 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 384 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 385 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 386 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 387 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 388 | }; |
| 389 | |
| 390 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 391 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 392 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
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()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 398 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 399 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 400 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 401 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 402 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 403 | if (successor_ == nullptr) { |
| 404 | __ B(GetReturnLabel()); |
| 405 | } else { |
| 406 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 407 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | vixl::Label* GetReturnLabel() { |
| 411 | DCHECK(successor_ == nullptr); |
| 412 | return &return_label_; |
| 413 | } |
| 414 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 415 | HBasicBlock* GetSuccessor() const { |
| 416 | return successor_; |
| 417 | } |
| 418 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 419 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 420 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 421 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | // If not null, the block to branch to after the suspend check. |
| 423 | HBasicBlock* const successor_; |
| 424 | |
| 425 | // If `successor_` is null, the label to branch to after the suspend check. |
| 426 | vixl::Label return_label_; |
| 427 | |
| 428 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 429 | }; |
| 430 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 431 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 432 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 433 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 434 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 435 | |
| 436 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 437 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 438 | Location class_to_check = locations->InAt(1); |
| 439 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 440 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 441 | DCHECK(instruction_->IsCheckCast() |
| 442 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 443 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 444 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 445 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 446 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 447 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 448 | if (!is_fatal_) { |
| 449 | SaveLiveRegisters(codegen, locations); |
| 450 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 451 | |
| 452 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 453 | // move resolver. |
| 454 | InvokeRuntimeCallingConvention calling_convention; |
| 455 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 456 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 457 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 458 | |
| 459 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 460 | arm64_codegen->InvokeRuntime( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 461 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 462 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t, |
| 463 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 464 | Primitive::Type ret_type = instruction_->GetType(); |
| 465 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 466 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 467 | } else { |
| 468 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 469 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 470 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 473 | if (!is_fatal_) { |
| 474 | RestoreLiveRegisters(codegen, locations); |
| 475 | __ B(GetExitLabel()); |
| 476 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 479 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 480 | bool IsFatal() const { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 481 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 482 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 483 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 484 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 486 | }; |
| 487 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 488 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 489 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 490 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 491 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 492 | |
| 493 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 494 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 495 | __ Bind(GetEntryLabel()); |
| 496 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 497 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 498 | instruction_, |
| 499 | instruction_->GetDexPc(), |
| 500 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 501 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 504 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 505 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 506 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 507 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 508 | }; |
| 509 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 510 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 511 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 512 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 513 | |
| 514 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 515 | LocationSummary* locations = instruction_->GetLocations(); |
| 516 | __ Bind(GetEntryLabel()); |
| 517 | SaveLiveRegisters(codegen, locations); |
| 518 | |
| 519 | InvokeRuntimeCallingConvention calling_convention; |
| 520 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 521 | parallel_move.AddMove( |
| 522 | locations->InAt(0), |
| 523 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 524 | Primitive::kPrimNot, |
| 525 | nullptr); |
| 526 | parallel_move.AddMove( |
| 527 | locations->InAt(1), |
| 528 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 529 | Primitive::kPrimInt, |
| 530 | nullptr); |
| 531 | parallel_move.AddMove( |
| 532 | locations->InAt(2), |
| 533 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 534 | Primitive::kPrimNot, |
| 535 | nullptr); |
| 536 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 537 | |
| 538 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 539 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 540 | instruction_, |
| 541 | instruction_->GetDexPc(), |
| 542 | this); |
| 543 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 544 | RestoreLiveRegisters(codegen, locations); |
| 545 | __ B(GetExitLabel()); |
| 546 | } |
| 547 | |
| 548 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 549 | |
| 550 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 551 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 552 | }; |
| 553 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 554 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 555 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 556 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 557 | |
| 558 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 559 | // underlying code buffer and we have generated the jump table with right size. |
| 560 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 561 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 562 | |
| 563 | __ Bind(&table_start_); |
| 564 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 565 | for (uint32_t i = 0; i < num_entries; i++) { |
| 566 | vixl::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 567 | DCHECK(target_label->IsBound()); |
| 568 | ptrdiff_t jump_offset = target_label->location() - table_start_.location(); |
| 569 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 570 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 571 | Literal<int32_t> literal(jump_offset); |
| 572 | __ place(&literal); |
| 573 | } |
| 574 | } |
| 575 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 576 | // Slow path marking an object during a read barrier. |
| 577 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 578 | public: |
| 579 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 580 | : SlowPathCodeARM64(instruction), out_(out), obj_(obj) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 581 | DCHECK(kEmitCompilerReadBarrier); |
| 582 | } |
| 583 | |
| 584 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 585 | |
| 586 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 587 | LocationSummary* locations = instruction_->GetLocations(); |
| 588 | Primitive::Type type = Primitive::kPrimNot; |
| 589 | DCHECK(locations->CanCall()); |
| 590 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| 591 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 592 | instruction_->IsStaticFieldGet() || |
| 593 | instruction_->IsArrayGet() || |
| 594 | instruction_->IsLoadClass() || |
| 595 | instruction_->IsLoadString() || |
| 596 | instruction_->IsInstanceOf() || |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 597 | instruction_->IsCheckCast() || |
| 598 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
| 599 | instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 600 | << "Unexpected instruction in read barrier marking slow path: " |
| 601 | << instruction_->DebugName(); |
| 602 | |
| 603 | __ Bind(GetEntryLabel()); |
| 604 | SaveLiveRegisters(codegen, locations); |
| 605 | |
| 606 | InvokeRuntimeCallingConvention calling_convention; |
| 607 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 608 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), obj_, type); |
| 609 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 610 | instruction_, |
| 611 | instruction_->GetDexPc(), |
| 612 | this); |
| 613 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 614 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 615 | |
| 616 | RestoreLiveRegisters(codegen, locations); |
| 617 | __ B(GetExitLabel()); |
| 618 | } |
| 619 | |
| 620 | private: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 621 | const Location out_; |
| 622 | const Location obj_; |
| 623 | |
| 624 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 625 | }; |
| 626 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 627 | // Slow path generating a read barrier for a heap reference. |
| 628 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 629 | public: |
| 630 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 631 | Location out, |
| 632 | Location ref, |
| 633 | Location obj, |
| 634 | uint32_t offset, |
| 635 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 636 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 637 | out_(out), |
| 638 | ref_(ref), |
| 639 | obj_(obj), |
| 640 | offset_(offset), |
| 641 | index_(index) { |
| 642 | DCHECK(kEmitCompilerReadBarrier); |
| 643 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 644 | // has been overwritten by (or after) the heap object reference load |
| 645 | // to be instrumented, e.g.: |
| 646 | // |
| 647 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 648 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 649 | // |
| 650 | // In that case, we have lost the information about the original |
| 651 | // object, and the emitted read barrier cannot work properly. |
| 652 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 653 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 654 | } |
| 655 | |
| 656 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 657 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 658 | LocationSummary* locations = instruction_->GetLocations(); |
| 659 | Primitive::Type type = Primitive::kPrimNot; |
| 660 | DCHECK(locations->CanCall()); |
| 661 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 662 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 663 | instruction_->IsStaticFieldGet() || |
| 664 | instruction_->IsArrayGet() || |
| 665 | instruction_->IsInstanceOf() || |
| 666 | instruction_->IsCheckCast() || |
| 667 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 668 | instruction_->GetLocations()->Intrinsified())) |
| 669 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 670 | << instruction_->DebugName(); |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 671 | // The read barrier instrumentation does not support the |
| 672 | // HArm64IntermediateAddress instruction yet. |
| 673 | DCHECK(!(instruction_->IsArrayGet() && |
| 674 | instruction_->AsArrayGet()->GetArray()->IsArm64IntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 675 | |
| 676 | __ Bind(GetEntryLabel()); |
| 677 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 678 | SaveLiveRegisters(codegen, locations); |
| 679 | |
| 680 | // We may have to change the index's value, but as `index_` is a |
| 681 | // constant member (like other "inputs" of this slow path), |
| 682 | // introduce a copy of it, `index`. |
| 683 | Location index = index_; |
| 684 | if (index_.IsValid()) { |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 685 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 686 | if (instruction_->IsArrayGet()) { |
| 687 | // Compute the actual memory offset and store it in `index`. |
| 688 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 689 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 690 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 691 | // We are about to change the value of `index_reg` (see the |
| 692 | // calls to vixl::MacroAssembler::Lsl and |
| 693 | // vixl::MacroAssembler::Mov below), but it has |
| 694 | // not been saved by the previous call to |
| 695 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 696 | // callee-save register -- |
| 697 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 698 | // callee-save registers, as it has been designed with the |
| 699 | // assumption that callee-save registers are supposed to be |
| 700 | // handled by the called function. So, as a callee-save |
| 701 | // register, `index_reg` _would_ eventually be saved onto |
| 702 | // the stack, but it would be too late: we would have |
| 703 | // changed its value earlier. Therefore, we manually save |
| 704 | // it here into another freely available register, |
| 705 | // `free_reg`, chosen of course among the caller-save |
| 706 | // registers (as a callee-save `free_reg` register would |
| 707 | // exhibit the same problem). |
| 708 | // |
| 709 | // Note we could have requested a temporary register from |
| 710 | // the register allocator instead; but we prefer not to, as |
| 711 | // this is a slow path, and we know we can find a |
| 712 | // caller-save register that is available. |
| 713 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 714 | __ Mov(free_reg.W(), index_reg); |
| 715 | index_reg = free_reg; |
| 716 | index = LocationFrom(index_reg); |
| 717 | } else { |
| 718 | // The initial register stored in `index_` has already been |
| 719 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 720 | // (as it is not a callee-save register), so we can freely |
| 721 | // use it. |
| 722 | } |
| 723 | // Shifting the index value contained in `index_reg` by the scale |
| 724 | // factor (2) cannot overflow in practice, as the runtime is |
| 725 | // unable to allocate object arrays with a size larger than |
| 726 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 727 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 728 | static_assert( |
| 729 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 730 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 731 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 732 | } else { |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 733 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 734 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 735 | // (as in the case of ArrayGet), as it is actually an offset |
| 736 | // to an object field within an object. |
| 737 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 738 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 739 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 740 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 741 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 742 | DCHECK_EQ(offset_, 0U); |
| 743 | DCHECK(index_.IsRegisterPair()); |
| 744 | // UnsafeGet's offset location is a register pair, the low |
| 745 | // part contains the correct offset. |
| 746 | index = index_.ToLow(); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | // We're moving two or three locations to locations that could |
| 751 | // overlap, so we need a parallel move resolver. |
| 752 | InvokeRuntimeCallingConvention calling_convention; |
| 753 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 754 | parallel_move.AddMove(ref_, |
| 755 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 756 | type, |
| 757 | nullptr); |
| 758 | parallel_move.AddMove(obj_, |
| 759 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 760 | type, |
| 761 | nullptr); |
| 762 | if (index.IsValid()) { |
| 763 | parallel_move.AddMove(index, |
| 764 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 765 | Primitive::kPrimInt, |
| 766 | nullptr); |
| 767 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 768 | } else { |
| 769 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 770 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 771 | } |
| 772 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 773 | instruction_, |
| 774 | instruction_->GetDexPc(), |
| 775 | this); |
| 776 | CheckEntrypointTypes< |
| 777 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 778 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 779 | |
| 780 | RestoreLiveRegisters(codegen, locations); |
| 781 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 782 | __ B(GetExitLabel()); |
| 783 | } |
| 784 | |
| 785 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 786 | |
| 787 | private: |
| 788 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 789 | size_t ref = static_cast<int>(XRegisterFrom(ref_).code()); |
| 790 | size_t obj = static_cast<int>(XRegisterFrom(obj_).code()); |
| 791 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 792 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 793 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 794 | } |
| 795 | } |
| 796 | // We shall never fail to find a free caller-save register, as |
| 797 | // there are more than two core caller-save registers on ARM64 |
| 798 | // (meaning it is possible to find one which is different from |
| 799 | // `ref` and `obj`). |
| 800 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 801 | LOG(FATAL) << "Could not find a free register"; |
| 802 | UNREACHABLE(); |
| 803 | } |
| 804 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 805 | const Location out_; |
| 806 | const Location ref_; |
| 807 | const Location obj_; |
| 808 | const uint32_t offset_; |
| 809 | // An additional location containing an index to an array. |
| 810 | // Only used for HArrayGet and the UnsafeGetObject & |
| 811 | // UnsafeGetObjectVolatile intrinsics. |
| 812 | const Location index_; |
| 813 | |
| 814 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 815 | }; |
| 816 | |
| 817 | // Slow path generating a read barrier for a GC root. |
| 818 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 819 | public: |
| 820 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 821 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 822 | DCHECK(kEmitCompilerReadBarrier); |
| 823 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 824 | |
| 825 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 826 | LocationSummary* locations = instruction_->GetLocations(); |
| 827 | Primitive::Type type = Primitive::kPrimNot; |
| 828 | DCHECK(locations->CanCall()); |
| 829 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 830 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 831 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 832 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 833 | |
| 834 | __ Bind(GetEntryLabel()); |
| 835 | SaveLiveRegisters(codegen, locations); |
| 836 | |
| 837 | InvokeRuntimeCallingConvention calling_convention; |
| 838 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 839 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 840 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 841 | // thus we need a 64-bit move here, and we cannot use |
| 842 | // |
| 843 | // arm64_codegen->MoveLocation( |
| 844 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 845 | // root_, |
| 846 | // type); |
| 847 | // |
| 848 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 849 | // reference type (`Primitive::kPrimNot`). |
| 850 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| 851 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 852 | instruction_, |
| 853 | instruction_->GetDexPc(), |
| 854 | this); |
| 855 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 856 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 857 | |
| 858 | RestoreLiveRegisters(codegen, locations); |
| 859 | __ B(GetExitLabel()); |
| 860 | } |
| 861 | |
| 862 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 863 | |
| 864 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 865 | const Location out_; |
| 866 | const Location root_; |
| 867 | |
| 868 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 869 | }; |
| 870 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 871 | #undef __ |
| 872 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 873 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 874 | Location next_location; |
| 875 | if (type == Primitive::kPrimVoid) { |
| 876 | LOG(FATAL) << "Unreachable type " << type; |
| 877 | } |
| 878 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 879 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 880 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 881 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 882 | } else if (!Primitive::IsFloatingPointType(type) && |
| 883 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 884 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 885 | } else { |
| 886 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 887 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 888 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 889 | } |
| 890 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 891 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 892 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 893 | return next_location; |
| 894 | } |
| 895 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 896 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 897 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 898 | } |
| 899 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 900 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 901 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 902 | const CompilerOptions& compiler_options, |
| 903 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 904 | : CodeGenerator(graph, |
| 905 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 906 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 907 | kNumberOfAllocatableRegisterPairs, |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 908 | callee_saved_core_registers.list(), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 909 | callee_saved_fp_registers.list(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 910 | compiler_options, |
| 911 | stats), |
Alexandre Rames | c393d63 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 912 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 913 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 914 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 915 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 916 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | d1ee809 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 917 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 918 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 919 | uint32_literals_(std::less<uint32_t>(), |
| 920 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 921 | uint64_literals_(std::less<uint64_t>(), |
| 922 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 923 | method_patches_(MethodReferenceComparator(), |
| 924 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 925 | call_patches_(MethodReferenceComparator(), |
| 926 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 927 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 928 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 929 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 930 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 931 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 932 | boot_image_address_patches_(std::less<uint32_t>(), |
| 933 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 934 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 935 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 936 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 937 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 938 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 939 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 940 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c393d63 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 941 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 942 | jump_table->EmitTable(this); |
| 943 | } |
| 944 | } |
| 945 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 946 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 947 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 948 | // Ensure we emit the literal pool. |
| 949 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 950 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 951 | CodeGenerator::Finalize(allocator); |
| 952 | } |
| 953 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 954 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 955 | // Note: There are 6 kinds of moves: |
| 956 | // 1. constant -> GPR/FPR (non-cycle) |
| 957 | // 2. constant -> stack (non-cycle) |
| 958 | // 3. GPR/FPR -> GPR/FPR |
| 959 | // 4. GPR/FPR -> stack |
| 960 | // 5. stack -> GPR/FPR |
| 961 | // 6. stack -> stack (non-cycle) |
| 962 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 963 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 964 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 965 | // dependency. |
| 966 | vixl_temps_.Open(GetVIXLAssembler()); |
| 967 | } |
| 968 | |
| 969 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 970 | vixl_temps_.Close(); |
| 971 | } |
| 972 | |
| 973 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 974 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 975 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 976 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 977 | Location scratch = GetScratchLocation(kind); |
| 978 | if (!scratch.Equals(Location::NoLocation())) { |
| 979 | return scratch; |
| 980 | } |
| 981 | // Allocate from VIXL temp registers. |
| 982 | if (kind == Location::kRegister) { |
| 983 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 984 | } else { |
| 985 | DCHECK(kind == Location::kFpuRegister); |
| 986 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 987 | } |
| 988 | AddScratchLocation(scratch); |
| 989 | return scratch; |
| 990 | } |
| 991 | |
| 992 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 993 | if (loc.IsRegister()) { |
| 994 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 995 | } else { |
| 996 | DCHECK(loc.IsFpuRegister()); |
| 997 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 998 | } |
| 999 | RemoveScratchLocation(loc); |
| 1000 | } |
| 1001 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1002 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1003 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1004 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1007 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1008 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1009 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1010 | __ Bind(&frame_entry_label_); |
| 1011 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1012 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1013 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1014 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1015 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1016 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1017 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1018 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1019 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1020 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1021 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1022 | if (!HasEmptyFrame()) { |
| 1023 | int frame_size = GetFrameSize(); |
| 1024 | // Stack layout: |
| 1025 | // sp[frame_size - 8] : lr. |
| 1026 | // ... : other preserved core registers. |
| 1027 | // ... : other preserved fp registers. |
| 1028 | // ... : reserved frame space. |
| 1029 | // sp[0] : current method. |
| 1030 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1031 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1032 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1033 | frame_size - GetCoreSpillSize()); |
| 1034 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1035 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1036 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1040 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1041 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1042 | if (!HasEmptyFrame()) { |
| 1043 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1044 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1045 | frame_size - FrameEntrySpillSize()); |
| 1046 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1047 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1048 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1049 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1050 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1051 | __ Ret(); |
| 1052 | GetAssembler()->cfi().RestoreState(); |
| 1053 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1056 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| 1057 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| 1058 | return vixl::CPURegList(vixl::CPURegister::kRegister, vixl::kXRegSize, |
| 1059 | core_spill_mask_); |
| 1060 | } |
| 1061 | |
| 1062 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| 1063 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1064 | GetNumberOfFloatingPointRegisters())); |
| 1065 | return vixl::CPURegList(vixl::CPURegister::kFPRegister, vixl::kDRegSize, |
| 1066 | fpu_spill_mask_); |
| 1067 | } |
| 1068 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1069 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1070 | __ Bind(GetLabelOf(block)); |
| 1071 | } |
| 1072 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1073 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1074 | DCHECK(location.IsRegister()); |
| 1075 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1076 | } |
| 1077 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1078 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1079 | if (location.IsRegister()) { |
| 1080 | locations->AddTemp(location); |
| 1081 | } else { |
| 1082 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1086 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1087 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1088 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1089 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1090 | vixl::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1091 | if (value_can_be_null) { |
| 1092 | __ Cbz(value, &done); |
| 1093 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1094 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 1095 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1096 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1097 | if (value_can_be_null) { |
| 1098 | __ Bind(&done); |
| 1099 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1102 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1103 | // Blocked core registers: |
| 1104 | // lr : Runtime reserved. |
| 1105 | // tr : Runtime reserved. |
| 1106 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1107 | // ip1 : VIXL core temp. |
| 1108 | // ip0 : VIXL core temp. |
| 1109 | // |
| 1110 | // Blocked fp registers: |
| 1111 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1112 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1113 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1114 | while (!reserved_core_registers.IsEmpty()) { |
| 1115 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 1116 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1117 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1118 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1119 | while (!reserved_fp_registers.IsEmpty()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1120 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 1121 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1122 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1123 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1124 | // Stubs do not save callee-save floating point registers. If the graph |
| 1125 | // is debuggable, we need to deal with these registers differently. For |
| 1126 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1127 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1128 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
| 1129 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().code()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1130 | } |
| 1131 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1132 | } |
| 1133 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1134 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1135 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1136 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1137 | return kArm64WordSize; |
| 1138 | } |
| 1139 | |
| 1140 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1141 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1142 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1143 | return kArm64WordSize; |
| 1144 | } |
| 1145 | |
| 1146 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1147 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1148 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1149 | return kArm64WordSize; |
| 1150 | } |
| 1151 | |
| 1152 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1153 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1154 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1155 | return kArm64WordSize; |
| 1156 | } |
| 1157 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1158 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1159 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1163 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1166 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1167 | if (constant->IsIntConstant()) { |
| 1168 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1169 | } else if (constant->IsLongConstant()) { |
| 1170 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1171 | } else if (constant->IsNullConstant()) { |
| 1172 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1173 | } else if (constant->IsFloatConstant()) { |
| 1174 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1175 | } else { |
| 1176 | DCHECK(constant->IsDoubleConstant()); |
| 1177 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1178 | } |
| 1179 | } |
| 1180 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1181 | |
| 1182 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1183 | DCHECK(constant.IsConstant()); |
| 1184 | HConstant* cst = constant.GetConstant(); |
| 1185 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1186 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1187 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1188 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1189 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1190 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1191 | } |
| 1192 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1193 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1194 | Location source, |
| 1195 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1196 | if (source.Equals(destination)) { |
| 1197 | return; |
| 1198 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1199 | |
| 1200 | // A valid move can always be inferred from the destination and source |
| 1201 | // locations. When moving from and to a register, the argument type can be |
| 1202 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1203 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1204 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1205 | |
| 1206 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1207 | if (unspecified_type) { |
| 1208 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1209 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1210 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1211 | || src_cst->IsFloatConstant() |
| 1212 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1213 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1214 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1215 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1216 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1217 | // type is appropriate. Else the source is a register, and since the |
| 1218 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1219 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1220 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1221 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1222 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1223 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1224 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1225 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1226 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1227 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1228 | __ Ldr(dst, StackOperandFrom(source)); |
| 1229 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1230 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1231 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1232 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1233 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1234 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1235 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1236 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1237 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1238 | ? Primitive::kPrimLong |
| 1239 | : Primitive::kPrimInt; |
| 1240 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1241 | } |
| 1242 | } else { |
| 1243 | DCHECK(source.IsFpuRegister()); |
| 1244 | if (destination.IsRegister()) { |
| 1245 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1246 | ? Primitive::kPrimDouble |
| 1247 | : Primitive::kPrimFloat; |
| 1248 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1249 | } else { |
| 1250 | DCHECK(destination.IsFpuRegister()); |
| 1251 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1252 | } |
| 1253 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1254 | } else { // The destination is not a register. It must be a stack slot. |
| 1255 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1256 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1257 | if (unspecified_type) { |
| 1258 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1259 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1260 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1261 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1262 | } |
| 1263 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1264 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1265 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1266 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1267 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1268 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1269 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1270 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1271 | HConstant* src_cst = source.GetConstant(); |
| 1272 | CPURegister temp; |
Alexandre Rames | 7be929d | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1273 | if (src_cst->IsZeroBitPattern()) { |
| 1274 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1275 | } else { |
Alexandre Rames | 7be929d | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1276 | if (src_cst->IsIntConstant()) { |
| 1277 | temp = temps.AcquireW(); |
| 1278 | } else if (src_cst->IsLongConstant()) { |
| 1279 | temp = temps.AcquireX(); |
| 1280 | } else if (src_cst->IsFloatConstant()) { |
| 1281 | temp = temps.AcquireS(); |
| 1282 | } else { |
| 1283 | DCHECK(src_cst->IsDoubleConstant()); |
| 1284 | temp = temps.AcquireD(); |
| 1285 | } |
| 1286 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1287 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1288 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1289 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1290 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1291 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1292 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1293 | // There is generally less pressure on FP registers. |
| 1294 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1295 | __ Ldr(temp, StackOperandFrom(source)); |
| 1296 | __ Str(temp, StackOperandFrom(destination)); |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1302 | CPURegister dst, |
| 1303 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1304 | switch (type) { |
| 1305 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1306 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1307 | break; |
| 1308 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1309 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1310 | break; |
| 1311 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1312 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1313 | break; |
| 1314 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1315 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1316 | break; |
| 1317 | case Primitive::kPrimInt: |
| 1318 | case Primitive::kPrimNot: |
| 1319 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1320 | case Primitive::kPrimFloat: |
| 1321 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1322 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1323 | __ Ldr(dst, src); |
| 1324 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1325 | case Primitive::kPrimVoid: |
| 1326 | LOG(FATAL) << "Unreachable type " << type; |
| 1327 | } |
| 1328 | } |
| 1329 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1330 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1331 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1332 | const MemOperand& src, |
| 1333 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1334 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1335 | BlockPoolsScope block_pools(masm); |
| 1336 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1337 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1338 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1339 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1340 | DCHECK(!src.IsPreIndex()); |
| 1341 | DCHECK(!src.IsPostIndex()); |
| 1342 | |
| 1343 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1344 | __ Add(temp_base, src.base(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1345 | MemOperand base = MemOperand(temp_base); |
| 1346 | switch (type) { |
| 1347 | case Primitive::kPrimBoolean: |
| 1348 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1349 | if (needs_null_check) { |
| 1350 | MaybeRecordImplicitNullCheck(instruction); |
| 1351 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1352 | break; |
| 1353 | case Primitive::kPrimByte: |
| 1354 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1355 | if (needs_null_check) { |
| 1356 | MaybeRecordImplicitNullCheck(instruction); |
| 1357 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1358 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1359 | break; |
| 1360 | case Primitive::kPrimChar: |
| 1361 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1362 | if (needs_null_check) { |
| 1363 | MaybeRecordImplicitNullCheck(instruction); |
| 1364 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1365 | break; |
| 1366 | case Primitive::kPrimShort: |
| 1367 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1368 | if (needs_null_check) { |
| 1369 | MaybeRecordImplicitNullCheck(instruction); |
| 1370 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1371 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1372 | break; |
| 1373 | case Primitive::kPrimInt: |
| 1374 | case Primitive::kPrimNot: |
| 1375 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1376 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1377 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1378 | if (needs_null_check) { |
| 1379 | MaybeRecordImplicitNullCheck(instruction); |
| 1380 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1381 | break; |
| 1382 | case Primitive::kPrimFloat: |
| 1383 | case Primitive::kPrimDouble: { |
| 1384 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1385 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1386 | |
| 1387 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1388 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1389 | if (needs_null_check) { |
| 1390 | MaybeRecordImplicitNullCheck(instruction); |
| 1391 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1392 | __ Fmov(FPRegister(dst), temp); |
| 1393 | break; |
| 1394 | } |
| 1395 | case Primitive::kPrimVoid: |
| 1396 | LOG(FATAL) << "Unreachable type " << type; |
| 1397 | } |
| 1398 | } |
| 1399 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1400 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1401 | CPURegister src, |
| 1402 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1403 | switch (type) { |
| 1404 | case Primitive::kPrimBoolean: |
| 1405 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1406 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1407 | break; |
| 1408 | case Primitive::kPrimChar: |
| 1409 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1410 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1411 | break; |
| 1412 | case Primitive::kPrimInt: |
| 1413 | case Primitive::kPrimNot: |
| 1414 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1415 | case Primitive::kPrimFloat: |
| 1416 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1417 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1418 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1419 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1420 | case Primitive::kPrimVoid: |
| 1421 | LOG(FATAL) << "Unreachable type " << type; |
| 1422 | } |
| 1423 | } |
| 1424 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1425 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1426 | CPURegister src, |
| 1427 | const MemOperand& dst) { |
| 1428 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1429 | Register temp_base = temps.AcquireX(); |
| 1430 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1431 | DCHECK(!dst.IsPreIndex()); |
| 1432 | DCHECK(!dst.IsPostIndex()); |
| 1433 | |
| 1434 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1435 | Operand op = OperandFromMemOperand(dst); |
| 1436 | __ Add(temp_base, dst.base(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1437 | MemOperand base = MemOperand(temp_base); |
| 1438 | switch (type) { |
| 1439 | case Primitive::kPrimBoolean: |
| 1440 | case Primitive::kPrimByte: |
| 1441 | __ Stlrb(Register(src), base); |
| 1442 | break; |
| 1443 | case Primitive::kPrimChar: |
| 1444 | case Primitive::kPrimShort: |
| 1445 | __ Stlrh(Register(src), base); |
| 1446 | break; |
| 1447 | case Primitive::kPrimInt: |
| 1448 | case Primitive::kPrimNot: |
| 1449 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1450 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1451 | __ Stlr(Register(src), base); |
| 1452 | break; |
| 1453 | case Primitive::kPrimFloat: |
| 1454 | case Primitive::kPrimDouble: { |
| 1455 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1456 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1457 | |
| 1458 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1459 | __ Fmov(temp, FPRegister(src)); |
| 1460 | __ Stlr(temp, base); |
| 1461 | break; |
| 1462 | } |
| 1463 | case Primitive::kPrimVoid: |
| 1464 | LOG(FATAL) << "Unreachable type " << type; |
| 1465 | } |
| 1466 | } |
| 1467 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1468 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1469 | HInstruction* instruction, |
| 1470 | uint32_t dex_pc, |
| 1471 | SlowPathCode* slow_path) { |
| 1472 | InvokeRuntime(GetThreadOffset<kArm64WordSize>(entrypoint).Int32Value(), |
| 1473 | instruction, |
| 1474 | dex_pc, |
| 1475 | slow_path); |
| 1476 | } |
| 1477 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1478 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 1479 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1480 | uint32_t dex_pc, |
| 1481 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1482 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1483 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1484 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1485 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1486 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| 1490 | vixl::Register class_reg) { |
| 1491 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1492 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1493 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1494 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1495 | // 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] | 1496 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1497 | __ Add(temp, class_reg, status_offset); |
| 1498 | __ Ldar(temp, HeapOperand(temp)); |
| 1499 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1500 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1501 | __ Bind(slow_path->GetExitLabel()); |
| 1502 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1503 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1504 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1505 | BarrierType type = BarrierAll; |
| 1506 | |
| 1507 | switch (kind) { |
| 1508 | case MemBarrierKind::kAnyAny: |
| 1509 | case MemBarrierKind::kAnyStore: { |
| 1510 | type = BarrierAll; |
| 1511 | break; |
| 1512 | } |
| 1513 | case MemBarrierKind::kLoadAny: { |
| 1514 | type = BarrierReads; |
| 1515 | break; |
| 1516 | } |
| 1517 | case MemBarrierKind::kStoreStore: { |
| 1518 | type = BarrierWrites; |
| 1519 | break; |
| 1520 | } |
| 1521 | default: |
| 1522 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1523 | } |
| 1524 | __ Dmb(InnerShareable, type); |
| 1525 | } |
| 1526 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1527 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1528 | HBasicBlock* successor) { |
| 1529 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1530 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1531 | if (slow_path == nullptr) { |
| 1532 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1533 | instruction->SetSlowPath(slow_path); |
| 1534 | codegen_->AddSlowPath(slow_path); |
| 1535 | if (successor != nullptr) { |
| 1536 | DCHECK(successor->IsLoopHeader()); |
| 1537 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1538 | } |
| 1539 | } else { |
| 1540 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1541 | } |
| 1542 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1543 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1544 | Register temp = temps.AcquireW(); |
| 1545 | |
| 1546 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue())); |
| 1547 | if (successor == nullptr) { |
| 1548 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1549 | __ Bind(slow_path->GetReturnLabel()); |
| 1550 | } else { |
| 1551 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1552 | __ B(slow_path->GetEntryLabel()); |
| 1553 | // slow_path will return to GetLabelOf(successor). |
| 1554 | } |
| 1555 | } |
| 1556 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1557 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1558 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1559 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1560 | assembler_(codegen->GetAssembler()), |
| 1561 | codegen_(codegen) {} |
| 1562 | |
| 1563 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1564 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1565 | |
| 1566 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1567 | |
| 1568 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1569 | // Using a base helps identify when we hit such breakpoints. |
| 1570 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1571 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1572 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1573 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1574 | }; |
| 1575 | |
| 1576 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1577 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1578 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1579 | } \ |
| 1580 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1581 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1582 | locations->SetOut(Location::Any()); \ |
| 1583 | } |
| 1584 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1585 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1586 | |
| 1587 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1588 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1589 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1590 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1591 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1592 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1593 | Primitive::Type type = instr->GetResultType(); |
| 1594 | switch (type) { |
| 1595 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1596 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1597 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1598 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1599 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1600 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1601 | |
| 1602 | case Primitive::kPrimFloat: |
| 1603 | case Primitive::kPrimDouble: |
| 1604 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1605 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1606 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1607 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1608 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1609 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1610 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1611 | } |
| 1612 | } |
| 1613 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1614 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1615 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1616 | |
| 1617 | bool object_field_get_with_read_barrier = |
| 1618 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1619 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1620 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1621 | object_field_get_with_read_barrier ? |
| 1622 | LocationSummary::kCallOnSlowPath : |
| 1623 | LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1624 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1625 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1626 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1627 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1628 | // The output overlaps for an object field get when read barriers |
| 1629 | // are enabled: we do not want the load to overwrite the object's |
| 1630 | // location, as we need it to emit the read barrier. |
| 1631 | locations->SetOut( |
| 1632 | Location::RequiresRegister(), |
| 1633 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1638 | const FieldInfo& field_info) { |
| 1639 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1640 | LocationSummary* locations = instruction->GetLocations(); |
| 1641 | Location base_loc = locations->InAt(0); |
| 1642 | Location out = locations->Out(); |
| 1643 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1644 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1645 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1646 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1647 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1648 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1649 | // Object FieldGet with Baker's read barrier case. |
| 1650 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1651 | UseScratchRegisterScope temps(masm); |
| 1652 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1653 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1654 | Register temp = temps.AcquireW(); |
| 1655 | // Note that potential implicit null checks are handled in this |
| 1656 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1657 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1658 | instruction, |
| 1659 | out, |
| 1660 | base, |
| 1661 | offset, |
| 1662 | temp, |
| 1663 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1664 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1665 | } else { |
| 1666 | // General case. |
| 1667 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1668 | // Note that a potential implicit null check is handled in this |
| 1669 | // CodeGeneratorARM64::LoadAcquire call. |
| 1670 | // NB: LoadAcquire will record the pc info if needed. |
| 1671 | codegen_->LoadAcquire( |
| 1672 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1673 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1674 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1675 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1676 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1677 | if (field_type == Primitive::kPrimNot) { |
| 1678 | // If read barriers are enabled, emit read barriers other than |
| 1679 | // Baker's using a slow path (and also unpoison the loaded |
| 1680 | // reference, if heap poisoning is enabled). |
| 1681 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1682 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1683 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1687 | LocationSummary* locations = |
| 1688 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1689 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1690 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1691 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1692 | } else { |
| 1693 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1698 | const FieldInfo& field_info, |
| 1699 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1700 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1701 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1702 | |
| 1703 | Register obj = InputRegisterAt(instruction, 0); |
| 1704 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1705 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1706 | Offset offset = field_info.GetFieldOffset(); |
| 1707 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1708 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1709 | { |
| 1710 | // We use a block to end the scratch scope before the write barrier, thus |
| 1711 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1712 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1713 | |
| 1714 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1715 | DCHECK(value.IsW()); |
| 1716 | Register temp = temps.AcquireW(); |
| 1717 | __ Mov(temp, value.W()); |
| 1718 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1719 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1720 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1721 | |
| 1722 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1723 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1724 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1725 | } else { |
| 1726 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1727 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1728 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1732 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1736 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1737 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1738 | |
| 1739 | switch (type) { |
| 1740 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1741 | case Primitive::kPrimLong: { |
| 1742 | Register dst = OutputRegister(instr); |
| 1743 | Register lhs = InputRegisterAt(instr, 0); |
| 1744 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1745 | if (instr->IsAdd()) { |
| 1746 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1747 | } else if (instr->IsAnd()) { |
| 1748 | __ And(dst, lhs, rhs); |
| 1749 | } else if (instr->IsOr()) { |
| 1750 | __ Orr(dst, lhs, rhs); |
| 1751 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1752 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1753 | } else if (instr->IsRor()) { |
| 1754 | if (rhs.IsImmediate()) { |
| 1755 | uint32_t shift = rhs.immediate() & (lhs.SizeInBits() - 1); |
| 1756 | __ Ror(dst, lhs, shift); |
| 1757 | } else { |
| 1758 | // Ensure shift distance is in the same size register as the result. If |
| 1759 | // we are rotating a long and the shift comes in a w register originally, |
| 1760 | // we don't need to sxtw for use as an x since the shift distances are |
| 1761 | // all & reg_bits - 1. |
| 1762 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1763 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1764 | } else { |
| 1765 | DCHECK(instr->IsXor()); |
| 1766 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1767 | } |
| 1768 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1769 | } |
| 1770 | case Primitive::kPrimFloat: |
| 1771 | case Primitive::kPrimDouble: { |
| 1772 | FPRegister dst = OutputFPRegister(instr); |
| 1773 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1774 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1775 | if (instr->IsAdd()) { |
| 1776 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1777 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1778 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1779 | } else { |
| 1780 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1781 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1782 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1783 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1784 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1785 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1789 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1790 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1791 | |
| 1792 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1793 | Primitive::Type type = instr->GetResultType(); |
| 1794 | switch (type) { |
| 1795 | case Primitive::kPrimInt: |
| 1796 | case Primitive::kPrimLong: { |
| 1797 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1798 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1799 | locations->SetOut(Location::RequiresRegister()); |
| 1800 | break; |
| 1801 | } |
| 1802 | default: |
| 1803 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1808 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1809 | |
| 1810 | Primitive::Type type = instr->GetType(); |
| 1811 | switch (type) { |
| 1812 | case Primitive::kPrimInt: |
| 1813 | case Primitive::kPrimLong: { |
| 1814 | Register dst = OutputRegister(instr); |
| 1815 | Register lhs = InputRegisterAt(instr, 0); |
| 1816 | Operand rhs = InputOperandAt(instr, 1); |
| 1817 | if (rhs.IsImmediate()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1818 | uint32_t shift_value = rhs.immediate() & |
| 1819 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1820 | if (instr->IsShl()) { |
| 1821 | __ Lsl(dst, lhs, shift_value); |
| 1822 | } else if (instr->IsShr()) { |
| 1823 | __ Asr(dst, lhs, shift_value); |
| 1824 | } else { |
| 1825 | __ Lsr(dst, lhs, shift_value); |
| 1826 | } |
| 1827 | } else { |
| 1828 | Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W(); |
| 1829 | |
| 1830 | if (instr->IsShl()) { |
| 1831 | __ Lsl(dst, lhs, rhs_reg); |
| 1832 | } else if (instr->IsShr()) { |
| 1833 | __ Asr(dst, lhs, rhs_reg); |
| 1834 | } else { |
| 1835 | __ Lsr(dst, lhs, rhs_reg); |
| 1836 | } |
| 1837 | } |
| 1838 | break; |
| 1839 | } |
| 1840 | default: |
| 1841 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1842 | } |
| 1843 | } |
| 1844 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1845 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1846 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1850 | HandleBinaryOp(instruction); |
| 1851 | } |
| 1852 | |
| 1853 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1854 | HandleBinaryOp(instruction); |
| 1855 | } |
| 1856 | |
| 1857 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1858 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1859 | } |
| 1860 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1861 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1862 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 1863 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1864 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1865 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 1866 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1867 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1868 | } |
| 1869 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1870 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1871 | Register dst = OutputRegister(instr); |
| 1872 | Register lhs = InputRegisterAt(instr, 0); |
| 1873 | Register rhs = InputRegisterAt(instr, 1); |
| 1874 | |
| 1875 | switch (instr->GetOpKind()) { |
| 1876 | case HInstruction::kAnd: |
| 1877 | __ Bic(dst, lhs, rhs); |
| 1878 | break; |
| 1879 | case HInstruction::kOr: |
| 1880 | __ Orn(dst, lhs, rhs); |
| 1881 | break; |
| 1882 | case HInstruction::kXor: |
| 1883 | __ Eon(dst, lhs, rhs); |
| 1884 | break; |
| 1885 | default: |
| 1886 | LOG(FATAL) << "Unreachable"; |
| 1887 | } |
| 1888 | } |
| 1889 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1890 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 1891 | HArm64DataProcWithShifterOp* instruction) { |
| 1892 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 1893 | instruction->GetType() == Primitive::kPrimLong); |
| 1894 | LocationSummary* locations = |
| 1895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1896 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 1897 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 1898 | } else { |
| 1899 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1900 | } |
| 1901 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1902 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1903 | } |
| 1904 | |
| 1905 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 1906 | HArm64DataProcWithShifterOp* instruction) { |
| 1907 | Primitive::Type type = instruction->GetType(); |
| 1908 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1909 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1910 | Register out = OutputRegister(instruction); |
| 1911 | Register left; |
| 1912 | if (kind != HInstruction::kNeg) { |
| 1913 | left = InputRegisterAt(instruction, 0); |
| 1914 | } |
| 1915 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 1916 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 1917 | // conversion) can have a different type from the current instruction's type, |
| 1918 | // so we manually indicate the type. |
| 1919 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1920 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 1921 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1922 | |
| 1923 | Operand right_operand(0); |
| 1924 | |
| 1925 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 1926 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 1927 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 1928 | } else { |
| 1929 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 1930 | } |
| 1931 | |
| 1932 | // Logical binary operations do not support extension operations in the |
| 1933 | // operand. Note that VIXL would still manage if it was passed by generating |
| 1934 | // the extension as a separate instruction. |
| 1935 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 1936 | DCHECK(!right_operand.IsExtendedRegister() || |
| 1937 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 1938 | kind != HInstruction::kNeg)); |
| 1939 | switch (kind) { |
| 1940 | case HInstruction::kAdd: |
| 1941 | __ Add(out, left, right_operand); |
| 1942 | break; |
| 1943 | case HInstruction::kAnd: |
| 1944 | __ And(out, left, right_operand); |
| 1945 | break; |
| 1946 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1947 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1948 | __ Neg(out, right_operand); |
| 1949 | break; |
| 1950 | case HInstruction::kOr: |
| 1951 | __ Orr(out, left, right_operand); |
| 1952 | break; |
| 1953 | case HInstruction::kSub: |
| 1954 | __ Sub(out, left, right_operand); |
| 1955 | break; |
| 1956 | case HInstruction::kXor: |
| 1957 | __ Eor(out, left, right_operand); |
| 1958 | break; |
| 1959 | default: |
| 1960 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 1961 | UNREACHABLE(); |
| 1962 | } |
| 1963 | } |
| 1964 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1965 | void LocationsBuilderARM64::VisitArm64IntermediateAddress(HArm64IntermediateAddress* instruction) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1966 | // The read barrier instrumentation does not support the |
| 1967 | // HArm64IntermediateAddress instruction yet. |
| 1968 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1969 | LocationSummary* locations = |
| 1970 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1972 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 1973 | locations->SetOut(Location::RequiresRegister()); |
| 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorARM64::VisitArm64IntermediateAddress( |
| 1977 | HArm64IntermediateAddress* instruction) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1978 | // The read barrier instrumentation does not support the |
| 1979 | // HArm64IntermediateAddress instruction yet. |
| 1980 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1981 | __ Add(OutputRegister(instruction), |
| 1982 | InputRegisterAt(instruction, 0), |
| 1983 | Operand(InputOperandAt(instruction, 1))); |
| 1984 | } |
| 1985 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1986 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1987 | LocationSummary* locations = |
| 1988 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1989 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 1990 | if (instr->GetOpKind() == HInstruction::kSub && |
| 1991 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1992 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1993 | // Don't allocate register for Mneg instruction. |
| 1994 | } else { |
| 1995 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 1996 | Location::RequiresRegister()); |
| 1997 | } |
| 1998 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 1999 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2000 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2001 | } |
| 2002 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2003 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2004 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2005 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2006 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2007 | |
| 2008 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2009 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2010 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2011 | if (instr->GetType() == Primitive::kPrimLong && |
| 2012 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2013 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
| 2014 | vixl::Instruction* prev = masm->GetCursorAddress<vixl::Instruction*>() - vixl::kInstructionSize; |
| 2015 | if (prev->IsLoadOrStore()) { |
| 2016 | // Make sure we emit only exactly one nop. |
| 2017 | vixl::CodeBufferCheckScope scope(masm, |
| 2018 | vixl::kInstructionSize, |
| 2019 | vixl::CodeBufferCheckScope::kCheck, |
| 2020 | vixl::CodeBufferCheckScope::kExactSize); |
| 2021 | __ nop(); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2026 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2027 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2028 | } else { |
| 2029 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2030 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2031 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2032 | __ Mneg(res, mul_left, mul_right); |
| 2033 | } else { |
| 2034 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2035 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2036 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2040 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2041 | bool object_array_get_with_read_barrier = |
| 2042 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2043 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2044 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2045 | object_array_get_with_read_barrier ? |
| 2046 | LocationSummary::kCallOnSlowPath : |
| 2047 | LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2048 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2049 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2050 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2051 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2052 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2053 | // The output overlaps in the case of an object array get with |
| 2054 | // read barriers enabled: we do not want the move to overwrite the |
| 2055 | // array's location, as we need it to emit the read barrier. |
| 2056 | locations->SetOut( |
| 2057 | Location::RequiresRegister(), |
| 2058 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2059 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2063 | Primitive::Type type = instruction->GetType(); |
| 2064 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2065 | LocationSummary* locations = instruction->GetLocations(); |
| 2066 | Location index = locations->InAt(1); |
| 2067 | uint32_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2068 | Location out = locations->Out(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2069 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2070 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2071 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2072 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2073 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2074 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2075 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2076 | // Object ArrayGet with Baker's read barrier case. |
| 2077 | Register temp = temps.AcquireW(); |
| 2078 | // The read barrier instrumentation does not support the |
| 2079 | // HArm64IntermediateAddress instruction yet. |
| 2080 | DCHECK(!instruction->GetArray()->IsArm64IntermediateAddress()); |
| 2081 | // Note that a potential implicit null check is handled in the |
| 2082 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2083 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2084 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2085 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2086 | // General case. |
| 2087 | MemOperand source = HeapOperand(obj); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2088 | if (index.IsConstant()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2089 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2090 | source = HeapOperand(obj, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2091 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2092 | Register temp = temps.AcquireSameSizeAs(obj); |
| 2093 | if (instruction->GetArray()->IsArm64IntermediateAddress()) { |
| 2094 | // The read barrier instrumentation does not support the |
| 2095 | // HArm64IntermediateAddress instruction yet. |
| 2096 | DCHECK(!kEmitCompilerReadBarrier); |
| 2097 | // We do not need to compute the intermediate address from the array: the |
| 2098 | // input instruction has done it already. See the comment in |
| 2099 | // `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`. |
| 2100 | if (kIsDebugBuild) { |
| 2101 | HArm64IntermediateAddress* tmp = instruction->GetArray()->AsArm64IntermediateAddress(); |
| 2102 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2103 | } |
| 2104 | temp = obj; |
| 2105 | } else { |
| 2106 | __ Add(temp, obj, offset); |
| 2107 | } |
| 2108 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2109 | } |
| 2110 | |
| 2111 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2112 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2113 | |
| 2114 | if (type == Primitive::kPrimNot) { |
| 2115 | static_assert( |
| 2116 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2117 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2118 | Location obj_loc = locations->InAt(0); |
| 2119 | if (index.IsConstant()) { |
| 2120 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2121 | } else { |
| 2122 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2123 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2124 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2125 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2128 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2129 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2130 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2131 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | 51c103e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2135 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2136 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Vladimir Marko | 51c103e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2137 | __ Ldr(OutputRegister(instruction), HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2138 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2139 | } |
| 2140 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2141 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2142 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2143 | |
| 2144 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2145 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2146 | instruction, |
Vladimir Marko | efafb12 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2147 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2148 | LocationSummary::kCallOnSlowPath : |
| 2149 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2151 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2152 | if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2153 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2154 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2155 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2160 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2161 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2162 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2163 | bool needs_write_barrier = |
| 2164 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2165 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2166 | Register array = InputRegisterAt(instruction, 0); |
| 2167 | CPURegister value = InputCPURegisterAt(instruction, 2); |
| 2168 | CPURegister source = value; |
| 2169 | Location index = locations->InAt(1); |
| 2170 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2171 | MemOperand destination = HeapOperand(array); |
| 2172 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2173 | BlockPoolsScope block_pools(masm); |
| 2174 | |
| 2175 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2176 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2177 | if (index.IsConstant()) { |
| 2178 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2179 | destination = HeapOperand(array, offset); |
| 2180 | } else { |
| 2181 | UseScratchRegisterScope temps(masm); |
| 2182 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2183 | if (instruction->GetArray()->IsArm64IntermediateAddress()) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 2184 | // The read barrier instrumentation does not support the |
| 2185 | // HArm64IntermediateAddress instruction yet. |
| 2186 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2187 | // We do not need to compute the intermediate address from the array: the |
| 2188 | // input instruction has done it already. See the comment in |
| 2189 | // `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`. |
| 2190 | if (kIsDebugBuild) { |
| 2191 | HArm64IntermediateAddress* tmp = instruction->GetArray()->AsArm64IntermediateAddress(); |
| 2192 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2193 | } |
| 2194 | temp = array; |
| 2195 | } else { |
| 2196 | __ Add(temp, array, offset); |
| 2197 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2198 | destination = HeapOperand(temp, |
| 2199 | XRegisterFrom(index), |
| 2200 | LSL, |
| 2201 | Primitive::ComponentSizeShift(value_type)); |
| 2202 | } |
| 2203 | codegen_->Store(value_type, value, destination); |
| 2204 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2205 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2206 | DCHECK(needs_write_barrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2207 | DCHECK(!instruction->GetArray()->IsArm64IntermediateAddress()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2208 | vixl::Label done; |
| 2209 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2210 | { |
| 2211 | // We use a block to end the scratch scope before the write barrier, thus |
| 2212 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2213 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2214 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2215 | if (index.IsConstant()) { |
| 2216 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2217 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2218 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2219 | destination = HeapOperand(temp, |
| 2220 | XRegisterFrom(index), |
| 2221 | LSL, |
| 2222 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2225 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2226 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2227 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2228 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2229 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2230 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2231 | codegen_->AddSlowPath(slow_path); |
| 2232 | if (instruction->GetValueCanBeNull()) { |
| 2233 | vixl::Label non_zero; |
| 2234 | __ Cbnz(Register(value), &non_zero); |
| 2235 | if (!index.IsConstant()) { |
| 2236 | __ Add(temp, array, offset); |
| 2237 | } |
| 2238 | __ Str(wzr, destination); |
| 2239 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2240 | __ B(&done); |
| 2241 | __ Bind(&non_zero); |
| 2242 | } |
| 2243 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2244 | if (kEmitCompilerReadBarrier) { |
| 2245 | // When read barriers are enabled, the type checking |
| 2246 | // instrumentation requires two read barriers: |
| 2247 | // |
| 2248 | // __ Mov(temp2, temp); |
| 2249 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2250 | // __ Ldr(temp, HeapOperand(temp, component_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2251 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2252 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 2253 | // |
| 2254 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2255 | // __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2256 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2257 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp_loc); |
| 2258 | // |
| 2259 | // __ Cmp(temp, temp2); |
| 2260 | // |
| 2261 | // However, the second read barrier may trash `temp`, as it |
| 2262 | // is a temporary register, and as such would not be saved |
| 2263 | // along with live registers before calling the runtime (nor |
| 2264 | // restored afterwards). So in this case, we bail out and |
| 2265 | // delegate the work to the array set slow path. |
| 2266 | // |
| 2267 | // TODO: Extend the register allocator to support a new |
| 2268 | // "(locally) live temp" location so as to avoid always |
| 2269 | // going into the slow path when read barriers are enabled. |
| 2270 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2271 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2272 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2273 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2274 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2275 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2276 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2277 | |
| 2278 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2279 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2280 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2281 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2282 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2283 | // nor `temp2`, as we are comparing two poisoned references. |
| 2284 | __ Cmp(temp, temp2); |
| 2285 | |
| 2286 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2287 | vixl::Label do_put; |
| 2288 | __ B(eq, &do_put); |
| 2289 | // If heap poisoning is enabled, the `temp` reference has |
| 2290 | // not been unpoisoned yet; unpoison it now. |
| 2291 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2292 | |
| 2293 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2294 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2295 | // If heap poisoning is enabled, no need to unpoison |
| 2296 | // `temp`, as we are comparing against null below. |
| 2297 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2298 | __ Bind(&do_put); |
| 2299 | } else { |
| 2300 | __ B(ne, slow_path->GetEntryLabel()); |
| 2301 | } |
| 2302 | temps.Release(temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2307 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2308 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2309 | __ Mov(temp2, value.W()); |
| 2310 | GetAssembler()->PoisonHeapReference(temp2); |
| 2311 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | if (!index.IsConstant()) { |
| 2315 | __ Add(temp, array, offset); |
| 2316 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2317 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2318 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2319 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2320 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2321 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2322 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2323 | |
| 2324 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2325 | |
| 2326 | if (done.IsLinked()) { |
| 2327 | __ Bind(&done); |
| 2328 | } |
| 2329 | |
| 2330 | if (slow_path != nullptr) { |
| 2331 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2332 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2336 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2337 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2338 | ? LocationSummary::kCallOnSlowPath |
| 2339 | : LocationSummary::kNoCall; |
| 2340 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2341 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2342 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2343 | if (instruction->HasUses()) { |
| 2344 | locations->SetOut(Location::SameAsFirstInput()); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2349 | BoundsCheckSlowPathARM64* slow_path = |
| 2350 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2351 | codegen_->AddSlowPath(slow_path); |
| 2352 | |
| 2353 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2354 | __ B(slow_path->GetEntryLabel(), hs); |
| 2355 | } |
| 2356 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2357 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2358 | LocationSummary* locations = |
| 2359 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2361 | if (check->HasUses()) { |
| 2362 | locations->SetOut(Location::SameAsFirstInput()); |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2367 | // We assume the class is not null. |
| 2368 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2369 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2370 | codegen_->AddSlowPath(slow_path); |
| 2371 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2372 | } |
| 2373 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2374 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2375 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2376 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2377 | } |
| 2378 | |
| 2379 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2380 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2381 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2382 | if (rhs_loc.IsConstant()) { |
| 2383 | // 0.0 is the only immediate that can be encoded directly in |
| 2384 | // an FCMP instruction. |
| 2385 | // |
| 2386 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2387 | // specify that in a floating-point comparison, positive zero |
| 2388 | // and negative zero are considered equal, so we can use the |
| 2389 | // literal 0.0 for both cases here. |
| 2390 | // |
| 2391 | // Note however that some methods (Float.equal, Float.compare, |
| 2392 | // Float.compareTo, Double.equal, Double.compare, |
| 2393 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2394 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2395 | // -0.0. So if we ever translate calls to these methods into a |
| 2396 | // HCompare instruction, we must handle the -0.0 case with |
| 2397 | // care here. |
| 2398 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2399 | __ Fcmp(lhs_reg, 0.0); |
| 2400 | } else { |
| 2401 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2402 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2405 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2406 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2407 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2408 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2409 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2410 | case Primitive::kPrimBoolean: |
| 2411 | case Primitive::kPrimByte: |
| 2412 | case Primitive::kPrimShort: |
| 2413 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2414 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2415 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2416 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2417 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2418 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2419 | break; |
| 2420 | } |
| 2421 | case Primitive::kPrimFloat: |
| 2422 | case Primitive::kPrimDouble: { |
| 2423 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2424 | locations->SetInAt(1, |
| 2425 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2426 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2427 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2428 | locations->SetOut(Location::RequiresRegister()); |
| 2429 | break; |
| 2430 | } |
| 2431 | default: |
| 2432 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2437 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2438 | |
| 2439 | // 0 if: left == right |
| 2440 | // 1 if: left > right |
| 2441 | // -1 if: left < right |
| 2442 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2443 | case Primitive::kPrimBoolean: |
| 2444 | case Primitive::kPrimByte: |
| 2445 | case Primitive::kPrimShort: |
| 2446 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2447 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimLong: { |
| 2449 | Register result = OutputRegister(compare); |
| 2450 | Register left = InputRegisterAt(compare, 0); |
| 2451 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2452 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2453 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2454 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2455 | break; |
| 2456 | } |
| 2457 | case Primitive::kPrimFloat: |
| 2458 | case Primitive::kPrimDouble: { |
| 2459 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2460 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2461 | __ Cset(result, ne); |
| 2462 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2463 | break; |
| 2464 | } |
| 2465 | default: |
| 2466 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2467 | } |
| 2468 | } |
| 2469 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2470 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2471 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2472 | |
| 2473 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2474 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2475 | locations->SetInAt(1, |
| 2476 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2477 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2478 | : Location::RequiresFpuRegister()); |
| 2479 | } else { |
| 2480 | // Integer cases. |
| 2481 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2482 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2483 | } |
| 2484 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2485 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2486 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2490 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2491 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2492 | return; |
| 2493 | } |
| 2494 | |
| 2495 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2496 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2497 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2498 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2499 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2500 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2501 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2502 | } else { |
| 2503 | // Integer cases. |
| 2504 | Register lhs = InputRegisterAt(instruction, 0); |
| 2505 | Operand rhs = InputOperandAt(instruction, 1); |
| 2506 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2507 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2508 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2512 | M(Equal) \ |
| 2513 | M(NotEqual) \ |
| 2514 | M(LessThan) \ |
| 2515 | M(LessThanOrEqual) \ |
| 2516 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2517 | M(GreaterThanOrEqual) \ |
| 2518 | M(Below) \ |
| 2519 | M(BelowOrEqual) \ |
| 2520 | M(Above) \ |
| 2521 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2522 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2523 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2524 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2525 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2526 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2527 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2528 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2529 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2530 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2531 | |
| 2532 | LocationSummary* locations = instruction->GetLocations(); |
| 2533 | Location second = locations->InAt(1); |
| 2534 | DCHECK(second.IsConstant()); |
| 2535 | |
| 2536 | Register out = OutputRegister(instruction); |
| 2537 | Register dividend = InputRegisterAt(instruction, 0); |
| 2538 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2539 | DCHECK(imm == 1 || imm == -1); |
| 2540 | |
| 2541 | if (instruction->IsRem()) { |
| 2542 | __ Mov(out, 0); |
| 2543 | } else { |
| 2544 | if (imm == 1) { |
| 2545 | __ Mov(out, dividend); |
| 2546 | } else { |
| 2547 | __ Neg(out, dividend); |
| 2548 | } |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2553 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2554 | |
| 2555 | LocationSummary* locations = instruction->GetLocations(); |
| 2556 | Location second = locations->InAt(1); |
| 2557 | DCHECK(second.IsConstant()); |
| 2558 | |
| 2559 | Register out = OutputRegister(instruction); |
| 2560 | Register dividend = InputRegisterAt(instruction, 0); |
| 2561 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2562 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2563 | int ctz_imm = CTZ(abs_imm); |
| 2564 | |
| 2565 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2566 | Register temp = temps.AcquireSameSizeAs(out); |
| 2567 | |
| 2568 | if (instruction->IsDiv()) { |
| 2569 | __ Add(temp, dividend, abs_imm - 1); |
| 2570 | __ Cmp(dividend, 0); |
| 2571 | __ Csel(out, temp, dividend, lt); |
| 2572 | if (imm > 0) { |
| 2573 | __ Asr(out, out, ctz_imm); |
| 2574 | } else { |
| 2575 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2576 | } |
| 2577 | } else { |
| 2578 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2579 | __ Asr(temp, dividend, bits - 1); |
| 2580 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2581 | __ Add(out, dividend, temp); |
| 2582 | __ And(out, out, abs_imm - 1); |
| 2583 | __ Sub(out, out, temp); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2588 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2589 | |
| 2590 | LocationSummary* locations = instruction->GetLocations(); |
| 2591 | Location second = locations->InAt(1); |
| 2592 | DCHECK(second.IsConstant()); |
| 2593 | |
| 2594 | Register out = OutputRegister(instruction); |
| 2595 | Register dividend = InputRegisterAt(instruction, 0); |
| 2596 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2597 | |
| 2598 | Primitive::Type type = instruction->GetResultType(); |
| 2599 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2600 | |
| 2601 | int64_t magic; |
| 2602 | int shift; |
| 2603 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2604 | |
| 2605 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2606 | Register temp = temps.AcquireSameSizeAs(out); |
| 2607 | |
| 2608 | // temp = get_high(dividend * magic) |
| 2609 | __ Mov(temp, magic); |
| 2610 | if (type == Primitive::kPrimLong) { |
| 2611 | __ Smulh(temp, dividend, temp); |
| 2612 | } else { |
| 2613 | __ Smull(temp.X(), dividend, temp); |
| 2614 | __ Lsr(temp.X(), temp.X(), 32); |
| 2615 | } |
| 2616 | |
| 2617 | if (imm > 0 && magic < 0) { |
| 2618 | __ Add(temp, temp, dividend); |
| 2619 | } else if (imm < 0 && magic > 0) { |
| 2620 | __ Sub(temp, temp, dividend); |
| 2621 | } |
| 2622 | |
| 2623 | if (shift != 0) { |
| 2624 | __ Asr(temp, temp, shift); |
| 2625 | } |
| 2626 | |
| 2627 | if (instruction->IsDiv()) { |
| 2628 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2629 | } else { |
| 2630 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2631 | // TODO: Strength reduction for msub. |
| 2632 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2633 | __ Mov(temp_imm, imm); |
| 2634 | __ Msub(out, temp, temp_imm, dividend); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2639 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2640 | Primitive::Type type = instruction->GetResultType(); |
| 2641 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2642 | |
| 2643 | LocationSummary* locations = instruction->GetLocations(); |
| 2644 | Register out = OutputRegister(instruction); |
| 2645 | Location second = locations->InAt(1); |
| 2646 | |
| 2647 | if (second.IsConstant()) { |
| 2648 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2649 | |
| 2650 | if (imm == 0) { |
| 2651 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2652 | } else if (imm == 1 || imm == -1) { |
| 2653 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2654 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2655 | DivRemByPowerOfTwo(instruction); |
| 2656 | } else { |
| 2657 | DCHECK(imm <= -2 || imm >= 2); |
| 2658 | GenerateDivRemWithAnyConstant(instruction); |
| 2659 | } |
| 2660 | } else { |
| 2661 | Register dividend = InputRegisterAt(instruction, 0); |
| 2662 | Register divisor = InputRegisterAt(instruction, 1); |
| 2663 | if (instruction->IsDiv()) { |
| 2664 | __ Sdiv(out, dividend, divisor); |
| 2665 | } else { |
| 2666 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2667 | Register temp = temps.AcquireSameSizeAs(out); |
| 2668 | __ Sdiv(temp, dividend, divisor); |
| 2669 | __ Msub(out, temp, divisor, dividend); |
| 2670 | } |
| 2671 | } |
| 2672 | } |
| 2673 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2674 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2675 | LocationSummary* locations = |
| 2676 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2677 | switch (div->GetResultType()) { |
| 2678 | case Primitive::kPrimInt: |
| 2679 | case Primitive::kPrimLong: |
| 2680 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2681 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2682 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2683 | break; |
| 2684 | |
| 2685 | case Primitive::kPrimFloat: |
| 2686 | case Primitive::kPrimDouble: |
| 2687 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2688 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2689 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2690 | break; |
| 2691 | |
| 2692 | default: |
| 2693 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2698 | Primitive::Type type = div->GetResultType(); |
| 2699 | switch (type) { |
| 2700 | case Primitive::kPrimInt: |
| 2701 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2702 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | case Primitive::kPrimFloat: |
| 2706 | case Primitive::kPrimDouble: |
| 2707 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2708 | break; |
| 2709 | |
| 2710 | default: |
| 2711 | LOG(FATAL) << "Unexpected div type " << type; |
| 2712 | } |
| 2713 | } |
| 2714 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2715 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2716 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2717 | ? LocationSummary::kCallOnSlowPath |
| 2718 | : LocationSummary::kNoCall; |
| 2719 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2720 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2721 | if (instruction->HasUses()) { |
| 2722 | locations->SetOut(Location::SameAsFirstInput()); |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2727 | SlowPathCodeARM64* slow_path = |
| 2728 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2729 | codegen_->AddSlowPath(slow_path); |
| 2730 | Location value = instruction->GetLocations()->InAt(0); |
| 2731 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2732 | Primitive::Type type = instruction->GetType(); |
| 2733 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2734 | if (!Primitive::IsIntegralType(type)) { |
| 2735 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2736 | return; |
| 2737 | } |
| 2738 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2739 | if (value.IsConstant()) { |
| 2740 | int64_t divisor = Int64ConstantFrom(value); |
| 2741 | if (divisor == 0) { |
| 2742 | __ B(slow_path->GetEntryLabel()); |
| 2743 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2744 | // A division by a non-null constant is valid. We don't need to perform |
| 2745 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2746 | } |
| 2747 | } else { |
| 2748 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2749 | } |
| 2750 | } |
| 2751 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2752 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2753 | LocationSummary* locations = |
| 2754 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2755 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2756 | } |
| 2757 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2758 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2759 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2760 | // Will be generated at use site. |
| 2761 | } |
| 2762 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2763 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2764 | exit->SetLocations(nullptr); |
| 2765 | } |
| 2766 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2767 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2768 | } |
| 2769 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2770 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2771 | LocationSummary* locations = |
| 2772 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2773 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2774 | } |
| 2775 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2776 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2777 | // Will be generated at use site. |
| 2778 | } |
| 2779 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2780 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2781 | DCHECK(!successor->IsExitBlock()); |
| 2782 | HBasicBlock* block = got->GetBlock(); |
| 2783 | HInstruction* previous = got->GetPrevious(); |
| 2784 | HLoopInformation* info = block->GetLoopInformation(); |
| 2785 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2786 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2787 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2788 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2789 | return; |
| 2790 | } |
| 2791 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2792 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2793 | } |
| 2794 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2795 | __ B(codegen_->GetLabelOf(successor)); |
| 2796 | } |
| 2797 | } |
| 2798 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2799 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2800 | got->SetLocations(nullptr); |
| 2801 | } |
| 2802 | |
| 2803 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2804 | HandleGoto(got, got->GetSuccessor()); |
| 2805 | } |
| 2806 | |
| 2807 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2808 | try_boundary->SetLocations(nullptr); |
| 2809 | } |
| 2810 | |
| 2811 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2812 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2813 | if (!successor->IsExitBlock()) { |
| 2814 | HandleGoto(try_boundary, successor); |
| 2815 | } |
| 2816 | } |
| 2817 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2818 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2819 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2820 | vixl::Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2821 | vixl::Label* false_target) { |
| 2822 | // FP branching requires both targets to be explicit. If either of the targets |
| 2823 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2824 | vixl::Label fallthrough_target; |
| 2825 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2826 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2827 | if (true_target == nullptr && false_target == nullptr) { |
| 2828 | // Nothing to do. The code always falls through. |
| 2829 | return; |
| 2830 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2831 | // Constant condition, statically compared against "true" (integer value 1). |
| 2832 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2833 | if (true_target != nullptr) { |
| 2834 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2835 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2836 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2837 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2838 | if (false_target != nullptr) { |
| 2839 | __ B(false_target); |
| 2840 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2841 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2842 | return; |
| 2843 | } |
| 2844 | |
| 2845 | // The following code generates these patterns: |
| 2846 | // (1) true_target == nullptr && false_target != nullptr |
| 2847 | // - opposite condition true => branch to false_target |
| 2848 | // (2) true_target != nullptr && false_target == nullptr |
| 2849 | // - condition true => branch to true_target |
| 2850 | // (3) true_target != nullptr && false_target != nullptr |
| 2851 | // - condition true => branch to true_target |
| 2852 | // - branch to false_target |
| 2853 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2854 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2855 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2856 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2857 | if (true_target == nullptr) { |
| 2858 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 2859 | } else { |
| 2860 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 2861 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2862 | } else { |
| 2863 | // The condition instruction has not been materialized, use its inputs as |
| 2864 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2865 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2866 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2867 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2868 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2869 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2870 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2871 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 2872 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2873 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2874 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2875 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2876 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2877 | // Integer cases. |
| 2878 | Register lhs = InputRegisterAt(condition, 0); |
| 2879 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2880 | |
| 2881 | Condition arm64_cond; |
| 2882 | vixl::Label* non_fallthrough_target; |
| 2883 | if (true_target == nullptr) { |
| 2884 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 2885 | non_fallthrough_target = false_target; |
| 2886 | } else { |
| 2887 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2888 | non_fallthrough_target = true_target; |
| 2889 | } |
| 2890 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 2891 | if ((arm64_cond == eq || arm64_cond == ne || arm64_cond == lt || arm64_cond == ge) && |
| 2892 | rhs.IsImmediate() && (rhs.immediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2893 | switch (arm64_cond) { |
| 2894 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2895 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2896 | break; |
| 2897 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2898 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | case lt: |
| 2901 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2902 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2903 | break; |
| 2904 | case ge: |
| 2905 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2906 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2907 | break; |
| 2908 | default: |
| 2909 | // Without the `static_cast` the compiler throws an error for |
| 2910 | // `-Werror=sign-promo`. |
| 2911 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 2912 | } |
| 2913 | } else { |
| 2914 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2915 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2916 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2917 | } |
| 2918 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2919 | |
| 2920 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2921 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2922 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2923 | __ B(false_target); |
| 2924 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2925 | |
| 2926 | if (fallthrough_target.IsLinked()) { |
| 2927 | __ Bind(&fallthrough_target); |
| 2928 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2929 | } |
| 2930 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2931 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 2932 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2933 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2935 | } |
| 2936 | } |
| 2937 | |
| 2938 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2939 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2940 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2941 | vixl::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2942 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2943 | vixl::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2944 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2945 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2949 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2950 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2951 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2957 | SlowPathCodeARM64* slow_path = |
| 2958 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2959 | GenerateTestAndBranch(deoptimize, |
| 2960 | /* condition_input_index */ 0, |
| 2961 | slow_path->GetEntryLabel(), |
| 2962 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 2965 | enum SelectVariant { |
| 2966 | kCsel, |
| 2967 | kCselFalseConst, |
| 2968 | kCselTrueConst, |
| 2969 | kFcsel, |
| 2970 | }; |
| 2971 | |
| 2972 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 2973 | return condition->IsCondition() && |
| 2974 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 2975 | } |
| 2976 | |
| 2977 | static inline bool IsRecognizedCselConstant(HInstruction* constant) { |
| 2978 | if (constant->IsConstant()) { |
| 2979 | int64_t value = Int64FromConstant(constant->AsConstant()); |
| 2980 | if ((value == -1) || (value == 0) || (value == 1)) { |
| 2981 | return true; |
| 2982 | } |
| 2983 | } |
| 2984 | return false; |
| 2985 | } |
| 2986 | |
| 2987 | static inline SelectVariant GetSelectVariant(HSelect* select) { |
| 2988 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2989 | return kFcsel; |
| 2990 | } else if (IsRecognizedCselConstant(select->GetFalseValue())) { |
| 2991 | return kCselFalseConst; |
| 2992 | } else if (IsRecognizedCselConstant(select->GetTrueValue())) { |
| 2993 | return kCselTrueConst; |
| 2994 | } else { |
| 2995 | return kCsel; |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | static inline bool HasSwappedInputs(SelectVariant variant) { |
| 3000 | return variant == kCselTrueConst; |
| 3001 | } |
| 3002 | |
| 3003 | static inline Condition GetConditionForSelect(HCondition* condition, SelectVariant variant) { |
| 3004 | IfCondition cond = HasSwappedInputs(variant) ? condition->GetOppositeCondition() |
| 3005 | : condition->GetCondition(); |
| 3006 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3007 | : ARM64Condition(cond); |
| 3008 | } |
| 3009 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3010 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3011 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3012 | switch (GetSelectVariant(select)) { |
| 3013 | case kCsel: |
| 3014 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3015 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3016 | locations->SetOut(Location::RequiresRegister()); |
| 3017 | break; |
| 3018 | case kCselFalseConst: |
| 3019 | locations->SetInAt(0, Location::ConstantLocation(select->InputAt(0)->AsConstant())); |
| 3020 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3021 | locations->SetOut(Location::RequiresRegister()); |
| 3022 | break; |
| 3023 | case kCselTrueConst: |
| 3024 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3025 | locations->SetInAt(1, Location::ConstantLocation(select->InputAt(1)->AsConstant())); |
| 3026 | locations->SetOut(Location::RequiresRegister()); |
| 3027 | break; |
| 3028 | case kFcsel: |
| 3029 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3030 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3031 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3032 | break; |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3033 | } |
| 3034 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3035 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3036 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3040 | HInstruction* cond = select->GetCondition(); |
| 3041 | SelectVariant variant = GetSelectVariant(select); |
| 3042 | Condition csel_cond; |
| 3043 | |
| 3044 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3045 | if (cond->IsCondition() && cond->GetNext() == select) { |
| 3046 | // Condition codes set from previous instruction. |
| 3047 | csel_cond = GetConditionForSelect(cond->AsCondition(), variant); |
| 3048 | } else { |
| 3049 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3050 | csel_cond = HasSwappedInputs(variant) ? eq : ne; |
| 3051 | } |
| 3052 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3053 | GenerateFcmp(cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3054 | csel_cond = GetConditionForSelect(cond->AsCondition(), variant); |
| 3055 | } else { |
| 3056 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
| 3057 | csel_cond = GetConditionForSelect(cond->AsCondition(), variant); |
| 3058 | } |
| 3059 | |
| 3060 | switch (variant) { |
| 3061 | case kCsel: |
| 3062 | case kCselFalseConst: |
| 3063 | __ Csel(OutputRegister(select), |
| 3064 | InputRegisterAt(select, 1), |
| 3065 | InputOperandAt(select, 0), |
| 3066 | csel_cond); |
| 3067 | break; |
| 3068 | case kCselTrueConst: |
| 3069 | __ Csel(OutputRegister(select), |
| 3070 | InputRegisterAt(select, 0), |
| 3071 | InputOperandAt(select, 1), |
| 3072 | csel_cond); |
| 3073 | break; |
| 3074 | case kFcsel: |
| 3075 | __ Fcsel(OutputFPRegister(select), |
| 3076 | InputFPRegisterAt(select, 1), |
| 3077 | InputFPRegisterAt(select, 0), |
| 3078 | csel_cond); |
| 3079 | break; |
| 3080 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3083 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3084 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3085 | } |
| 3086 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3087 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3088 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | void CodeGeneratorARM64::GenerateNop() { |
| 3092 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3095 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3096 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3100 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3104 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3108 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3109 | } |
| 3110 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3111 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 3112 | return kEmitCompilerReadBarrier && |
| 3113 | (kUseBakerReadBarrier || |
| 3114 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3115 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3116 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 3117 | } |
| 3118 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3119 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3120 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3121 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3122 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3123 | case TypeCheckKind::kExactCheck: |
| 3124 | case TypeCheckKind::kAbstractClassCheck: |
| 3125 | case TypeCheckKind::kClassHierarchyCheck: |
| 3126 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3127 | call_kind = |
| 3128 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3129 | break; |
| 3130 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3131 | case TypeCheckKind::kUnresolvedCheck: |
| 3132 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3133 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3134 | break; |
| 3135 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3136 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3137 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3139 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3140 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3141 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3142 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3143 | // When read barriers are enabled, we need a temporary register for |
| 3144 | // some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3145 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3146 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3147 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3151 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3152 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3153 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3154 | Register obj = InputRegisterAt(instruction, 0); |
| 3155 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3156 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3157 | Register out = OutputRegister(instruction); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3158 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3159 | locations->GetTemp(0) : |
| 3160 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3161 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3162 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3163 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3164 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3165 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3166 | vixl::Label done, zero; |
| 3167 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3168 | |
| 3169 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3170 | // Avoid null check if we know `obj` is not null. |
| 3171 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3172 | __ Cbz(obj, &zero); |
| 3173 | } |
| 3174 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3175 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3176 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3177 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3178 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3179 | case TypeCheckKind::kExactCheck: { |
| 3180 | __ Cmp(out, cls); |
| 3181 | __ Cset(out, eq); |
| 3182 | if (zero.IsLinked()) { |
| 3183 | __ B(&done); |
| 3184 | } |
| 3185 | break; |
| 3186 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3187 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3188 | case TypeCheckKind::kAbstractClassCheck: { |
| 3189 | // If the class is abstract, we eagerly fetch the super class of the |
| 3190 | // object to avoid doing a comparison we know will fail. |
| 3191 | vixl::Label loop, success; |
| 3192 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3193 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3194 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3195 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3196 | __ Cbz(out, &done); |
| 3197 | __ Cmp(out, cls); |
| 3198 | __ B(ne, &loop); |
| 3199 | __ Mov(out, 1); |
| 3200 | if (zero.IsLinked()) { |
| 3201 | __ B(&done); |
| 3202 | } |
| 3203 | break; |
| 3204 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3205 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3206 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3207 | // Walk over the class hierarchy to find a match. |
| 3208 | vixl::Label loop, success; |
| 3209 | __ Bind(&loop); |
| 3210 | __ Cmp(out, cls); |
| 3211 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3212 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3213 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3214 | __ Cbnz(out, &loop); |
| 3215 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3216 | __ B(&done); |
| 3217 | __ Bind(&success); |
| 3218 | __ Mov(out, 1); |
| 3219 | if (zero.IsLinked()) { |
| 3220 | __ B(&done); |
| 3221 | } |
| 3222 | break; |
| 3223 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3224 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3225 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3226 | // Do an exact check. |
| 3227 | vixl::Label exact_check; |
| 3228 | __ Cmp(out, cls); |
| 3229 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3230 | // 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] | 3231 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3232 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3233 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3234 | __ Cbz(out, &done); |
| 3235 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3236 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3237 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3238 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3239 | __ Mov(out, 1); |
| 3240 | __ B(&done); |
| 3241 | break; |
| 3242 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3243 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3244 | case TypeCheckKind::kArrayCheck: { |
| 3245 | __ Cmp(out, cls); |
| 3246 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3247 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3248 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3249 | codegen_->AddSlowPath(slow_path); |
| 3250 | __ B(ne, slow_path->GetEntryLabel()); |
| 3251 | __ Mov(out, 1); |
| 3252 | if (zero.IsLinked()) { |
| 3253 | __ B(&done); |
| 3254 | } |
| 3255 | break; |
| 3256 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3257 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3258 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3259 | case TypeCheckKind::kInterfaceCheck: { |
| 3260 | // Note that we indeed only call on slow path, but we always go |
| 3261 | // into the slow path for the unresolved and interface check |
| 3262 | // cases. |
| 3263 | // |
| 3264 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3265 | // entry point without resorting to a type checking slow path |
| 3266 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3267 | // require to assign fixed registers for the inputs of this |
| 3268 | // HInstanceOf instruction (following the runtime calling |
| 3269 | // convention), which might be cluttered by the potential first |
| 3270 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3271 | // |
| 3272 | // TODO: Introduce a new runtime entry point taking the object |
| 3273 | // to test (instead of its class) as argument, and let it deal |
| 3274 | // with the read barrier issues. This will let us refactor this |
| 3275 | // case of the `switch` code as it was previously (with a direct |
| 3276 | // call to the runtime not using a type checking slow path). |
| 3277 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3278 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3279 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3280 | /* is_fatal */ false); |
| 3281 | codegen_->AddSlowPath(slow_path); |
| 3282 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3283 | if (zero.IsLinked()) { |
| 3284 | __ B(&done); |
| 3285 | } |
| 3286 | break; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | if (zero.IsLinked()) { |
| 3291 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3292 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | if (done.IsLinked()) { |
| 3296 | __ Bind(&done); |
| 3297 | } |
| 3298 | |
| 3299 | if (slow_path != nullptr) { |
| 3300 | __ Bind(slow_path->GetExitLabel()); |
| 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3305 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3306 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3307 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3308 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3309 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3310 | case TypeCheckKind::kExactCheck: |
| 3311 | case TypeCheckKind::kAbstractClassCheck: |
| 3312 | case TypeCheckKind::kClassHierarchyCheck: |
| 3313 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3314 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3315 | LocationSummary::kCallOnSlowPath : |
| 3316 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3317 | break; |
| 3318 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3319 | case TypeCheckKind::kUnresolvedCheck: |
| 3320 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3321 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3322 | break; |
| 3323 | } |
| 3324 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3325 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3326 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3327 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3328 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3329 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3330 | // When read barriers are enabled, we need an additional temporary |
| 3331 | // register for some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3332 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
| 3333 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3338 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3339 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3340 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3341 | Register obj = InputRegisterAt(instruction, 0); |
| 3342 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3343 | Location temp_loc = locations->GetTemp(0); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3344 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3345 | locations->GetTemp(1) : |
| 3346 | Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3347 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3348 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3349 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3350 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3351 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3352 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3353 | bool is_type_check_slow_path_fatal = |
| 3354 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3355 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3356 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3357 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3358 | !instruction->CanThrowIntoCatchBlock(); |
| 3359 | SlowPathCodeARM64* type_check_slow_path = |
| 3360 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3361 | is_type_check_slow_path_fatal); |
| 3362 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3363 | |
| 3364 | vixl::Label done; |
| 3365 | // Avoid null check if we know obj is not null. |
| 3366 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3367 | __ Cbz(obj, &done); |
| 3368 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3369 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3370 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3371 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3372 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3373 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3374 | case TypeCheckKind::kExactCheck: |
| 3375 | case TypeCheckKind::kArrayCheck: { |
| 3376 | __ Cmp(temp, cls); |
| 3377 | // Jump to slow path for throwing the exception or doing a |
| 3378 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3379 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3380 | break; |
| 3381 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3382 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3383 | case TypeCheckKind::kAbstractClassCheck: { |
| 3384 | // If the class is abstract, we eagerly fetch the super class of the |
| 3385 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3386 | vixl::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3387 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3388 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3389 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3390 | |
| 3391 | // If the class reference currently in `temp` is not null, jump |
| 3392 | // to the `compare_classes` label to compare it with the checked |
| 3393 | // class. |
| 3394 | __ Cbnz(temp, &compare_classes); |
| 3395 | // Otherwise, jump to the slow path to throw the exception. |
| 3396 | // |
| 3397 | // But before, move back the object's class into `temp` before |
| 3398 | // going into the slow path, as it has been overwritten in the |
| 3399 | // meantime. |
| 3400 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3401 | GenerateReferenceLoadTwoRegisters( |
| 3402 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3403 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3404 | |
| 3405 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3406 | __ Cmp(temp, cls); |
| 3407 | __ B(ne, &loop); |
| 3408 | break; |
| 3409 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3410 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3411 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3412 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3413 | vixl::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3414 | __ Bind(&loop); |
| 3415 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3416 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3417 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3418 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3419 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3420 | |
| 3421 | // If the class reference currently in `temp` is not null, jump |
| 3422 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3423 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3424 | // Otherwise, jump to the slow path to throw the exception. |
| 3425 | // |
| 3426 | // But before, move back the object's class into `temp` before |
| 3427 | // going into the slow path, as it has been overwritten in the |
| 3428 | // meantime. |
| 3429 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3430 | GenerateReferenceLoadTwoRegisters( |
| 3431 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3432 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 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. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3438 | vixl::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3439 | __ Cmp(temp, cls); |
| 3440 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3441 | |
| 3442 | // 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] | 3443 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3444 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3445 | |
| 3446 | // If the component type is not null (i.e. the object is indeed |
| 3447 | // an array), jump to label `check_non_primitive_component_type` |
| 3448 | // to further check that this component type is not a primitive |
| 3449 | // type. |
| 3450 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3451 | // Otherwise, jump to the slow path to throw the exception. |
| 3452 | // |
| 3453 | // But before, move back the object's class into `temp` before |
| 3454 | // going into the slow path, as it has been overwritten in the |
| 3455 | // meantime. |
| 3456 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3457 | GenerateReferenceLoadTwoRegisters( |
| 3458 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3459 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3460 | |
| 3461 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3462 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3463 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3464 | __ Cbz(temp, &done); |
| 3465 | // Same comment as above regarding `temp` and the slow path. |
| 3466 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3467 | GenerateReferenceLoadTwoRegisters( |
| 3468 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3469 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3470 | break; |
| 3471 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3472 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3473 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3474 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3475 | // We always go into the type check slow path for the unresolved |
| 3476 | // and interface check cases. |
| 3477 | // |
| 3478 | // We cannot directly call the CheckCast runtime entry point |
| 3479 | // without resorting to a type checking slow path here (i.e. by |
| 3480 | // calling InvokeRuntime directly), as it would require to |
| 3481 | // assign fixed registers for the inputs of this HInstanceOf |
| 3482 | // instruction (following the runtime calling convention), which |
| 3483 | // might be cluttered by the potential first read barrier |
| 3484 | // emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3485 | // |
| 3486 | // TODO: Introduce a new runtime entry point taking the object |
| 3487 | // to test (instead of its class) as argument, and let it deal |
| 3488 | // with the read barrier issues. This will let us refactor this |
| 3489 | // case of the `switch` code as it was previously (with a direct |
| 3490 | // call to the runtime not using a type checking slow path). |
| 3491 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3492 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3493 | break; |
| 3494 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3495 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3496 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3497 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3500 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3501 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3502 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3503 | } |
| 3504 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3505 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3506 | // Will be generated at use site. |
| 3507 | } |
| 3508 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3509 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3510 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3511 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3512 | } |
| 3513 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3514 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3515 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3518 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3519 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3520 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3521 | // the method_idx. |
| 3522 | HandleInvoke(invoke); |
| 3523 | } |
| 3524 | |
| 3525 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3526 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3527 | } |
| 3528 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3529 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3530 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3531 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3532 | } |
| 3533 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3534 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3535 | HandleInvoke(invoke); |
| 3536 | } |
| 3537 | |
| 3538 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3539 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3540 | LocationSummary* locations = invoke->GetLocations(); |
| 3541 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3542 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3543 | Offset class_offset = mirror::Object::ClassOffset(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3544 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3545 | |
| 3546 | // The register ip1 is required to be used for the hidden argument in |
| 3547 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3548 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3549 | UseScratchRegisterScope scratch_scope(masm); |
| 3550 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3551 | scratch_scope.Exclude(ip1); |
| 3552 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3553 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3554 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3555 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3556 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3557 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3558 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3559 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3560 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3561 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3562 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3563 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3564 | // emit a read barrier for the previous class reference load. |
| 3565 | // However this is not required in practice, as this is an |
| 3566 | // intermediate/temporary reference and because the current |
| 3567 | // concurrent copying collector keeps the from-space memory |
| 3568 | // intact/accessible until the end of the marking phase (the |
| 3569 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3570 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | df2d4f2 | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3571 | __ Ldr(temp, |
| 3572 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3573 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3574 | invoke->GetImtIndex() % ImTable::kSize, kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3575 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3576 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3577 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3578 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3579 | // lr(); |
| 3580 | __ Blr(lr); |
| 3581 | DCHECK(!codegen_->IsLeafMethod()); |
| 3582 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3583 | } |
| 3584 | |
| 3585 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3586 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3587 | if (intrinsic.TryDispatch(invoke)) { |
| 3588 | return; |
| 3589 | } |
| 3590 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3591 | HandleInvoke(invoke); |
| 3592 | } |
| 3593 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3594 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3595 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3596 | // art::PrepareForRegisterAllocation. |
| 3597 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3598 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3599 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3600 | if (intrinsic.TryDispatch(invoke)) { |
| 3601 | return; |
| 3602 | } |
| 3603 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3604 | HandleInvoke(invoke); |
| 3605 | } |
| 3606 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3607 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3608 | if (invoke->GetLocations()->Intrinsified()) { |
| 3609 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3610 | intrinsic.Dispatch(invoke); |
| 3611 | return true; |
| 3612 | } |
| 3613 | return false; |
| 3614 | } |
| 3615 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3616 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3617 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 3618 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3619 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3620 | return desired_dispatch_info; |
| 3621 | } |
| 3622 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3623 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3624 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3625 | bool direct_code_loaded = false; |
| 3626 | switch (invoke->GetCodePtrLocation()) { |
| 3627 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3628 | // LR = code address from literal pool with link-time patch. |
| 3629 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3630 | direct_code_loaded = true; |
| 3631 | break; |
| 3632 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3633 | // LR = invoke->GetDirectCodePtr(); |
| 3634 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3635 | direct_code_loaded = true; |
| 3636 | break; |
| 3637 | default: |
| 3638 | break; |
| 3639 | } |
| 3640 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3641 | // 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] | 3642 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3643 | switch (invoke->GetMethodLoadKind()) { |
| 3644 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3645 | // temp = thread->string_init_entrypoint |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3646 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, invoke->GetStringInitOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3649 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3650 | break; |
| 3651 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3652 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3653 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3656 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3657 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3658 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3659 | break; |
| 3660 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3661 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3662 | const DexFile& dex_file = *invoke->GetTargetMethod().dex_file; |
| 3663 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
| 3664 | vixl::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3665 | { |
| 3666 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3667 | __ Bind(adrp_label); |
| 3668 | __ adrp(XRegisterFrom(temp), /* offset placeholder */ 0); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3669 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3670 | // Add LDR with its PC-relative DexCache access patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3671 | vixl::Label* ldr_label = |
| 3672 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3673 | { |
| 3674 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3675 | __ Bind(ldr_label); |
| 3676 | __ ldr(XRegisterFrom(temp), MemOperand(XRegisterFrom(temp), /* offset placeholder */ 0)); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3677 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3678 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3679 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3680 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3681 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3682 | Register reg = XRegisterFrom(temp); |
| 3683 | Register method_reg; |
| 3684 | if (current_method.IsRegister()) { |
| 3685 | method_reg = XRegisterFrom(current_method); |
| 3686 | } else { |
| 3687 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3688 | DCHECK(!current_method.IsValid()); |
| 3689 | method_reg = reg; |
| 3690 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3691 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3692 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3693 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3694 | __ Ldr(reg.X(), |
| 3695 | MemOperand(method_reg.X(), |
| 3696 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64WordSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3697 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3698 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3699 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3700 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3701 | break; |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | switch (invoke->GetCodePtrLocation()) { |
| 3706 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3707 | __ Bl(&frame_entry_label_); |
| 3708 | break; |
| 3709 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3710 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3711 | vixl::Label* label = &relative_call_patches_.back().label; |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3712 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3713 | __ Bind(label); |
| 3714 | __ 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] | 3715 | break; |
| 3716 | } |
| 3717 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3718 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3719 | // LR prepared above for better instruction scheduling. |
| 3720 | DCHECK(direct_code_loaded); |
| 3721 | // lr() |
| 3722 | __ Blr(lr); |
| 3723 | break; |
| 3724 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3725 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3726 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3727 | XRegisterFrom(callee_method), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3728 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value())); |
| 3729 | // lr() |
| 3730 | __ Blr(lr); |
| 3731 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3732 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3733 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3734 | DCHECK(!IsLeafMethod()); |
| 3735 | } |
| 3736 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3737 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3738 | // Use the calling convention instead of the location of the receiver, as |
| 3739 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3740 | // slow path, the arguments have been moved to the right place, so here we are |
| 3741 | // guaranteed that the receiver is the first register of the calling convention. |
| 3742 | InvokeDexCallingConvention calling_convention; |
| 3743 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3744 | Register temp = XRegisterFrom(temp_in); |
| 3745 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3746 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3747 | Offset class_offset = mirror::Object::ClassOffset(); |
| 3748 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 3749 | |
| 3750 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3751 | |
| 3752 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3753 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3754 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3755 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3756 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3757 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3758 | // intermediate/temporary reference and because the current |
| 3759 | // concurrent copying collector keeps the from-space memory |
| 3760 | // intact/accessible until the end of the marking phase (the |
| 3761 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3762 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3763 | // temp = temp->GetMethodAt(method_offset); |
| 3764 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3765 | // lr = temp->GetEntryPoint(); |
| 3766 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3767 | // lr(); |
| 3768 | __ Blr(lr); |
| 3769 | } |
| 3770 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3771 | vixl::Label* CodeGeneratorARM64::NewPcRelativeStringPatch(const DexFile& dex_file, |
| 3772 | uint32_t string_index, |
| 3773 | vixl::Label* adrp_label) { |
| 3774 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 3775 | } |
| 3776 | |
| 3777 | vixl::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 3778 | uint32_t element_offset, |
| 3779 | vixl::Label* adrp_label) { |
| 3780 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 3781 | } |
| 3782 | |
| 3783 | vixl::Label* CodeGeneratorARM64::NewPcRelativePatch(const DexFile& dex_file, |
| 3784 | uint32_t offset_or_index, |
| 3785 | vixl::Label* adrp_label, |
| 3786 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 3787 | // Add a patch entry and return the label. |
| 3788 | patches->emplace_back(dex_file, offset_or_index); |
| 3789 | PcRelativePatchInfo* info = &patches->back(); |
| 3790 | vixl::Label* label = &info->label; |
| 3791 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 3792 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 3793 | return label; |
| 3794 | } |
| 3795 | |
| 3796 | vixl::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
| 3797 | const DexFile& dex_file, uint32_t string_index) { |
| 3798 | return boot_image_string_patches_.GetOrCreate( |
| 3799 | StringReference(&dex_file, string_index), |
| 3800 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3801 | } |
| 3802 | |
| 3803 | vixl::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
| 3804 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 3805 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 3806 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 3807 | } |
| 3808 | |
| 3809 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral(uint64_t address) { |
| 3810 | return DeduplicateUint64Literal(address); |
| 3811 | } |
| 3812 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3813 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3814 | DCHECK(linker_patches->empty()); |
| 3815 | size_t size = |
| 3816 | method_patches_.size() + |
| 3817 | call_patches_.size() + |
| 3818 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3819 | pc_relative_dex_cache_patches_.size() + |
| 3820 | boot_image_string_patches_.size() + |
| 3821 | pc_relative_string_patches_.size() + |
| 3822 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3823 | linker_patches->reserve(size); |
| 3824 | for (const auto& entry : method_patches_) { |
| 3825 | const MethodReference& target_method = entry.first; |
| 3826 | vixl::Literal<uint64_t>* literal = entry.second; |
| 3827 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->offset(), |
| 3828 | target_method.dex_file, |
| 3829 | target_method.dex_method_index)); |
| 3830 | } |
| 3831 | for (const auto& entry : call_patches_) { |
| 3832 | const MethodReference& target_method = entry.first; |
| 3833 | vixl::Literal<uint64_t>* literal = entry.second; |
| 3834 | linker_patches->push_back(LinkerPatch::CodePatch(literal->offset(), |
| 3835 | target_method.dex_file, |
| 3836 | target_method.dex_method_index)); |
| 3837 | } |
| 3838 | for (const MethodPatchInfo<vixl::Label>& info : relative_call_patches_) { |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3839 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3840 | info.target_method.dex_file, |
| 3841 | info.target_method.dex_method_index)); |
| 3842 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3843 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3844 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3845 | &info.target_dex_file, |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3846 | info.pc_insn_label->location(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3847 | info.offset_or_index)); |
| 3848 | } |
| 3849 | for (const auto& entry : boot_image_string_patches_) { |
| 3850 | const StringReference& target_string = entry.first; |
| 3851 | vixl::Literal<uint32_t>* literal = entry.second; |
| 3852 | linker_patches->push_back(LinkerPatch::StringPatch(literal->offset(), |
| 3853 | target_string.dex_file, |
| 3854 | target_string.string_index)); |
| 3855 | } |
| 3856 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 3857 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(info.label.location(), |
| 3858 | &info.target_dex_file, |
| 3859 | info.pc_insn_label->location(), |
| 3860 | info.offset_or_index)); |
| 3861 | } |
| 3862 | for (const auto& entry : boot_image_address_patches_) { |
| 3863 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 3864 | vixl::Literal<uint32_t>* literal = entry.second; |
| 3865 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->offset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3869 | vixl::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
| 3870 | Uint32ToLiteralMap* map) { |
| 3871 | return map->GetOrCreate( |
| 3872 | value, |
| 3873 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 3874 | } |
| 3875 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3876 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3877 | return uint64_literals_.GetOrCreate( |
| 3878 | value, |
| 3879 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
| 3883 | MethodReference target_method, |
| 3884 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3885 | return map->GetOrCreate( |
| 3886 | target_method, |
| 3887 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
| 3891 | MethodReference target_method) { |
| 3892 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 3893 | } |
| 3894 | |
| 3895 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
| 3896 | MethodReference target_method) { |
| 3897 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 3898 | } |
| 3899 | |
| 3900 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3901 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3902 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3903 | // art::PrepareForRegisterAllocation. |
| 3904 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3905 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3906 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3907 | return; |
| 3908 | } |
| 3909 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3910 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3911 | LocationSummary* locations = invoke->GetLocations(); |
| 3912 | codegen_->GenerateStaticOrDirectCall( |
| 3913 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3914 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3918 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3919 | return; |
| 3920 | } |
| 3921 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3922 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3923 | DCHECK(!codegen_->IsLeafMethod()); |
| 3924 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3925 | } |
| 3926 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3927 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3928 | InvokeRuntimeCallingConvention calling_convention; |
| 3929 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3930 | cls, |
| 3931 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3932 | LocationFrom(vixl::x0), |
| 3933 | /* code_generator_supports_read_barrier */ true); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3937 | if (cls->NeedsAccessCheck()) { |
| 3938 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
| 3939 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 3940 | cls, |
| 3941 | cls->GetDexPc(), |
| 3942 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3943 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3944 | return; |
| 3945 | } |
| 3946 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3947 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3948 | Register out = OutputRegister(cls); |
| 3949 | Register current_method = InputRegisterAt(cls, 0); |
| 3950 | if (cls->IsReferrersClass()) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3951 | DCHECK(!cls->CanCallRuntime()); |
| 3952 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3953 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 3954 | GenerateGcRootFieldLoad( |
| 3955 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3956 | } else { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3957 | MemberOffset resolved_types_offset = ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3958 | // /* GcRoot<mirror::Class>[] */ out = |
| 3959 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3960 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3961 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 3962 | GenerateGcRootFieldLoad( |
| 3963 | cls, out_loc, out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3964 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 3965 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 3966 | DCHECK(cls->CanCallRuntime()); |
| 3967 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3968 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3969 | codegen_->AddSlowPath(slow_path); |
| 3970 | if (!cls->IsInDexCache()) { |
| 3971 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 3972 | } |
| 3973 | if (cls->MustGenerateClinitCheck()) { |
| 3974 | GenerateClassInitializationCheck(slow_path, out); |
| 3975 | } else { |
| 3976 | __ Bind(slow_path->GetExitLabel()); |
| 3977 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | } |
| 3981 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3982 | static MemOperand GetExceptionTlsAddress() { |
| 3983 | return MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); |
| 3984 | } |
| 3985 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3986 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 3987 | LocationSummary* locations = |
| 3988 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3989 | locations->SetOut(Location::RequiresRegister()); |
| 3990 | } |
| 3991 | |
| 3992 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3993 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 3994 | } |
| 3995 | |
| 3996 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 3997 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 3998 | } |
| 3999 | |
| 4000 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4001 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4004 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4005 | HLoadString::LoadKind desired_string_load_kind) { |
| 4006 | if (kEmitCompilerReadBarrier) { |
| 4007 | switch (desired_string_load_kind) { |
| 4008 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4009 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4010 | case HLoadString::LoadKind::kBootImageAddress: |
| 4011 | // TODO: Implement for read barrier. |
| 4012 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 4013 | default: |
| 4014 | break; |
| 4015 | } |
| 4016 | } |
| 4017 | switch (desired_string_load_kind) { |
| 4018 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4019 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4020 | break; |
| 4021 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4022 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4023 | break; |
| 4024 | case HLoadString::LoadKind::kBootImageAddress: |
| 4025 | break; |
| 4026 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | e5de54c | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4027 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4028 | break; |
| 4029 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | e5de54c | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4030 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4031 | break; |
| 4032 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4033 | break; |
| 4034 | } |
| 4035 | return desired_string_load_kind; |
| 4036 | } |
| 4037 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4038 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4039 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4040 | ? LocationSummary::kCallOnSlowPath |
| 4041 | : LocationSummary::kNoCall; |
| 4042 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4043 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 4044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4045 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4046 | locations->SetOut(Location::RequiresRegister()); |
| 4047 | } |
| 4048 | |
| 4049 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4050 | Location out_loc = load->GetLocations()->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4051 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4052 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4053 | switch (load->GetLoadKind()) { |
| 4054 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4055 | DCHECK(!kEmitCompilerReadBarrier); |
| 4056 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4057 | load->GetStringIndex())); |
| 4058 | return; // No dex cache slow path. |
| 4059 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 4060 | DCHECK(!kEmitCompilerReadBarrier); |
| 4061 | // Add ADRP with its PC-relative String patch. |
| 4062 | const DexFile& dex_file = load->GetDexFile(); |
| 4063 | uint32_t string_index = load->GetStringIndex(); |
| 4064 | vixl::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 4065 | { |
| 4066 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4067 | __ Bind(adrp_label); |
| 4068 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4069 | } |
| 4070 | // Add ADD with its PC-relative String patch. |
| 4071 | vixl::Label* add_label = |
| 4072 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 4073 | { |
| 4074 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4075 | __ Bind(add_label); |
| 4076 | __ add(out.X(), out.X(), Operand(/* offset placeholder */ 0)); |
| 4077 | } |
| 4078 | return; // No dex cache slow path. |
| 4079 | } |
| 4080 | case HLoadString::LoadKind::kBootImageAddress: { |
| 4081 | DCHECK(!kEmitCompilerReadBarrier); |
| 4082 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4083 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4084 | return; // No dex cache slow path. |
| 4085 | } |
| 4086 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 4087 | DCHECK_NE(load->GetAddress(), 0u); |
| 4088 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4089 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4090 | // multiple strings, simply split the dex cache address to a 16KiB aligned base |
| 4091 | // loaded from a literal and the remaining offset embedded in the load. |
| 4092 | static_assert(sizeof(GcRoot<mirror::String>) == 4u, "Expected GC root to be 4 bytes."); |
| 4093 | DCHECK_ALIGNED(load->GetAddress(), 4u); |
| 4094 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4095 | uint64_t base_address = load->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4096 | uint32_t offset = load->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4097 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4098 | GenerateGcRootFieldLoad(load, out_loc, out.X(), offset); |
| 4099 | break; |
| 4100 | } |
| 4101 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 4102 | // Add ADRP with its PC-relative DexCache access patch. |
| 4103 | const DexFile& dex_file = load->GetDexFile(); |
| 4104 | uint32_t element_offset = load->GetDexCacheElementOffset(); |
| 4105 | vixl::Label* adrp_label = codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
| 4106 | { |
| 4107 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4108 | __ Bind(adrp_label); |
| 4109 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4110 | } |
| 4111 | // Add LDR with its PC-relative DexCache access patch. |
| 4112 | vixl::Label* ldr_label = |
| 4113 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4114 | GenerateGcRootFieldLoad(load, out_loc, out.X(), /* offset placeholder */ 0, ldr_label); |
| 4115 | break; |
| 4116 | } |
| 4117 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 4118 | Register current_method = InputRegisterAt(load, 0); |
| 4119 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4120 | GenerateGcRootFieldLoad( |
| 4121 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 4122 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 4123 | __ Ldr(out.X(), HeapOperand(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 4124 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 4125 | GenerateGcRootFieldLoad( |
| 4126 | load, out_loc, out.X(), CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 4127 | break; |
| 4128 | } |
| 4129 | default: |
| 4130 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 4131 | UNREACHABLE(); |
| 4132 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4133 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4134 | if (!load->IsInDexCache()) { |
| 4135 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 4136 | codegen_->AddSlowPath(slow_path); |
| 4137 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4138 | __ Bind(slow_path->GetExitLabel()); |
| 4139 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4142 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4143 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4144 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4145 | } |
| 4146 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4147 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4148 | // Will be generated at use site. |
| 4149 | } |
| 4150 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4151 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4152 | LocationSummary* locations = |
| 4153 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4154 | InvokeRuntimeCallingConvention calling_convention; |
| 4155 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4156 | } |
| 4157 | |
| 4158 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4159 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4160 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4161 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4162 | instruction->GetDexPc(), |
| 4163 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4164 | if (instruction->IsEnter()) { |
| 4165 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4166 | } else { |
| 4167 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4168 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4169 | } |
| 4170 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4171 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4172 | LocationSummary* locations = |
| 4173 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4174 | switch (mul->GetResultType()) { |
| 4175 | case Primitive::kPrimInt: |
| 4176 | case Primitive::kPrimLong: |
| 4177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4178 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4179 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4180 | break; |
| 4181 | |
| 4182 | case Primitive::kPrimFloat: |
| 4183 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4184 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4185 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4186 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4187 | break; |
| 4188 | |
| 4189 | default: |
| 4190 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4191 | } |
| 4192 | } |
| 4193 | |
| 4194 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4195 | switch (mul->GetResultType()) { |
| 4196 | case Primitive::kPrimInt: |
| 4197 | case Primitive::kPrimLong: |
| 4198 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4199 | break; |
| 4200 | |
| 4201 | case Primitive::kPrimFloat: |
| 4202 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4203 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4204 | break; |
| 4205 | |
| 4206 | default: |
| 4207 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4208 | } |
| 4209 | } |
| 4210 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4211 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4212 | LocationSummary* locations = |
| 4213 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4214 | switch (neg->GetResultType()) { |
| 4215 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4216 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4217 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4218 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4219 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4220 | |
| 4221 | case Primitive::kPrimFloat: |
| 4222 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4223 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4224 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4225 | break; |
| 4226 | |
| 4227 | default: |
| 4228 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4233 | switch (neg->GetResultType()) { |
| 4234 | case Primitive::kPrimInt: |
| 4235 | case Primitive::kPrimLong: |
| 4236 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4237 | break; |
| 4238 | |
| 4239 | case Primitive::kPrimFloat: |
| 4240 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4241 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4242 | break; |
| 4243 | |
| 4244 | default: |
| 4245 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4250 | LocationSummary* locations = |
| 4251 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4252 | InvokeRuntimeCallingConvention calling_convention; |
| 4253 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4254 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4255 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4256 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4260 | LocationSummary* locations = instruction->GetLocations(); |
| 4261 | InvokeRuntimeCallingConvention calling_convention; |
| 4262 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4263 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4264 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4265 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4266 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4267 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4268 | instruction, |
| 4269 | instruction->GetDexPc(), |
| 4270 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4271 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4274 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4275 | LocationSummary* locations = |
| 4276 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4277 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4278 | if (instruction->IsStringAlloc()) { |
| 4279 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4280 | } else { |
| 4281 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4282 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4283 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4284 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4285 | } |
| 4286 | |
| 4287 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4288 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4289 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4290 | if (instruction->IsStringAlloc()) { |
| 4291 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4292 | Location temp = instruction->GetLocations()->GetTemp(0); |
| 4293 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 4294 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4295 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4296 | __ Blr(lr); |
| 4297 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4298 | } else { |
| 4299 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4300 | instruction, |
| 4301 | instruction->GetDexPc(), |
| 4302 | nullptr); |
| 4303 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4304 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4308 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4309 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4310 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4314 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4315 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4316 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4317 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4318 | break; |
| 4319 | |
| 4320 | default: |
| 4321 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4322 | } |
| 4323 | } |
| 4324 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4325 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4326 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4328 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4329 | } |
| 4330 | |
| 4331 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4332 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1)); |
| 4333 | } |
| 4334 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4335 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4336 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4337 | ? LocationSummary::kCallOnSlowPath |
| 4338 | : LocationSummary::kNoCall; |
| 4339 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4340 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4341 | if (instruction->HasUses()) { |
| 4342 | locations->SetOut(Location::SameAsFirstInput()); |
| 4343 | } |
| 4344 | } |
| 4345 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4346 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4347 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4348 | return; |
| 4349 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4350 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4351 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4352 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4353 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4354 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4357 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4358 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4359 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4360 | |
| 4361 | LocationSummary* locations = instruction->GetLocations(); |
| 4362 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4363 | |
| 4364 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4365 | } |
| 4366 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4367 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4368 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4371 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4372 | HandleBinaryOp(instruction); |
| 4373 | } |
| 4374 | |
| 4375 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4376 | HandleBinaryOp(instruction); |
| 4377 | } |
| 4378 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4379 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4380 | LOG(FATAL) << "Unreachable"; |
| 4381 | } |
| 4382 | |
| 4383 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4384 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4385 | } |
| 4386 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4387 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4388 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4389 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4390 | if (location.IsStackSlot()) { |
| 4391 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4392 | } else if (location.IsDoubleStackSlot()) { |
| 4393 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4394 | } |
| 4395 | locations->SetOut(location); |
| 4396 | } |
| 4397 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4398 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4399 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4400 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4404 | LocationSummary* locations = |
| 4405 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4406 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4410 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4411 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4415 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 3925c6e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4416 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4417 | locations->SetInAt(i, Location::Any()); |
| 4418 | } |
| 4419 | locations->SetOut(Location::Any()); |
| 4420 | } |
| 4421 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4422 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4423 | LOG(FATAL) << "Unreachable"; |
| 4424 | } |
| 4425 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4426 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4427 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4428 | LocationSummary::CallKind call_kind = |
| 4429 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4430 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4431 | |
| 4432 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4433 | case Primitive::kPrimInt: |
| 4434 | case Primitive::kPrimLong: |
| 4435 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4436 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4437 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4438 | break; |
| 4439 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4440 | case Primitive::kPrimFloat: |
| 4441 | case Primitive::kPrimDouble: { |
| 4442 | InvokeRuntimeCallingConvention calling_convention; |
| 4443 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4444 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4445 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4446 | |
| 4447 | break; |
| 4448 | } |
| 4449 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4450 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4451 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4456 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4457 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4458 | switch (type) { |
| 4459 | case Primitive::kPrimInt: |
| 4460 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4461 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4462 | break; |
| 4463 | } |
| 4464 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4465 | case Primitive::kPrimFloat: |
| 4466 | case Primitive::kPrimDouble: { |
| 4467 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 4468 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4469 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4470 | if (type == Primitive::kPrimFloat) { |
| 4471 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4472 | } else { |
| 4473 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4474 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4475 | break; |
| 4476 | } |
| 4477 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4478 | default: |
| 4479 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4480 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4484 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4485 | memory_barrier->SetLocations(nullptr); |
| 4486 | } |
| 4487 | |
| 4488 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4489 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4490 | } |
| 4491 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4492 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4493 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4494 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4495 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4496 | } |
| 4497 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4498 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4499 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4503 | instruction->SetLocations(nullptr); |
| 4504 | } |
| 4505 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4506 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4507 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4510 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4511 | HandleBinaryOp(ror); |
| 4512 | } |
| 4513 | |
| 4514 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4515 | HandleBinaryOp(ror); |
| 4516 | } |
| 4517 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4518 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4519 | HandleShift(shl); |
| 4520 | } |
| 4521 | |
| 4522 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4523 | HandleShift(shl); |
| 4524 | } |
| 4525 | |
| 4526 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4527 | HandleShift(shr); |
| 4528 | } |
| 4529 | |
| 4530 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4531 | HandleShift(shr); |
| 4532 | } |
| 4533 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4534 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4535 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4539 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4542 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4543 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4547 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4551 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4552 | } |
| 4553 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4554 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4555 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4556 | } |
| 4557 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4558 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4559 | HUnresolvedInstanceFieldGet* instruction) { |
| 4560 | FieldAccessCallingConventionARM64 calling_convention; |
| 4561 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4562 | instruction, instruction->GetFieldType(), calling_convention); |
| 4563 | } |
| 4564 | |
| 4565 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4566 | HUnresolvedInstanceFieldGet* instruction) { |
| 4567 | FieldAccessCallingConventionARM64 calling_convention; |
| 4568 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4569 | instruction->GetFieldType(), |
| 4570 | instruction->GetFieldIndex(), |
| 4571 | instruction->GetDexPc(), |
| 4572 | calling_convention); |
| 4573 | } |
| 4574 | |
| 4575 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4576 | HUnresolvedInstanceFieldSet* instruction) { |
| 4577 | FieldAccessCallingConventionARM64 calling_convention; |
| 4578 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4579 | instruction, instruction->GetFieldType(), calling_convention); |
| 4580 | } |
| 4581 | |
| 4582 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4583 | HUnresolvedInstanceFieldSet* instruction) { |
| 4584 | FieldAccessCallingConventionARM64 calling_convention; |
| 4585 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4586 | instruction->GetFieldType(), |
| 4587 | instruction->GetFieldIndex(), |
| 4588 | instruction->GetDexPc(), |
| 4589 | calling_convention); |
| 4590 | } |
| 4591 | |
| 4592 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4593 | HUnresolvedStaticFieldGet* instruction) { |
| 4594 | FieldAccessCallingConventionARM64 calling_convention; |
| 4595 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4596 | instruction, instruction->GetFieldType(), calling_convention); |
| 4597 | } |
| 4598 | |
| 4599 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4600 | HUnresolvedStaticFieldGet* instruction) { |
| 4601 | FieldAccessCallingConventionARM64 calling_convention; |
| 4602 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4603 | instruction->GetFieldType(), |
| 4604 | instruction->GetFieldIndex(), |
| 4605 | instruction->GetDexPc(), |
| 4606 | calling_convention); |
| 4607 | } |
| 4608 | |
| 4609 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4610 | HUnresolvedStaticFieldSet* instruction) { |
| 4611 | FieldAccessCallingConventionARM64 calling_convention; |
| 4612 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4613 | instruction, instruction->GetFieldType(), calling_convention); |
| 4614 | } |
| 4615 | |
| 4616 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4617 | HUnresolvedStaticFieldSet* instruction) { |
| 4618 | FieldAccessCallingConventionARM64 calling_convention; |
| 4619 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4620 | instruction->GetFieldType(), |
| 4621 | instruction->GetFieldIndex(), |
| 4622 | instruction->GetDexPc(), |
| 4623 | calling_convention); |
| 4624 | } |
| 4625 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4626 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4627 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4628 | } |
| 4629 | |
| 4630 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4631 | HBasicBlock* block = instruction->GetBlock(); |
| 4632 | if (block->GetLoopInformation() != nullptr) { |
| 4633 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4634 | // The back edge will generate the suspend check. |
| 4635 | return; |
| 4636 | } |
| 4637 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4638 | // The goto will generate the suspend check. |
| 4639 | return; |
| 4640 | } |
| 4641 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4644 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 4645 | LocationSummary* locations = |
| 4646 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4647 | InvokeRuntimeCallingConvention calling_convention; |
| 4648 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4649 | } |
| 4650 | |
| 4651 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 4652 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4653 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4654 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4658 | LocationSummary* locations = |
| 4659 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 4660 | Primitive::Type input_type = conversion->GetInputType(); |
| 4661 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 4662 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4663 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4664 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4665 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4666 | } |
| 4667 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4668 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4669 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4670 | } else { |
| 4671 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4672 | } |
| 4673 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4674 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4675 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4676 | } else { |
| 4677 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4682 | Primitive::Type result_type = conversion->GetResultType(); |
| 4683 | Primitive::Type input_type = conversion->GetInputType(); |
| 4684 | |
| 4685 | DCHECK_NE(input_type, result_type); |
| 4686 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4687 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4688 | int result_size = Primitive::ComponentSize(result_type); |
| 4689 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4690 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4691 | Register output = OutputRegister(conversion); |
| 4692 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4693 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 4694 | // 'int' values are used directly as W registers, discarding the top |
| 4695 | // bits, so we don't need to sign-extend and can just perform a move. |
| 4696 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 4697 | // top 32 bits of the target register. We theoretically could leave those |
| 4698 | // bits unchanged, but we would have to make sure that no code uses a |
| 4699 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 4700 | // zero. |
| 4701 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4702 | } else if (result_type == Primitive::kPrimChar || |
| 4703 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 4704 | __ Ubfx(output, |
| 4705 | output.IsX() ? source.X() : source.W(), |
| 4706 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4707 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4708 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4709 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4710 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4711 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4712 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4713 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4714 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4715 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4716 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4717 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 4718 | } else { |
| 4719 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4720 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4721 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4722 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4723 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4724 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 4725 | HandleShift(ushr); |
| 4726 | } |
| 4727 | |
| 4728 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 4729 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 4733 | HandleBinaryOp(instruction); |
| 4734 | } |
| 4735 | |
| 4736 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 4737 | HandleBinaryOp(instruction); |
| 4738 | } |
| 4739 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4740 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4741 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4742 | LOG(FATAL) << "Unreachable"; |
| 4743 | } |
| 4744 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4745 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4746 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4747 | LOG(FATAL) << "Unreachable"; |
| 4748 | } |
| 4749 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4750 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4751 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4752 | LocationSummary* locations = |
| 4753 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4754 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4755 | } |
| 4756 | |
| 4757 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4758 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4759 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4760 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 4761 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4762 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4763 | // Roughly set 16 as max average assemblies generated per HIR in a graph. |
| 4764 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * vixl::kInstructionSize; |
| 4765 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 4766 | // make sure we don't emit it if the target may run out of range. |
| 4767 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 4768 | // ranges and emit the tables only as required. |
| 4769 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4770 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4771 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4772 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 4773 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 4774 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4775 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4776 | Register temp = temps.AcquireW(); |
| 4777 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 4778 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4779 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4780 | // Jump to successors[0] if value == lower_bound. |
| 4781 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 4782 | int32_t last_index = 0; |
| 4783 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4784 | __ Subs(temp, temp, Operand(2)); |
| 4785 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4786 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4787 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4788 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4789 | } |
| 4790 | if (num_entries - last_index == 2) { |
| 4791 | // The last missing case_value. |
| 4792 | __ Cmp(temp, Operand(1)); |
| 4793 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | // And the default for any other value. |
| 4797 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4798 | __ B(codegen_->GetLabelOf(default_block)); |
| 4799 | } |
| 4800 | } else { |
Alexandre Rames | c393d63 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 4801 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4802 | |
| 4803 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4804 | |
| 4805 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 4806 | // registers, we are free to block one. |
| 4807 | Register temp_w = temps.AcquireW(); |
| 4808 | Register index; |
| 4809 | // Remove the bias. |
| 4810 | if (lower_bound != 0) { |
| 4811 | index = temp_w; |
| 4812 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 4813 | } else { |
| 4814 | index = value_reg; |
| 4815 | } |
| 4816 | |
| 4817 | // Jump to default block if index is out of the range. |
| 4818 | __ Cmp(index, Operand(num_entries)); |
| 4819 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 4820 | |
| 4821 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 4822 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 4823 | // register pressure. |
| 4824 | Register table_base = temps.AcquireX(); |
| 4825 | // Load jump offset from the table. |
| 4826 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 4827 | Register jump_offset = temp_w; |
| 4828 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 4829 | |
| 4830 | // Jump to target block by branching to table_base(pc related) + offset. |
| 4831 | Register target_address = table_base; |
| 4832 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 4833 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4834 | } |
| 4835 | } |
| 4836 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4837 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 4838 | Location out, |
| 4839 | uint32_t offset, |
| 4840 | Location maybe_temp) { |
| 4841 | Primitive::Type type = Primitive::kPrimNot; |
| 4842 | Register out_reg = RegisterFrom(out, type); |
| 4843 | if (kEmitCompilerReadBarrier) { |
| 4844 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4845 | if (kUseBakerReadBarrier) { |
| 4846 | // Load with fast path based Baker's read barrier. |
| 4847 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4848 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4849 | out, |
| 4850 | out_reg, |
| 4851 | offset, |
| 4852 | temp_reg, |
| 4853 | /* needs_null_check */ false, |
| 4854 | /* use_load_acquire */ false); |
| 4855 | } else { |
| 4856 | // Load with slow path based read barrier. |
| 4857 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4858 | // in the following move operation, as we will need it for the |
| 4859 | // read barrier below. |
| 4860 | __ Mov(temp_reg, out_reg); |
| 4861 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4862 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 4863 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4864 | } |
| 4865 | } else { |
| 4866 | // Plain load with no read barrier. |
| 4867 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4868 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 4869 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 4870 | } |
| 4871 | } |
| 4872 | |
| 4873 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 4874 | Location out, |
| 4875 | Location obj, |
| 4876 | uint32_t offset, |
| 4877 | Location maybe_temp) { |
| 4878 | Primitive::Type type = Primitive::kPrimNot; |
| 4879 | Register out_reg = RegisterFrom(out, type); |
| 4880 | Register obj_reg = RegisterFrom(obj, type); |
| 4881 | if (kEmitCompilerReadBarrier) { |
| 4882 | if (kUseBakerReadBarrier) { |
| 4883 | // Load with fast path based Baker's read barrier. |
| 4884 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4885 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4886 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4887 | out, |
| 4888 | obj_reg, |
| 4889 | offset, |
| 4890 | temp_reg, |
| 4891 | /* needs_null_check */ false, |
| 4892 | /* use_load_acquire */ false); |
| 4893 | } else { |
| 4894 | // Load with slow path based read barrier. |
| 4895 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4896 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 4897 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4898 | } |
| 4899 | } else { |
| 4900 | // Plain load with no read barrier. |
| 4901 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4902 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 4903 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 4904 | } |
| 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 4908 | Location root, |
| 4909 | vixl::Register obj, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4910 | uint32_t offset, |
| 4911 | vixl::Label* fixup_label) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4912 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
| 4913 | if (kEmitCompilerReadBarrier) { |
| 4914 | if (kUseBakerReadBarrier) { |
| 4915 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4916 | // Baker's read barrier are used: |
| 4917 | // |
| 4918 | // root = obj.field; |
| 4919 | // if (Thread::Current()->GetIsGcMarking()) { |
| 4920 | // root = ReadBarrier::Mark(root) |
| 4921 | // } |
| 4922 | |
| 4923 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4924 | if (fixup_label == nullptr) { |
| 4925 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 4926 | } else { |
| 4927 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4928 | __ Bind(fixup_label); |
| 4929 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 4930 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4931 | static_assert( |
| 4932 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 4933 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 4934 | "have different sizes."); |
| 4935 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 4936 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 4937 | "have different sizes."); |
| 4938 | |
| 4939 | // Slow path used to mark the GC root `root`. |
| 4940 | SlowPathCodeARM64* slow_path = |
| 4941 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root, root); |
| 4942 | codegen_->AddSlowPath(slow_path); |
| 4943 | |
| 4944 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4945 | UseScratchRegisterScope temps(masm); |
| 4946 | Register temp = temps.AcquireW(); |
| 4947 | // temp = Thread::Current()->GetIsGcMarking() |
| 4948 | __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64WordSize>().Int32Value())); |
| 4949 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 4950 | __ Bind(slow_path->GetExitLabel()); |
| 4951 | } else { |
| 4952 | // GC root loaded through a slow path for read barriers other |
| 4953 | // than Baker's. |
| 4954 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4955 | if (fixup_label == nullptr) { |
| 4956 | __ Add(root_reg.X(), obj.X(), offset); |
| 4957 | } else { |
| 4958 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4959 | __ Bind(fixup_label); |
| 4960 | __ add(root_reg.X(), obj.X(), offset); |
| 4961 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4962 | // /* mirror::Object* */ root = root->Read() |
| 4963 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 4964 | } |
| 4965 | } else { |
| 4966 | // Plain GC root load with no read barrier. |
| 4967 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4968 | if (fixup_label == nullptr) { |
| 4969 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 4970 | } else { |
| 4971 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4972 | __ Bind(fixup_label); |
| 4973 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 4974 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4975 | // Note that GC roots are not affected by heap poisoning, thus we |
| 4976 | // do not have to unpoison `root_reg` here. |
| 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4981 | Location ref, |
| 4982 | vixl::Register obj, |
| 4983 | uint32_t offset, |
| 4984 | Register temp, |
| 4985 | bool needs_null_check, |
| 4986 | bool use_load_acquire) { |
| 4987 | DCHECK(kEmitCompilerReadBarrier); |
| 4988 | DCHECK(kUseBakerReadBarrier); |
| 4989 | |
| 4990 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4991 | Location no_index = Location::NoLocation(); |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 4992 | size_t no_scale_factor = 0U; |
| 4993 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4994 | ref, |
| 4995 | obj, |
| 4996 | offset, |
| 4997 | no_index, |
| 4998 | no_scale_factor, |
| 4999 | temp, |
| 5000 | needs_null_check, |
| 5001 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5005 | Location ref, |
| 5006 | vixl::Register obj, |
| 5007 | uint32_t data_offset, |
| 5008 | Location index, |
| 5009 | Register temp, |
| 5010 | bool needs_null_check) { |
| 5011 | DCHECK(kEmitCompilerReadBarrier); |
| 5012 | DCHECK(kUseBakerReadBarrier); |
| 5013 | |
| 5014 | // Array cells are never volatile variables, therefore array loads |
| 5015 | // never use Load-Acquire instructions on ARM64. |
| 5016 | const bool use_load_acquire = false; |
| 5017 | |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5018 | static_assert( |
| 5019 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5020 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5021 | // /* HeapReference<Object> */ ref = |
| 5022 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5023 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5024 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5025 | ref, |
| 5026 | obj, |
| 5027 | data_offset, |
| 5028 | index, |
| 5029 | scale_factor, |
| 5030 | temp, |
| 5031 | needs_null_check, |
| 5032 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5036 | Location ref, |
| 5037 | vixl::Register obj, |
| 5038 | uint32_t offset, |
| 5039 | Location index, |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5040 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5041 | Register temp, |
| 5042 | bool needs_null_check, |
| 5043 | bool use_load_acquire) { |
| 5044 | DCHECK(kEmitCompilerReadBarrier); |
| 5045 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5046 | // If we are emitting an array load, we should not be using a |
| 5047 | // Load Acquire instruction. In other words: |
| 5048 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5049 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5050 | |
| 5051 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5052 | UseScratchRegisterScope temps(masm); |
| 5053 | |
| 5054 | // In slow path based read barriers, the read barrier call is |
| 5055 | // inserted after the original load. However, in fast path based |
| 5056 | // Baker's read barriers, we need to perform the load of |
| 5057 | // mirror::Object::monitor_ *before* the original reference load. |
| 5058 | // This load-load ordering is required by the read barrier. |
| 5059 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5060 | // |
| 5061 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5062 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5063 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5064 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 5065 | // if (is_gray) { |
| 5066 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5067 | // } |
| 5068 | // |
| 5069 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5070 | // slightly more complex as it performs additional checks that we do |
| 5071 | // not do here for performance reasons. |
| 5072 | |
| 5073 | Primitive::Type type = Primitive::kPrimNot; |
| 5074 | Register ref_reg = RegisterFrom(ref, type); |
| 5075 | DCHECK(obj.IsW()); |
| 5076 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5077 | |
| 5078 | // /* int32_t */ monitor = obj->monitor_ |
| 5079 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5080 | if (needs_null_check) { |
| 5081 | MaybeRecordImplicitNullCheck(instruction); |
| 5082 | } |
| 5083 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5084 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5085 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5086 | |
Vladimir Marko | 836c654 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5087 | // Introduce a dependency on the lock_word including rb_state, |
| 5088 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5089 | // a memory barrier (which would be more expensive). |
Vladimir Marko | 836c654 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5090 | // obj is unchanged by this operation, but its value now depends on temp. |
| 5091 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5092 | |
| 5093 | // The actual reference load. |
| 5094 | if (index.IsValid()) { |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5095 | // Load types involving an "index". |
| 5096 | if (use_load_acquire) { |
| 5097 | // UnsafeGetObjectVolatile intrinsic case. |
| 5098 | // Register `index` is not an index in an object array, but an |
| 5099 | // offset to an object reference field within object `obj`. |
| 5100 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5101 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5102 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5103 | << instruction->AsInvoke()->GetIntrinsic(); |
| 5104 | DCHECK_EQ(offset, 0U); |
| 5105 | DCHECK_EQ(scale_factor, 0U); |
| 5106 | DCHECK_EQ(needs_null_check, 0U); |
| 5107 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5108 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5109 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5110 | } else { |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5111 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5112 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5113 | if (index.IsConstant()) { |
| 5114 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5115 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5116 | } else { |
Vladimir Marko | 836c654 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5117 | Register temp2 = temps.AcquireW(); |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5118 | __ Add(temp2, obj, offset); |
| 5119 | Load(type, ref_reg, HeapOperand(temp2, XRegisterFrom(index), LSL, scale_factor)); |
| 5120 | temps.Release(temp2); |
| 5121 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5122 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5123 | } else { |
| 5124 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5125 | MemOperand field = HeapOperand(obj, offset); |
| 5126 | if (use_load_acquire) { |
| 5127 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5128 | } else { |
| 5129 | Load(type, ref_reg, field); |
| 5130 | } |
| 5131 | } |
| 5132 | |
| 5133 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5134 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5135 | |
| 5136 | // Slow path used to mark the object `ref` when it is gray. |
| 5137 | SlowPathCodeARM64* slow_path = |
| 5138 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref, ref); |
| 5139 | AddSlowPath(slow_path); |
| 5140 | |
| 5141 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 5142 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 836c654 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5143 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 5144 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 5145 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 5146 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 5147 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5148 | __ Bind(slow_path->GetExitLabel()); |
| 5149 | } |
| 5150 | |
| 5151 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5152 | Location out, |
| 5153 | Location ref, |
| 5154 | Location obj, |
| 5155 | uint32_t offset, |
| 5156 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5157 | DCHECK(kEmitCompilerReadBarrier); |
| 5158 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5159 | // Insert a slow path based read barrier *after* the reference load. |
| 5160 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5161 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5162 | // reference will be carried out by the runtime within the slow |
| 5163 | // path. |
| 5164 | // |
| 5165 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5166 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5167 | // not used by the artReadBarrierSlow entry point. |
| 5168 | // |
| 5169 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5170 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5171 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5172 | AddSlowPath(slow_path); |
| 5173 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5174 | __ B(slow_path->GetEntryLabel()); |
| 5175 | __ Bind(slow_path->GetExitLabel()); |
| 5176 | } |
| 5177 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5178 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5179 | Location out, |
| 5180 | Location ref, |
| 5181 | Location obj, |
| 5182 | uint32_t offset, |
| 5183 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5184 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5185 | // Baker's read barriers shall be handled by the fast path |
| 5186 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5187 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5188 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5189 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5190 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5191 | } else if (kPoisonHeapReferences) { |
| 5192 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5193 | } |
| 5194 | } |
| 5195 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5196 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5197 | Location out, |
| 5198 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5199 | DCHECK(kEmitCompilerReadBarrier); |
| 5200 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5201 | // Insert a slow path based read barrier *after* the GC root load. |
| 5202 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5203 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5204 | // not need to do anything special for this here. |
| 5205 | SlowPathCodeARM64* slow_path = |
| 5206 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5207 | AddSlowPath(slow_path); |
| 5208 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5209 | __ B(slow_path->GetEntryLabel()); |
| 5210 | __ Bind(slow_path->GetExitLabel()); |
| 5211 | } |
| 5212 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5213 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5214 | LocationSummary* locations = |
| 5215 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5217 | locations->SetOut(Location::RequiresRegister()); |
| 5218 | } |
| 5219 | |
| 5220 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5221 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5222 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5223 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5224 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5225 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5226 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5227 | } else { |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5228 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 5229 | instruction->GetIndex() % ImTable::kSize, kArm64PointerSize)); |
Artem Udovichenko | df2d4f2 | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5230 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5231 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5232 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5233 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5234 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | |
| 5238 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5239 | #undef __ |
| 5240 | #undef QUICK_ENTRY_POINT |
| 5241 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5242 | } // namespace arm64 |
| 5243 | } // namespace art |