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