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