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