| 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 |  | 
|  | 45 | namespace arm64 { | 
|  | 46 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 47 | using helpers::CPURegisterFrom; | 
|  | 48 | using helpers::DRegisterFrom; | 
|  | 49 | using helpers::FPRegisterFrom; | 
|  | 50 | using helpers::HeapOperand; | 
|  | 51 | using helpers::HeapOperandFrom; | 
|  | 52 | using helpers::InputCPURegisterAt; | 
|  | 53 | using helpers::InputFPRegisterAt; | 
|  | 54 | using helpers::InputRegisterAt; | 
|  | 55 | using helpers::InputOperandAt; | 
|  | 56 | using helpers::Int64ConstantFrom; | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 57 | using helpers::LocationFrom; | 
|  | 58 | using helpers::OperandFromMemOperand; | 
|  | 59 | using helpers::OutputCPURegister; | 
|  | 60 | using helpers::OutputFPRegister; | 
|  | 61 | using helpers::OutputRegister; | 
|  | 62 | using helpers::RegisterFrom; | 
|  | 63 | using helpers::StackOperandFrom; | 
|  | 64 | using helpers::VIXLRegCodeFromART; | 
|  | 65 | using helpers::WRegisterFrom; | 
|  | 66 | using helpers::XRegisterFrom; | 
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 67 | using helpers::ARM64EncodableConstantOrRegister; | 
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 68 | using helpers::ArtVixlRegCodeCoherentForRegSet; | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 70 | static constexpr int kCurrentMethodStackOffset = 0; | 
|  | 71 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 72 | inline Condition ARM64Condition(IfCondition cond) { | 
|  | 73 | switch (cond) { | 
|  | 74 | case kCondEQ: return eq; | 
|  | 75 | case kCondNE: return ne; | 
|  | 76 | case kCondLT: return lt; | 
|  | 77 | case kCondLE: return le; | 
|  | 78 | case kCondGT: return gt; | 
|  | 79 | case kCondGE: return ge; | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 80 | } | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 81 | LOG(FATAL) << "Unreachable"; | 
|  | 82 | UNREACHABLE(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 85 | Location ARM64ReturnLocation(Primitive::Type return_type) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 86 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the | 
|  | 87 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, | 
|  | 88 | // but we use the exact registers for clarity. | 
|  | 89 | if (return_type == Primitive::kPrimFloat) { | 
|  | 90 | return LocationFrom(s0); | 
|  | 91 | } else if (return_type == Primitive::kPrimDouble) { | 
|  | 92 | return LocationFrom(d0); | 
|  | 93 | } else if (return_type == Primitive::kPrimLong) { | 
|  | 94 | return LocationFrom(x0); | 
| Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 95 | } else if (return_type == Primitive::kPrimVoid) { | 
|  | 96 | return Location::NoLocation(); | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 97 | } else { | 
|  | 98 | return LocationFrom(w0); | 
|  | 99 | } | 
|  | 100 | } | 
|  | 101 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 102 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 103 | return ARM64ReturnLocation(return_type); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 106 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> | 
|  | 107 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 108 |  | 
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 109 | // Calculate memory accessing operand for save/restore live registers. | 
|  | 110 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, | 
|  | 111 | RegisterSet* register_set, | 
|  | 112 | int64_t spill_offset, | 
|  | 113 | bool is_save) { | 
|  | 114 | DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(), | 
|  | 115 | codegen->GetNumberOfCoreRegisters(), | 
|  | 116 | register_set->GetFloatingPointRegisters(), | 
|  | 117 | codegen->GetNumberOfFloatingPointRegisters())); | 
|  | 118 |  | 
|  | 119 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, | 
|  | 120 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.list())); | 
| Nicolas Geoffray | 88a95ba | 2015-09-30 17:18:14 +0100 | [diff] [blame] | 121 | CPURegList fp_list = CPURegList( | 
|  | 122 | CPURegister::kFPRegister, | 
|  | 123 | kDRegSize, | 
|  | 124 | register_set->GetFloatingPointRegisters() | 
|  | 125 | & (~(codegen->GetGraph()->IsDebuggable() ? 0 : callee_saved_fp_registers.list()))); | 
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 126 |  | 
|  | 127 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); | 
|  | 128 | UseScratchRegisterScope temps(masm); | 
|  | 129 |  | 
|  | 130 | Register base = masm->StackPointer(); | 
|  | 131 | int64_t core_spill_size = core_list.TotalSizeInBytes(); | 
|  | 132 | int64_t fp_spill_size = fp_list.TotalSizeInBytes(); | 
|  | 133 | int64_t reg_size = kXRegSizeInBytes; | 
|  | 134 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; | 
|  | 135 | uint32_t ls_access_size = WhichPowerOf2(reg_size); | 
|  | 136 | if (((core_list.Count() > 1) || (fp_list.Count() > 1)) && | 
|  | 137 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { | 
|  | 138 | // If the offset does not fit in the instruction's immediate field, use an alternate register | 
|  | 139 | // to compute the base address(float point registers spill base address). | 
|  | 140 | Register new_base = temps.AcquireSameSizeAs(base); | 
|  | 141 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); | 
|  | 142 | base = new_base; | 
|  | 143 | spill_offset = -core_spill_size; | 
|  | 144 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; | 
|  | 145 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); | 
|  | 146 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | if (is_save) { | 
|  | 150 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); | 
|  | 151 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); | 
|  | 152 | } else { | 
|  | 153 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); | 
|  | 154 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); | 
|  | 155 | } | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { | 
|  | 159 | RegisterSet* register_set = locations->GetLiveRegisters(); | 
|  | 160 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); | 
|  | 161 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { | 
|  | 162 | if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) { | 
|  | 163 | // If the register holds an object, update the stack mask. | 
|  | 164 | if (locations->RegisterContainsObject(i)) { | 
|  | 165 | locations->SetStackBit(stack_offset / kVRegSize); | 
|  | 166 | } | 
|  | 167 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); | 
|  | 168 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); | 
|  | 169 | saved_core_stack_offsets_[i] = stack_offset; | 
|  | 170 | stack_offset += kXRegSizeInBytes; | 
|  | 171 | } | 
|  | 172 | } | 
|  | 173 |  | 
|  | 174 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { | 
|  | 175 | if (!codegen->IsFloatingPointCalleeSaveRegister(i) && | 
|  | 176 | register_set->ContainsFloatingPointRegister(i)) { | 
|  | 177 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); | 
|  | 178 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); | 
|  | 179 | saved_fpu_stack_offsets_[i] = stack_offset; | 
|  | 180 | stack_offset += kDRegSizeInBytes; | 
|  | 181 | } | 
|  | 182 | } | 
|  | 183 |  | 
|  | 184 | SaveRestoreLiveRegistersHelper(codegen, register_set, | 
|  | 185 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); | 
|  | 186 | } | 
|  | 187 |  | 
|  | 188 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { | 
|  | 189 | RegisterSet* register_set = locations->GetLiveRegisters(); | 
|  | 190 | SaveRestoreLiveRegistersHelper(codegen, register_set, | 
|  | 191 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); | 
|  | 192 | } | 
|  | 193 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 194 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 195 | public: | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 196 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : instruction_(instruction) {} | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 197 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 198 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 199 | LocationSummary* locations = instruction_->GetLocations(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 200 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 201 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 202 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 203 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 204 | // Live registers will be restored in the catch block if caught. | 
|  | 205 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 206 | } | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 207 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 208 | // move resolver. | 
|  | 209 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 210 | codegen->EmitParallelMoves( | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 211 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, | 
|  | 212 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 213 | arm64_codegen->InvokeRuntime( | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 214 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 215 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 218 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 219 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 220 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } | 
|  | 221 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 222 | private: | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 223 | HBoundsCheck* const instruction_; | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 224 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 225 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); | 
|  | 226 | }; | 
|  | 227 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 228 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 229 | public: | 
|  | 230 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {} | 
|  | 231 |  | 
|  | 232 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 233 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
|  | 234 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 235 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 236 | // Live registers will be restored in the catch block if caught. | 
|  | 237 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 238 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 239 | arm64_codegen->InvokeRuntime( | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 240 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 241 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 244 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 245 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 246 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } | 
|  | 247 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 248 | private: | 
|  | 249 | HDivZeroCheck* const instruction_; | 
|  | 250 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); | 
|  | 251 | }; | 
|  | 252 |  | 
|  | 253 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 254 | public: | 
|  | 255 | LoadClassSlowPathARM64(HLoadClass* cls, | 
|  | 256 | HInstruction* at, | 
|  | 257 | uint32_t dex_pc, | 
|  | 258 | bool do_clinit) | 
|  | 259 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { | 
|  | 260 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); | 
|  | 261 | } | 
|  | 262 |  | 
|  | 263 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 264 | LocationSummary* locations = at_->GetLocations(); | 
|  | 265 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
|  | 266 |  | 
|  | 267 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 268 | SaveLiveRegisters(codegen, locations); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 |  | 
|  | 270 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 271 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 272 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) | 
|  | 273 | : QUICK_ENTRY_POINT(pInitializeType); | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 274 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 275 | if (do_clinit_) { | 
| Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 276 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 277 | } else { | 
| Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 278 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 279 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 280 |  | 
|  | 281 | // Move the class to the desired location. | 
|  | 282 | Location out = locations->Out(); | 
|  | 283 | if (out.IsValid()) { | 
|  | 284 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); | 
|  | 285 | Primitive::Type type = at_->GetType(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 286 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | } | 
|  | 288 |  | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 289 | RestoreLiveRegisters(codegen, locations); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | __ B(GetExitLabel()); | 
|  | 291 | } | 
|  | 292 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 293 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } | 
|  | 294 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | private: | 
|  | 296 | // The class this slow path will load. | 
|  | 297 | HLoadClass* const cls_; | 
|  | 298 |  | 
|  | 299 | // The instruction where this slow path is happening. | 
|  | 300 | // (Might be the load class or an initialization check). | 
|  | 301 | HInstruction* const at_; | 
|  | 302 |  | 
|  | 303 | // The dex PC of `at_`. | 
|  | 304 | const uint32_t dex_pc_; | 
|  | 305 |  | 
|  | 306 | // Whether to initialize the class. | 
|  | 307 | const bool do_clinit_; | 
|  | 308 |  | 
|  | 309 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); | 
|  | 310 | }; | 
|  | 311 |  | 
|  | 312 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 313 | public: | 
|  | 314 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {} | 
|  | 315 |  | 
|  | 316 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 317 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 318 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 319 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
|  | 320 |  | 
|  | 321 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 322 | SaveLiveRegisters(codegen, locations); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 323 |  | 
|  | 324 | InvokeRuntimeCallingConvention calling_convention; | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 325 | __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | arm64_codegen->InvokeRuntime( | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 327 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); | 
| Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 328 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | Primitive::Type type = instruction_->GetType(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 330 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 331 |  | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 332 | RestoreLiveRegisters(codegen, locations); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | __ B(GetExitLabel()); | 
|  | 334 | } | 
|  | 335 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 336 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } | 
|  | 337 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 338 | private: | 
|  | 339 | HLoadString* const instruction_; | 
|  | 340 |  | 
|  | 341 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); | 
|  | 342 | }; | 
|  | 343 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 344 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 345 | public: | 
|  | 346 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {} | 
|  | 347 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 348 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 349 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 350 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 351 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 352 | // Live registers will be restored in the catch block if caught. | 
|  | 353 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 354 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | arm64_codegen->InvokeRuntime( | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 356 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 358 | } | 
|  | 359 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return true; } | 
|  | 361 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } | 
|  | 363 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 364 | private: | 
|  | 365 | HNullCheck* const instruction_; | 
|  | 366 |  | 
|  | 367 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); | 
|  | 368 | }; | 
|  | 369 |  | 
|  | 370 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 371 | public: | 
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 372 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 373 | : instruction_(instruction), successor_(successor) {} | 
|  | 374 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 375 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 376 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 377 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 378 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 379 | arm64_codegen->InvokeRuntime( | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 380 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 381 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 382 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 383 | if (successor_ == nullptr) { | 
|  | 384 | __ B(GetReturnLabel()); | 
|  | 385 | } else { | 
|  | 386 | __ B(arm64_codegen->GetLabelOf(successor_)); | 
|  | 387 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 388 | } | 
|  | 389 |  | 
|  | 390 | vixl::Label* GetReturnLabel() { | 
|  | 391 | DCHECK(successor_ == nullptr); | 
|  | 392 | return &return_label_; | 
|  | 393 | } | 
|  | 394 |  | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 395 | HBasicBlock* GetSuccessor() const { | 
|  | 396 | return successor_; | 
|  | 397 | } | 
|  | 398 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 399 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } | 
|  | 400 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 401 | private: | 
|  | 402 | HSuspendCheck* const instruction_; | 
|  | 403 | // If not null, the block to branch to after the suspend check. | 
|  | 404 | HBasicBlock* const successor_; | 
|  | 405 |  | 
|  | 406 | // If `successor_` is null, the label to branch to after the suspend check. | 
|  | 407 | vixl::Label return_label_; | 
|  | 408 |  | 
|  | 409 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); | 
|  | 410 | }; | 
|  | 411 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 412 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 413 | public: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 414 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) | 
|  | 415 | : instruction_(instruction), is_fatal_(is_fatal) {} | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 416 |  | 
|  | 417 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 418 | LocationSummary* locations = instruction_->GetLocations(); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 419 | Location class_to_check = locations->InAt(1); | 
|  | 420 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) | 
|  | 421 | : locations->Out(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 422 | DCHECK(instruction_->IsCheckCast() | 
|  | 423 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 424 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 425 | uint32_t dex_pc = instruction_->GetDexPc(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 426 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 427 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 428 |  | 
|  | 429 | if (instruction_->IsCheckCast()) { | 
|  | 430 | // The codegen for the instruction overwrites `temp`, so put it back in place. | 
|  | 431 | Register obj = InputRegisterAt(instruction_, 0); | 
|  | 432 | Register temp = WRegisterFrom(locations->GetTemp(0)); | 
|  | 433 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 434 | __ Ldr(temp, HeapOperand(obj, class_offset)); | 
|  | 435 | arm64_codegen->GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
|  | 436 | } | 
|  | 437 |  | 
|  | 438 | if (!is_fatal_) { | 
|  | 439 | SaveLiveRegisters(codegen, locations); | 
|  | 440 | } | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 441 |  | 
|  | 442 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 443 | // move resolver. | 
|  | 444 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 445 | codegen->EmitParallelMoves( | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 446 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, | 
|  | 447 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 448 |  | 
|  | 449 | if (instruction_->IsInstanceOf()) { | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 450 | arm64_codegen->InvokeRuntime( | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 451 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 452 | Primitive::Type ret_type = instruction_->GetType(); | 
|  | 453 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); | 
|  | 454 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 455 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t, | 
|  | 456 | const mirror::Class*, const mirror::Class*>(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 457 | } else { | 
|  | 458 | DCHECK(instruction_->IsCheckCast()); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 459 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 460 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 461 | } | 
|  | 462 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 463 | if (!is_fatal_) { | 
|  | 464 | RestoreLiveRegisters(codegen, locations); | 
|  | 465 | __ B(GetExitLabel()); | 
|  | 466 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 467 | } | 
|  | 468 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 469 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 470 | bool IsFatal() const { return is_fatal_; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 471 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 472 | private: | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 473 | HInstruction* const instruction_; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 474 | const bool is_fatal_; | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 476 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); | 
|  | 477 | }; | 
|  | 478 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 479 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { | 
|  | 480 | public: | 
|  | 481 | explicit DeoptimizationSlowPathARM64(HInstruction* instruction) | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 482 | : instruction_(instruction) {} | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 483 |  | 
|  | 484 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
|  | 485 | __ Bind(GetEntryLabel()); | 
|  | 486 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 487 | DCHECK(instruction_->IsDeoptimize()); | 
|  | 488 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); | 
|  | 489 | uint32_t dex_pc = deoptimize->GetDexPc(); | 
|  | 490 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); | 
|  | 491 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); | 
|  | 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 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 547 | #undef __ | 
|  | 548 |  | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 549 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 550 | Location next_location; | 
|  | 551 | if (type == Primitive::kPrimVoid) { | 
|  | 552 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 553 | } | 
|  | 554 |  | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 555 | if (Primitive::IsFloatingPointType(type) && | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 556 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { | 
|  | 557 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 558 | } else if (!Primitive::IsFloatingPointType(type) && | 
|  | 559 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 560 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); | 
|  | 561 | } else { | 
|  | 562 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 563 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) | 
|  | 564 | : Location::StackSlot(stack_offset); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 565 | } | 
|  | 566 |  | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 567 | // Space on the stack is reserved for all arguments. | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 568 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 569 | return next_location; | 
|  | 570 | } | 
|  | 571 |  | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 572 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { | 
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 573 | return LocationFrom(kArtMethodRegister); | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 574 | } | 
|  | 575 |  | 
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 576 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, | 
|  | 577 | const Arm64InstructionSetFeatures& isa_features, | 
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 578 | const CompilerOptions& compiler_options, | 
|  | 579 | OptimizingCompilerStats* stats) | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 580 | : CodeGenerator(graph, | 
|  | 581 | kNumberOfAllocatableRegisters, | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 582 | kNumberOfAllocatableFPRegisters, | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 583 | kNumberOfAllocatableRegisterPairs, | 
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 584 | callee_saved_core_registers.list(), | 
| Nicolas Geoffray | 88a95ba | 2015-09-30 17:18:14 +0100 | [diff] [blame] | 585 | // If the graph is debuggable, we need to save the fpu registers ourselves, | 
|  | 586 | // as the stubs do not do it. | 
|  | 587 | graph->IsDebuggable() ? 0 : callee_saved_fp_registers.list(), | 
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 588 | compiler_options, | 
|  | 589 | stats), | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 590 | block_labels_(nullptr), | 
|  | 591 | location_builder_(graph, this), | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 592 | instruction_visitor_(graph, this), | 
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 593 | move_resolver_(graph->GetArena(), this), | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 594 | isa_features_(isa_features), | 
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 595 | uint64_literals_(std::less<uint64_t>(), | 
|  | 596 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 597 | method_patches_(MethodReferenceComparator(), | 
|  | 598 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 599 | call_patches_(MethodReferenceComparator(), | 
|  | 600 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 601 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 602 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 603 | // Save the link register (containing the return address) to mimic Quick. | 
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 604 | AddAllocatedRegister(LocationFrom(lr)); | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 605 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 606 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 607 | #undef __ | 
|  | 608 | #define __ GetVIXLAssembler()-> | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 609 |  | 
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 610 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { | 
|  | 611 | // Ensure we emit the literal pool. | 
|  | 612 | __ FinalizeCode(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 613 |  | 
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 614 | CodeGenerator::Finalize(allocator); | 
|  | 615 | } | 
|  | 616 |  | 
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 617 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { | 
|  | 618 | // Note: There are 6 kinds of moves: | 
|  | 619 | // 1. constant -> GPR/FPR (non-cycle) | 
|  | 620 | // 2. constant -> stack (non-cycle) | 
|  | 621 | // 3. GPR/FPR -> GPR/FPR | 
|  | 622 | // 4. GPR/FPR -> stack | 
|  | 623 | // 5. stack -> GPR/FPR | 
|  | 624 | // 6. stack -> stack (non-cycle) | 
|  | 625 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 | 
|  | 626 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting | 
|  | 627 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the | 
|  | 628 | // dependency. | 
|  | 629 | vixl_temps_.Open(GetVIXLAssembler()); | 
|  | 630 | } | 
|  | 631 |  | 
|  | 632 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { | 
|  | 633 | vixl_temps_.Close(); | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { | 
|  | 637 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || | 
|  | 638 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); | 
|  | 639 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; | 
|  | 640 | Location scratch = GetScratchLocation(kind); | 
|  | 641 | if (!scratch.Equals(Location::NoLocation())) { | 
|  | 642 | return scratch; | 
|  | 643 | } | 
|  | 644 | // Allocate from VIXL temp registers. | 
|  | 645 | if (kind == Location::kRegister) { | 
|  | 646 | scratch = LocationFrom(vixl_temps_.AcquireX()); | 
|  | 647 | } else { | 
|  | 648 | DCHECK(kind == Location::kFpuRegister); | 
|  | 649 | scratch = LocationFrom(vixl_temps_.AcquireD()); | 
|  | 650 | } | 
|  | 651 | AddScratchLocation(scratch); | 
|  | 652 | return scratch; | 
|  | 653 | } | 
|  | 654 |  | 
|  | 655 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { | 
|  | 656 | if (loc.IsRegister()) { | 
|  | 657 | vixl_temps_.Release(XRegisterFrom(loc)); | 
|  | 658 | } else { | 
|  | 659 | DCHECK(loc.IsFpuRegister()); | 
|  | 660 | vixl_temps_.Release(DRegisterFrom(loc)); | 
|  | 661 | } | 
|  | 662 | RemoveScratchLocation(loc); | 
|  | 663 | } | 
|  | 664 |  | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 665 | void ParallelMoveResolverARM64::EmitMove(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 666 | DCHECK_LT(index, moves_.size()); | 
|  | 667 | MoveOperands* move = moves_[index]; | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 668 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 669 | } | 
|  | 670 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 671 | void CodeGeneratorARM64::GenerateFrameEntry() { | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 672 | MacroAssembler* masm = GetVIXLAssembler(); | 
|  | 673 | BlockPoolsScope block_pools(masm); | 
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 674 | __ Bind(&frame_entry_label_); | 
|  | 675 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 676 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); | 
|  | 677 | if (do_overflow_check) { | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 678 | UseScratchRegisterScope temps(masm); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 679 | Register temp = temps.AcquireX(); | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 680 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); | 
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 681 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 682 | __ Ldr(wzr, MemOperand(temp, 0)); | 
|  | 683 | RecordPcInfo(nullptr, 0); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 684 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 685 |  | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 686 | if (!HasEmptyFrame()) { | 
|  | 687 | int frame_size = GetFrameSize(); | 
|  | 688 | // Stack layout: | 
|  | 689 | //      sp[frame_size - 8]        : lr. | 
|  | 690 | //      ...                       : other preserved core registers. | 
|  | 691 | //      ...                       : other preserved fp registers. | 
|  | 692 | //      ...                       : reserved frame space. | 
|  | 693 | //      sp[0]                     : current method. | 
|  | 694 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 695 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); | 
| Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 696 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), | 
|  | 697 | frame_size - GetCoreSpillSize()); | 
|  | 698 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), | 
|  | 699 | frame_size - FrameEntrySpillSize()); | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 700 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 701 | } | 
|  | 702 |  | 
|  | 703 | void CodeGeneratorARM64::GenerateFrameExit() { | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 704 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 705 | GetAssembler()->cfi().RememberState(); | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 706 | if (!HasEmptyFrame()) { | 
|  | 707 | int frame_size = GetFrameSize(); | 
| Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 708 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), | 
|  | 709 | frame_size - FrameEntrySpillSize()); | 
|  | 710 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), | 
|  | 711 | frame_size - GetCoreSpillSize()); | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 712 | __ Drop(frame_size); | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 713 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 714 | } | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 715 | __ Ret(); | 
|  | 716 | GetAssembler()->cfi().RestoreState(); | 
|  | 717 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 718 | } | 
|  | 719 |  | 
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 720 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { | 
|  | 721 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); | 
|  | 722 | return vixl::CPURegList(vixl::CPURegister::kRegister, vixl::kXRegSize, | 
|  | 723 | core_spill_mask_); | 
|  | 724 | } | 
|  | 725 |  | 
|  | 726 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { | 
|  | 727 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, | 
|  | 728 | GetNumberOfFloatingPointRegisters())); | 
|  | 729 | return vixl::CPURegList(vixl::CPURegister::kFPRegister, vixl::kDRegSize, | 
|  | 730 | fpu_spill_mask_); | 
|  | 731 | } | 
|  | 732 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 733 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { | 
|  | 734 | __ Bind(GetLabelOf(block)); | 
|  | 735 | } | 
|  | 736 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 737 | void CodeGeneratorARM64::Move(HInstruction* instruction, | 
|  | 738 | Location location, | 
|  | 739 | HInstruction* move_for) { | 
|  | 740 | LocationSummary* locations = instruction->GetLocations(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 741 | Primitive::Type type = instruction->GetType(); | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 742 | DCHECK_NE(type, Primitive::kPrimVoid); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 743 |  | 
| Nicolas Geoffray | 9b1eba3 | 2015-07-13 15:55:26 +0100 | [diff] [blame] | 744 | if (instruction->IsFakeString()) { | 
|  | 745 | // The fake string is an alias for null. | 
|  | 746 | DCHECK(IsBaseline()); | 
|  | 747 | instruction = locations->Out().GetConstant(); | 
|  | 748 | DCHECK(instruction->IsNullConstant()) << instruction->DebugName(); | 
|  | 749 | } | 
|  | 750 |  | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 751 | if (instruction->IsCurrentMethod()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 752 | MoveLocation(location, | 
|  | 753 | Location::DoubleStackSlot(kCurrentMethodStackOffset), | 
|  | 754 | Primitive::kPrimVoid); | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 755 | } else if (locations != nullptr && locations->Out().Equals(location)) { | 
|  | 756 | return; | 
|  | 757 | } else if (instruction->IsIntConstant() | 
|  | 758 | || instruction->IsLongConstant() | 
|  | 759 | || instruction->IsNullConstant()) { | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 760 | int64_t value = GetInt64ValueOf(instruction->AsConstant()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 761 | if (location.IsRegister()) { | 
|  | 762 | Register dst = RegisterFrom(location, type); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 763 | DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) || | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 764 | (instruction->IsLongConstant() && dst.Is64Bits())); | 
|  | 765 | __ Mov(dst, value); | 
|  | 766 | } else { | 
|  | 767 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 768 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 769 | Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant()) | 
|  | 770 | ? temps.AcquireW() | 
|  | 771 | : temps.AcquireX(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 772 | __ Mov(temp, value); | 
|  | 773 | __ Str(temp, StackOperandFrom(location)); | 
|  | 774 | } | 
| Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 775 | } else if (instruction->IsTemporary()) { | 
|  | 776 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 777 | MoveLocation(location, temp_location, type); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 778 | } else if (instruction->IsLoadLocal()) { | 
|  | 779 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 780 | if (Primitive::Is64BitType(type)) { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 781 | MoveLocation(location, Location::DoubleStackSlot(stack_slot), type); | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 782 | } else { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 783 | MoveLocation(location, Location::StackSlot(stack_slot), type); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 784 | } | 
|  | 785 |  | 
|  | 786 | } else { | 
|  | 787 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 788 | MoveLocation(location, locations->Out(), type); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 789 | } | 
|  | 790 | } | 
|  | 791 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 792 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { | 
|  | 793 | DCHECK(location.IsRegister()); | 
|  | 794 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); | 
|  | 795 | } | 
|  | 796 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 797 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { | 
|  | 798 | if (location.IsRegister()) { | 
|  | 799 | locations->AddTemp(location); | 
|  | 800 | } else { | 
|  | 801 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; | 
|  | 802 | } | 
|  | 803 | } | 
|  | 804 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 805 | Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const { | 
|  | 806 | Primitive::Type type = load->GetType(); | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 807 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 808 | switch (type) { | 
|  | 809 | case Primitive::kPrimNot: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 810 | case Primitive::kPrimInt: | 
|  | 811 | case Primitive::kPrimFloat: | 
|  | 812 | return Location::StackSlot(GetStackSlot(load->GetLocal())); | 
|  | 813 |  | 
|  | 814 | case Primitive::kPrimLong: | 
|  | 815 | case Primitive::kPrimDouble: | 
|  | 816 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); | 
|  | 817 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 818 | case Primitive::kPrimBoolean: | 
|  | 819 | case Primitive::kPrimByte: | 
|  | 820 | case Primitive::kPrimChar: | 
|  | 821 | case Primitive::kPrimShort: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 822 | case Primitive::kPrimVoid: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 823 | LOG(FATAL) << "Unexpected type " << type; | 
|  | 824 | } | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 825 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 826 | LOG(FATAL) << "Unreachable"; | 
|  | 827 | return Location::NoLocation(); | 
|  | 828 | } | 
|  | 829 |  | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 830 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 831 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 832 | Register card = temps.AcquireX(); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 833 | Register temp = temps.AcquireW();   // Index within the CardTable - 32bit. | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 834 | vixl::Label done; | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 835 | if (value_can_be_null) { | 
|  | 836 | __ Cbz(value, &done); | 
|  | 837 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 838 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); | 
|  | 839 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 840 | __ Strb(card, MemOperand(card, temp.X())); | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 841 | if (value_can_be_null) { | 
|  | 842 | __ Bind(&done); | 
|  | 843 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 844 | } | 
|  | 845 |  | 
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 846 | void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const { | 
|  | 847 | // Blocked core registers: | 
|  | 848 | //      lr        : Runtime reserved. | 
|  | 849 | //      tr        : Runtime reserved. | 
|  | 850 | //      xSuspend  : Runtime reserved. TODO: Unblock this when the runtime stops using it. | 
|  | 851 | //      ip1       : VIXL core temp. | 
|  | 852 | //      ip0       : VIXL core temp. | 
|  | 853 | // | 
|  | 854 | // Blocked fp registers: | 
|  | 855 | //      d31       : VIXL fp temp. | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 856 | CPURegList reserved_core_registers = vixl_reserved_core_registers; | 
|  | 857 | reserved_core_registers.Combine(runtime_reserved_core_registers); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 858 | while (!reserved_core_registers.IsEmpty()) { | 
|  | 859 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; | 
|  | 860 | } | 
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 861 |  | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 862 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; | 
| Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 863 | while (!reserved_fp_registers.IsEmpty()) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 864 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; | 
|  | 865 | } | 
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 866 |  | 
|  | 867 | if (is_baseline) { | 
|  | 868 | CPURegList reserved_core_baseline_registers = callee_saved_core_registers; | 
|  | 869 | while (!reserved_core_baseline_registers.IsEmpty()) { | 
|  | 870 | blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true; | 
|  | 871 | } | 
|  | 872 |  | 
|  | 873 | CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers; | 
|  | 874 | while (!reserved_fp_baseline_registers.IsEmpty()) { | 
|  | 875 | blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true; | 
|  | 876 | } | 
|  | 877 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 878 | } | 
|  | 879 |  | 
|  | 880 | Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const { | 
|  | 881 | if (type == Primitive::kPrimVoid) { | 
|  | 882 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 883 | } | 
|  | 884 |  | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 885 | if (Primitive::IsFloatingPointType(type)) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 886 | ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters); | 
|  | 887 | DCHECK_NE(reg, -1); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 888 | return Location::FpuRegisterLocation(reg); | 
|  | 889 | } else { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 890 | ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters); | 
|  | 891 | DCHECK_NE(reg, -1); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 892 | return Location::RegisterLocation(reg); | 
|  | 893 | } | 
|  | 894 | } | 
|  | 895 |  | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 896 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 897 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); | 
|  | 898 | __ Str(reg, MemOperand(sp, stack_index)); | 
|  | 899 | return kArm64WordSize; | 
|  | 900 | } | 
|  | 901 |  | 
|  | 902 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 903 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); | 
|  | 904 | __ Ldr(reg, MemOperand(sp, stack_index)); | 
|  | 905 | return kArm64WordSize; | 
|  | 906 | } | 
|  | 907 |  | 
|  | 908 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 909 | FPRegister reg = FPRegister(reg_id, kDRegSize); | 
|  | 910 | __ Str(reg, MemOperand(sp, stack_index)); | 
|  | 911 | return kArm64WordSize; | 
|  | 912 | } | 
|  | 913 |  | 
|  | 914 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 915 | FPRegister reg = FPRegister(reg_id, kDRegSize); | 
|  | 916 | __ Ldr(reg, MemOperand(sp, stack_index)); | 
|  | 917 | return kArm64WordSize; | 
|  | 918 | } | 
|  | 919 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 920 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 921 | stream << XRegister(reg); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 922 | } | 
|  | 923 |  | 
|  | 924 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 925 | stream << DRegister(reg); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 926 | } | 
|  | 927 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 928 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 929 | if (constant->IsIntConstant()) { | 
|  | 930 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); | 
|  | 931 | } else if (constant->IsLongConstant()) { | 
|  | 932 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); | 
|  | 933 | } else if (constant->IsNullConstant()) { | 
|  | 934 | __ Mov(Register(destination), 0); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 935 | } else if (constant->IsFloatConstant()) { | 
|  | 936 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); | 
|  | 937 | } else { | 
|  | 938 | DCHECK(constant->IsDoubleConstant()); | 
|  | 939 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); | 
|  | 940 | } | 
|  | 941 | } | 
|  | 942 |  | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 943 |  | 
|  | 944 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { | 
|  | 945 | DCHECK(constant.IsConstant()); | 
|  | 946 | HConstant* cst = constant.GetConstant(); | 
|  | 947 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 948 | // Null is mapped to a core W register, which we associate with kPrimInt. | 
|  | 949 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 950 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || | 
|  | 951 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || | 
|  | 952 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); | 
|  | 953 | } | 
|  | 954 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 955 | void CodeGeneratorARM64::MoveLocation(Location destination, | 
|  | 956 | Location source, | 
|  | 957 | Primitive::Type dst_type) { | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 958 | if (source.Equals(destination)) { | 
|  | 959 | return; | 
|  | 960 | } | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 961 |  | 
|  | 962 | // A valid move can always be inferred from the destination and source | 
|  | 963 | // locations. When moving from and to a register, the argument type can be | 
|  | 964 | // used to generate 32bit instead of 64bit moves. In debug mode we also | 
|  | 965 | // checks the coherency of the locations and the type. | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 966 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 967 |  | 
|  | 968 | if (destination.IsRegister() || destination.IsFpuRegister()) { | 
|  | 969 | if (unspecified_type) { | 
|  | 970 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; | 
|  | 971 | if (source.IsStackSlot() || | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 972 | (src_cst != nullptr && (src_cst->IsIntConstant() | 
|  | 973 | || src_cst->IsFloatConstant() | 
|  | 974 | || src_cst->IsNullConstant()))) { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 975 | // For stack slots and 32bit constants, a 64bit type is appropriate. | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 976 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 977 | } else { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 978 | // If the source is a double stack slot or a 64bit constant, a 64bit | 
|  | 979 | // type is appropriate. Else the source is a register, and since the | 
|  | 980 | // type has not been specified, we chose a 64bit type to force a 64bit | 
|  | 981 | // move. | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 982 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 983 | } | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 984 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 985 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || | 
|  | 986 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); | 
|  | 987 | CPURegister dst = CPURegisterFrom(destination, dst_type); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 988 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { | 
|  | 989 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); | 
|  | 990 | __ Ldr(dst, StackOperandFrom(source)); | 
|  | 991 | } else if (source.IsConstant()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 992 | DCHECK(CoherentConstantAndType(source, dst_type)); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 993 | MoveConstant(dst, source.GetConstant()); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 994 | } else if (source.IsRegister()) { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 995 | if (destination.IsRegister()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 996 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 997 | } else { | 
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 998 | DCHECK(destination.IsFpuRegister()); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 999 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) | 
|  | 1000 | ? Primitive::kPrimLong | 
|  | 1001 | : Primitive::kPrimInt; | 
|  | 1002 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); | 
|  | 1003 | } | 
|  | 1004 | } else { | 
|  | 1005 | DCHECK(source.IsFpuRegister()); | 
|  | 1006 | if (destination.IsRegister()) { | 
|  | 1007 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) | 
|  | 1008 | ? Primitive::kPrimDouble | 
|  | 1009 | : Primitive::kPrimFloat; | 
|  | 1010 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); | 
|  | 1011 | } else { | 
|  | 1012 | DCHECK(destination.IsFpuRegister()); | 
|  | 1013 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1014 | } | 
|  | 1015 | } | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1016 | } else {  // The destination is not a register. It must be a stack slot. | 
|  | 1017 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); | 
|  | 1018 | if (source.IsRegister() || source.IsFpuRegister()) { | 
|  | 1019 | if (unspecified_type) { | 
|  | 1020 | if (source.IsRegister()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 1021 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1022 | } else { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 1023 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1024 | } | 
|  | 1025 | } | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 1026 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && | 
|  | 1027 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); | 
|  | 1028 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1029 | } else if (source.IsConstant()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 1030 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) | 
|  | 1031 | << source << " " << dst_type; | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1032 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 1033 | HConstant* src_cst = source.GetConstant(); | 
|  | 1034 | CPURegister temp; | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1035 | if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1036 | temp = temps.AcquireW(); | 
|  | 1037 | } else if (src_cst->IsLongConstant()) { | 
|  | 1038 | temp = temps.AcquireX(); | 
|  | 1039 | } else if (src_cst->IsFloatConstant()) { | 
|  | 1040 | temp = temps.AcquireS(); | 
|  | 1041 | } else { | 
|  | 1042 | DCHECK(src_cst->IsDoubleConstant()); | 
|  | 1043 | temp = temps.AcquireD(); | 
|  | 1044 | } | 
|  | 1045 | MoveConstant(temp, src_cst); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1046 | __ Str(temp, StackOperandFrom(destination)); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1047 | } else { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1048 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1049 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1050 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1051 | // There is generally less pressure on FP registers. | 
|  | 1052 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1053 | __ Ldr(temp, StackOperandFrom(source)); | 
|  | 1054 | __ Str(temp, StackOperandFrom(destination)); | 
|  | 1055 | } | 
|  | 1056 | } | 
|  | 1057 | } | 
|  | 1058 |  | 
|  | 1059 | void CodeGeneratorARM64::Load(Primitive::Type type, | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1060 | CPURegister dst, | 
|  | 1061 | const MemOperand& src) { | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1062 | switch (type) { | 
|  | 1063 | case Primitive::kPrimBoolean: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1064 | __ Ldrb(Register(dst), src); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1065 | break; | 
|  | 1066 | case Primitive::kPrimByte: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1067 | __ Ldrsb(Register(dst), src); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1068 | break; | 
|  | 1069 | case Primitive::kPrimShort: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1070 | __ Ldrsh(Register(dst), src); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1071 | break; | 
|  | 1072 | case Primitive::kPrimChar: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1073 | __ Ldrh(Register(dst), src); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1074 | break; | 
|  | 1075 | case Primitive::kPrimInt: | 
|  | 1076 | case Primitive::kPrimNot: | 
|  | 1077 | case Primitive::kPrimLong: | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1078 | case Primitive::kPrimFloat: | 
|  | 1079 | case Primitive::kPrimDouble: | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1080 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1081 | __ Ldr(dst, src); | 
|  | 1082 | break; | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1083 | case Primitive::kPrimVoid: | 
|  | 1084 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 1085 | } | 
|  | 1086 | } | 
|  | 1087 |  | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1088 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1089 | CPURegister dst, | 
|  | 1090 | const MemOperand& src) { | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1091 | MacroAssembler* masm = GetVIXLAssembler(); | 
|  | 1092 | BlockPoolsScope block_pools(masm); | 
|  | 1093 | UseScratchRegisterScope temps(masm); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1094 | Register temp_base = temps.AcquireX(); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1095 | Primitive::Type type = instruction->GetType(); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1096 |  | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1097 | DCHECK(!src.IsPreIndex()); | 
|  | 1098 | DCHECK(!src.IsPostIndex()); | 
|  | 1099 |  | 
|  | 1100 | // TODO(vixl): Let the MacroAssembler handle MemOperand. | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1101 | __ Add(temp_base, src.base(), OperandFromMemOperand(src)); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1102 | MemOperand base = MemOperand(temp_base); | 
|  | 1103 | switch (type) { | 
|  | 1104 | case Primitive::kPrimBoolean: | 
|  | 1105 | __ Ldarb(Register(dst), base); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1106 | MaybeRecordImplicitNullCheck(instruction); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1107 | break; | 
|  | 1108 | case Primitive::kPrimByte: | 
|  | 1109 | __ Ldarb(Register(dst), base); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1110 | MaybeRecordImplicitNullCheck(instruction); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1111 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); | 
|  | 1112 | break; | 
|  | 1113 | case Primitive::kPrimChar: | 
|  | 1114 | __ Ldarh(Register(dst), base); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1115 | MaybeRecordImplicitNullCheck(instruction); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1116 | break; | 
|  | 1117 | case Primitive::kPrimShort: | 
|  | 1118 | __ Ldarh(Register(dst), base); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1119 | MaybeRecordImplicitNullCheck(instruction); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1120 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); | 
|  | 1121 | break; | 
|  | 1122 | case Primitive::kPrimInt: | 
|  | 1123 | case Primitive::kPrimNot: | 
|  | 1124 | case Primitive::kPrimLong: | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1125 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1126 | __ Ldar(Register(dst), base); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1127 | MaybeRecordImplicitNullCheck(instruction); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1128 | break; | 
|  | 1129 | case Primitive::kPrimFloat: | 
|  | 1130 | case Primitive::kPrimDouble: { | 
|  | 1131 | DCHECK(dst.IsFPRegister()); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1132 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1133 |  | 
|  | 1134 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); | 
|  | 1135 | __ Ldar(temp, base); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1136 | MaybeRecordImplicitNullCheck(instruction); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1137 | __ Fmov(FPRegister(dst), temp); | 
|  | 1138 | break; | 
|  | 1139 | } | 
|  | 1140 | case Primitive::kPrimVoid: | 
|  | 1141 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 1142 | } | 
|  | 1143 | } | 
|  | 1144 |  | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1145 | void CodeGeneratorARM64::Store(Primitive::Type type, | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1146 | CPURegister src, | 
|  | 1147 | const MemOperand& dst) { | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1148 | switch (type) { | 
|  | 1149 | case Primitive::kPrimBoolean: | 
|  | 1150 | case Primitive::kPrimByte: | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1151 | __ Strb(Register(src), dst); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1152 | break; | 
|  | 1153 | case Primitive::kPrimChar: | 
|  | 1154 | case Primitive::kPrimShort: | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1155 | __ Strh(Register(src), dst); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1156 | break; | 
|  | 1157 | case Primitive::kPrimInt: | 
|  | 1158 | case Primitive::kPrimNot: | 
|  | 1159 | case Primitive::kPrimLong: | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1160 | case Primitive::kPrimFloat: | 
|  | 1161 | case Primitive::kPrimDouble: | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1162 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1163 | __ Str(src, dst); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1164 | break; | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1165 | case Primitive::kPrimVoid: | 
|  | 1166 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 1167 | } | 
|  | 1168 | } | 
|  | 1169 |  | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1170 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, | 
|  | 1171 | CPURegister src, | 
|  | 1172 | const MemOperand& dst) { | 
|  | 1173 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 1174 | Register temp_base = temps.AcquireX(); | 
|  | 1175 |  | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1176 | DCHECK(!dst.IsPreIndex()); | 
|  | 1177 | DCHECK(!dst.IsPostIndex()); | 
|  | 1178 |  | 
|  | 1179 | // TODO(vixl): Let the MacroAssembler handle this. | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1180 | Operand op = OperandFromMemOperand(dst); | 
|  | 1181 | __ Add(temp_base, dst.base(), op); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1182 | MemOperand base = MemOperand(temp_base); | 
|  | 1183 | switch (type) { | 
|  | 1184 | case Primitive::kPrimBoolean: | 
|  | 1185 | case Primitive::kPrimByte: | 
|  | 1186 | __ Stlrb(Register(src), base); | 
|  | 1187 | break; | 
|  | 1188 | case Primitive::kPrimChar: | 
|  | 1189 | case Primitive::kPrimShort: | 
|  | 1190 | __ Stlrh(Register(src), base); | 
|  | 1191 | break; | 
|  | 1192 | case Primitive::kPrimInt: | 
|  | 1193 | case Primitive::kPrimNot: | 
|  | 1194 | case Primitive::kPrimLong: | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1195 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1196 | __ Stlr(Register(src), base); | 
|  | 1197 | break; | 
|  | 1198 | case Primitive::kPrimFloat: | 
|  | 1199 | case Primitive::kPrimDouble: { | 
|  | 1200 | DCHECK(src.IsFPRegister()); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1201 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1202 |  | 
|  | 1203 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); | 
|  | 1204 | __ Fmov(temp, FPRegister(src)); | 
|  | 1205 | __ Stlr(temp, base); | 
|  | 1206 | break; | 
|  | 1207 | } | 
|  | 1208 | case Primitive::kPrimVoid: | 
|  | 1209 | LOG(FATAL) << "Unreachable type " << type; | 
|  | 1210 | } | 
|  | 1211 | } | 
|  | 1212 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1213 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, | 
|  | 1214 | HInstruction* instruction, | 
|  | 1215 | uint32_t dex_pc, | 
|  | 1216 | SlowPathCode* slow_path) { | 
|  | 1217 | InvokeRuntime(GetThreadOffset<kArm64WordSize>(entrypoint).Int32Value(), | 
|  | 1218 | instruction, | 
|  | 1219 | dex_pc, | 
|  | 1220 | slow_path); | 
|  | 1221 | } | 
|  | 1222 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1223 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, | 
|  | 1224 | HInstruction* instruction, | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1225 | uint32_t dex_pc, | 
|  | 1226 | SlowPathCode* slow_path) { | 
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1227 | ValidateInvokeRuntime(instruction, slow_path); | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1228 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1229 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); | 
|  | 1230 | __ Blr(lr); | 
| Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1231 | RecordPcInfo(instruction, dex_pc, slow_path); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1232 | } | 
|  | 1233 |  | 
|  | 1234 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, | 
|  | 1235 | vixl::Register class_reg) { | 
|  | 1236 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 1237 | Register temp = temps.AcquireW(); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1238 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); | 
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1239 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1240 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1241 | // 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] | 1242 | if (use_acquire_release) { | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1243 | // TODO(vixl): Let the MacroAssembler handle MemOperand. | 
|  | 1244 | __ Add(temp, class_reg, status_offset); | 
|  | 1245 | __ Ldar(temp, HeapOperand(temp)); | 
|  | 1246 | __ Cmp(temp, mirror::Class::kStatusInitialized); | 
|  | 1247 | __ B(lt, slow_path->GetEntryLabel()); | 
|  | 1248 | } else { | 
|  | 1249 | __ Ldr(temp, HeapOperand(class_reg, status_offset)); | 
|  | 1250 | __ Cmp(temp, mirror::Class::kStatusInitialized); | 
|  | 1251 | __ B(lt, slow_path->GetEntryLabel()); | 
|  | 1252 | __ Dmb(InnerShareable, BarrierReads); | 
|  | 1253 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1254 | __ Bind(slow_path->GetExitLabel()); | 
|  | 1255 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1256 |  | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1257 | void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { | 
|  | 1258 | BarrierType type = BarrierAll; | 
|  | 1259 |  | 
|  | 1260 | switch (kind) { | 
|  | 1261 | case MemBarrierKind::kAnyAny: | 
|  | 1262 | case MemBarrierKind::kAnyStore: { | 
|  | 1263 | type = BarrierAll; | 
|  | 1264 | break; | 
|  | 1265 | } | 
|  | 1266 | case MemBarrierKind::kLoadAny: { | 
|  | 1267 | type = BarrierReads; | 
|  | 1268 | break; | 
|  | 1269 | } | 
|  | 1270 | case MemBarrierKind::kStoreStore: { | 
|  | 1271 | type = BarrierWrites; | 
|  | 1272 | break; | 
|  | 1273 | } | 
|  | 1274 | default: | 
|  | 1275 | LOG(FATAL) << "Unexpected memory barrier " << kind; | 
|  | 1276 | } | 
|  | 1277 | __ Dmb(InnerShareable, type); | 
|  | 1278 | } | 
|  | 1279 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1280 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, | 
|  | 1281 | HBasicBlock* successor) { | 
|  | 1282 | SuspendCheckSlowPathARM64* slow_path = | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1283 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); | 
|  | 1284 | if (slow_path == nullptr) { | 
|  | 1285 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); | 
|  | 1286 | instruction->SetSlowPath(slow_path); | 
|  | 1287 | codegen_->AddSlowPath(slow_path); | 
|  | 1288 | if (successor != nullptr) { | 
|  | 1289 | DCHECK(successor->IsLoopHeader()); | 
|  | 1290 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); | 
|  | 1291 | } | 
|  | 1292 | } else { | 
|  | 1293 | DCHECK_EQ(slow_path->GetSuccessor(), successor); | 
|  | 1294 | } | 
|  | 1295 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1296 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); | 
|  | 1297 | Register temp = temps.AcquireW(); | 
|  | 1298 |  | 
|  | 1299 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue())); | 
|  | 1300 | if (successor == nullptr) { | 
|  | 1301 | __ Cbnz(temp, slow_path->GetEntryLabel()); | 
|  | 1302 | __ Bind(slow_path->GetReturnLabel()); | 
|  | 1303 | } else { | 
|  | 1304 | __ Cbz(temp, codegen_->GetLabelOf(successor)); | 
|  | 1305 | __ B(slow_path->GetEntryLabel()); | 
|  | 1306 | // slow_path will return to GetLabelOf(successor). | 
|  | 1307 | } | 
|  | 1308 | } | 
|  | 1309 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1310 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, | 
|  | 1311 | CodeGeneratorARM64* codegen) | 
|  | 1312 | : HGraphVisitor(graph), | 
|  | 1313 | assembler_(codegen->GetAssembler()), | 
|  | 1314 | codegen_(codegen) {} | 
|  | 1315 |  | 
|  | 1316 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M)              \ | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1317 | /* No unimplemented IR. */ | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1318 |  | 
|  | 1319 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode | 
|  | 1320 |  | 
|  | 1321 | enum UnimplementedInstructionBreakCode { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1322 | // Using a base helps identify when we hit such breakpoints. | 
|  | 1323 | UnimplementedInstructionBreakCodeBaseCode = 0x900, | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1324 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), | 
|  | 1325 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) | 
|  | 1326 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION | 
|  | 1327 | }; | 
|  | 1328 |  | 
|  | 1329 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name)                               \ | 
|  | 1330 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) {                   \ | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1331 | UNUSED(instr);                                                                    \ | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1332 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name));                               \ | 
|  | 1333 | }                                                                                   \ | 
|  | 1334 | void LocationsBuilderARM64::Visit##name(H##name* instr) {                           \ | 
|  | 1335 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ | 
|  | 1336 | locations->SetOut(Location::Any());                                               \ | 
|  | 1337 | } | 
|  | 1338 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) | 
|  | 1339 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS | 
|  | 1340 |  | 
|  | 1341 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1342 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1343 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1344 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1345 | DCHECK_EQ(instr->InputCount(), 2U); | 
|  | 1346 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); | 
|  | 1347 | Primitive::Type type = instr->GetResultType(); | 
|  | 1348 | switch (type) { | 
|  | 1349 | case Primitive::kPrimInt: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1350 | case Primitive::kPrimLong: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1351 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1352 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); | 
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1354 | break; | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1355 |  | 
|  | 1356 | case Primitive::kPrimFloat: | 
|  | 1357 | case Primitive::kPrimDouble: | 
|  | 1358 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 1359 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1360 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1361 | break; | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1362 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1363 | default: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1364 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1365 | } | 
|  | 1366 | } | 
|  | 1367 |  | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1368 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { | 
|  | 1369 | LocationSummary* locations = | 
|  | 1370 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 1371 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1372 | if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
|  | 1373 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 1374 | } else { | 
|  | 1375 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1376 | } | 
|  | 1377 | } | 
|  | 1378 |  | 
|  | 1379 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, | 
|  | 1380 | const FieldInfo& field_info) { | 
|  | 1381 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1382 | Primitive::Type field_type = field_info.GetFieldType(); | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1383 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1384 |  | 
|  | 1385 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); | 
|  | 1386 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); | 
|  | 1387 |  | 
|  | 1388 | if (field_info.IsVolatile()) { | 
|  | 1389 | if (use_acquire_release) { | 
|  | 1390 | // NB: LoadAcquire will record the pc info if needed. | 
|  | 1391 | codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field); | 
|  | 1392 | } else { | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1393 | codegen_->Load(field_type, OutputCPURegister(instruction), field); | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1394 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1395 | // For IRIW sequential consistency kLoadAny is not sufficient. | 
|  | 1396 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); | 
|  | 1397 | } | 
|  | 1398 | } else { | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1399 | codegen_->Load(field_type, OutputCPURegister(instruction), field); | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1400 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1401 | } | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1402 |  | 
|  | 1403 | if (field_type == Primitive::kPrimNot) { | 
|  | 1404 | GetAssembler()->MaybeUnpoisonHeapReference(OutputCPURegister(instruction).W()); | 
|  | 1405 | } | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1406 | } | 
|  | 1407 |  | 
|  | 1408 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { | 
|  | 1409 | LocationSummary* locations = | 
|  | 1410 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 1411 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1412 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { | 
|  | 1413 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 1414 | } else { | 
|  | 1415 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 1416 | } | 
|  | 1417 | } | 
|  | 1418 |  | 
|  | 1419 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1420 | const FieldInfo& field_info, | 
|  | 1421 | bool value_can_be_null) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1422 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1423 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1424 |  | 
|  | 1425 | Register obj = InputRegisterAt(instruction, 0); | 
|  | 1426 | CPURegister value = InputCPURegisterAt(instruction, 1); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1427 | CPURegister source = value; | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1428 | Offset offset = field_info.GetFieldOffset(); | 
|  | 1429 | Primitive::Type field_type = field_info.GetFieldType(); | 
|  | 1430 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); | 
|  | 1431 |  | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1432 | { | 
|  | 1433 | // We use a block to end the scratch scope before the write barrier, thus | 
|  | 1434 | // freeing the temporary registers so they can be used in `MarkGCCard`. | 
|  | 1435 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 1436 |  | 
|  | 1437 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { | 
|  | 1438 | DCHECK(value.IsW()); | 
|  | 1439 | Register temp = temps.AcquireW(); | 
|  | 1440 | __ Mov(temp, value.W()); | 
|  | 1441 | GetAssembler()->PoisonHeapReference(temp.W()); | 
|  | 1442 | source = temp; | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1443 | } | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1444 |  | 
|  | 1445 | if (field_info.IsVolatile()) { | 
|  | 1446 | if (use_acquire_release) { | 
|  | 1447 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); | 
|  | 1448 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1449 | } else { | 
|  | 1450 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); | 
|  | 1451 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); | 
|  | 1452 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1453 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); | 
|  | 1454 | } | 
|  | 1455 | } else { | 
|  | 1456 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); | 
|  | 1457 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1458 | } | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1459 | } | 
|  | 1460 |  | 
|  | 1461 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1462 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1463 | } | 
|  | 1464 | } | 
|  | 1465 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1466 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1467 | Primitive::Type type = instr->GetType(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1468 |  | 
|  | 1469 | switch (type) { | 
|  | 1470 | case Primitive::kPrimInt: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1471 | case Primitive::kPrimLong: { | 
|  | 1472 | Register dst = OutputRegister(instr); | 
|  | 1473 | Register lhs = InputRegisterAt(instr, 0); | 
|  | 1474 | Operand rhs = InputOperandAt(instr, 1); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1475 | if (instr->IsAdd()) { | 
|  | 1476 | __ Add(dst, lhs, rhs); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1477 | } else if (instr->IsAnd()) { | 
|  | 1478 | __ And(dst, lhs, rhs); | 
|  | 1479 | } else if (instr->IsOr()) { | 
|  | 1480 | __ Orr(dst, lhs, rhs); | 
|  | 1481 | } else if (instr->IsSub()) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1482 | __ Sub(dst, lhs, rhs); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1483 | } else { | 
|  | 1484 | DCHECK(instr->IsXor()); | 
|  | 1485 | __ Eor(dst, lhs, rhs); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1486 | } | 
|  | 1487 | break; | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1488 | } | 
|  | 1489 | case Primitive::kPrimFloat: | 
|  | 1490 | case Primitive::kPrimDouble: { | 
|  | 1491 | FPRegister dst = OutputFPRegister(instr); | 
|  | 1492 | FPRegister lhs = InputFPRegisterAt(instr, 0); | 
|  | 1493 | FPRegister rhs = InputFPRegisterAt(instr, 1); | 
|  | 1494 | if (instr->IsAdd()) { | 
|  | 1495 | __ Fadd(dst, lhs, rhs); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1496 | } else if (instr->IsSub()) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1497 | __ Fsub(dst, lhs, rhs); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1498 | } else { | 
|  | 1499 | LOG(FATAL) << "Unexpected floating-point binary operation"; | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1500 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1501 | break; | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1502 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1503 | default: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1504 | LOG(FATAL) << "Unexpected binary operation type " << type; | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1505 | } | 
|  | 1506 | } | 
|  | 1507 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1508 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { | 
|  | 1509 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); | 
|  | 1510 |  | 
|  | 1511 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); | 
|  | 1512 | Primitive::Type type = instr->GetResultType(); | 
|  | 1513 | switch (type) { | 
|  | 1514 | case Primitive::kPrimInt: | 
|  | 1515 | case Primitive::kPrimLong: { | 
|  | 1516 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1517 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); | 
|  | 1518 | locations->SetOut(Location::RequiresRegister()); | 
|  | 1519 | break; | 
|  | 1520 | } | 
|  | 1521 | default: | 
|  | 1522 | LOG(FATAL) << "Unexpected shift type " << type; | 
|  | 1523 | } | 
|  | 1524 | } | 
|  | 1525 |  | 
|  | 1526 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { | 
|  | 1527 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); | 
|  | 1528 |  | 
|  | 1529 | Primitive::Type type = instr->GetType(); | 
|  | 1530 | switch (type) { | 
|  | 1531 | case Primitive::kPrimInt: | 
|  | 1532 | case Primitive::kPrimLong: { | 
|  | 1533 | Register dst = OutputRegister(instr); | 
|  | 1534 | Register lhs = InputRegisterAt(instr, 0); | 
|  | 1535 | Operand rhs = InputOperandAt(instr, 1); | 
|  | 1536 | if (rhs.IsImmediate()) { | 
|  | 1537 | uint32_t shift_value = (type == Primitive::kPrimInt) | 
|  | 1538 | ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue) | 
|  | 1539 | : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue); | 
|  | 1540 | if (instr->IsShl()) { | 
|  | 1541 | __ Lsl(dst, lhs, shift_value); | 
|  | 1542 | } else if (instr->IsShr()) { | 
|  | 1543 | __ Asr(dst, lhs, shift_value); | 
|  | 1544 | } else { | 
|  | 1545 | __ Lsr(dst, lhs, shift_value); | 
|  | 1546 | } | 
|  | 1547 | } else { | 
|  | 1548 | Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W(); | 
|  | 1549 |  | 
|  | 1550 | if (instr->IsShl()) { | 
|  | 1551 | __ Lsl(dst, lhs, rhs_reg); | 
|  | 1552 | } else if (instr->IsShr()) { | 
|  | 1553 | __ Asr(dst, lhs, rhs_reg); | 
|  | 1554 | } else { | 
|  | 1555 | __ Lsr(dst, lhs, rhs_reg); | 
|  | 1556 | } | 
|  | 1557 | } | 
|  | 1558 | break; | 
|  | 1559 | } | 
|  | 1560 | default: | 
|  | 1561 | LOG(FATAL) << "Unexpected shift operation type " << type; | 
|  | 1562 | } | 
|  | 1563 | } | 
|  | 1564 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1565 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1566 | HandleBinaryOp(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1567 | } | 
|  | 1568 |  | 
|  | 1569 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1570 | HandleBinaryOp(instruction); | 
|  | 1571 | } | 
|  | 1572 |  | 
|  | 1573 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { | 
|  | 1574 | HandleBinaryOp(instruction); | 
|  | 1575 | } | 
|  | 1576 |  | 
|  | 1577 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { | 
|  | 1578 | HandleBinaryOp(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1579 | } | 
|  | 1580 |  | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1581 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { | 
|  | 1582 | LocationSummary* locations = | 
|  | 1583 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 1584 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1585 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 1586 | if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
|  | 1587 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 1588 | } else { | 
|  | 1589 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1590 | } | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1591 | } | 
|  | 1592 |  | 
|  | 1593 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { | 
|  | 1594 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1595 | Primitive::Type type = instruction->GetType(); | 
|  | 1596 | Register obj = InputRegisterAt(instruction, 0); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1597 | Location index = locations->InAt(1); | 
|  | 1598 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1599 | MemOperand source = HeapOperand(obj); | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1600 | MacroAssembler* masm = GetVIXLAssembler(); | 
|  | 1601 | UseScratchRegisterScope temps(masm); | 
|  | 1602 | BlockPoolsScope block_pools(masm); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1603 |  | 
|  | 1604 | if (index.IsConstant()) { | 
|  | 1605 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1606 | source = HeapOperand(obj, offset); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1607 | } else { | 
|  | 1608 | Register temp = temps.AcquireSameSizeAs(obj); | 
| Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 1609 | __ Add(temp, obj, offset); | 
|  | 1610 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1611 | } | 
|  | 1612 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1613 | codegen_->Load(type, OutputCPURegister(instruction), source); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1614 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1615 |  | 
|  | 1616 | if (type == Primitive::kPrimNot) { | 
|  | 1617 | GetAssembler()->MaybeUnpoisonHeapReference(OutputCPURegister(instruction).W()); | 
|  | 1618 | } | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1619 | } | 
|  | 1620 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1621 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { | 
|  | 1622 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 1623 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1624 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1625 | } | 
|  | 1626 |  | 
|  | 1627 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1628 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1629 | __ Ldr(OutputRegister(instruction), | 
|  | 1630 | HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset())); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1631 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1632 | } | 
|  | 1633 |  | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1634 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1635 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 1636 | instruction, | 
|  | 1637 | instruction->NeedsTypeCheck() ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); | 
|  | 1638 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1639 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 1640 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { | 
|  | 1641 | locations->SetInAt(2, Location::RequiresFpuRegister()); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1642 | } else { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1643 | locations->SetInAt(2, Location::RequiresRegister()); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1644 | } | 
|  | 1645 | } | 
|  | 1646 |  | 
|  | 1647 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { | 
|  | 1648 | Primitive::Type value_type = instruction->GetComponentType(); | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1649 | LocationSummary* locations = instruction->GetLocations(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1650 | bool may_need_runtime_call = locations->CanCall(); | 
|  | 1651 | bool needs_write_barrier = | 
|  | 1652 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1653 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1654 | Register array = InputRegisterAt(instruction, 0); | 
|  | 1655 | CPURegister value = InputCPURegisterAt(instruction, 2); | 
|  | 1656 | CPURegister source = value; | 
|  | 1657 | Location index = locations->InAt(1); | 
|  | 1658 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); | 
|  | 1659 | MemOperand destination = HeapOperand(array); | 
|  | 1660 | MacroAssembler* masm = GetVIXLAssembler(); | 
|  | 1661 | BlockPoolsScope block_pools(masm); | 
|  | 1662 |  | 
|  | 1663 | if (!needs_write_barrier) { | 
|  | 1664 | DCHECK(!may_need_runtime_call); | 
|  | 1665 | if (index.IsConstant()) { | 
|  | 1666 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); | 
|  | 1667 | destination = HeapOperand(array, offset); | 
|  | 1668 | } else { | 
|  | 1669 | UseScratchRegisterScope temps(masm); | 
|  | 1670 | Register temp = temps.AcquireSameSizeAs(array); | 
|  | 1671 | __ Add(temp, array, offset); | 
|  | 1672 | destination = HeapOperand(temp, | 
|  | 1673 | XRegisterFrom(index), | 
|  | 1674 | LSL, | 
|  | 1675 | Primitive::ComponentSizeShift(value_type)); | 
|  | 1676 | } | 
|  | 1677 | codegen_->Store(value_type, value, destination); | 
|  | 1678 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1679 | } else { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1680 | DCHECK(needs_write_barrier); | 
|  | 1681 | vixl::Label done; | 
|  | 1682 | SlowPathCodeARM64* slow_path = nullptr; | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1683 | { | 
|  | 1684 | // We use a block to end the scratch scope before the write barrier, thus | 
|  | 1685 | // freeing the temporary registers so they can be used in `MarkGCCard`. | 
|  | 1686 | UseScratchRegisterScope temps(masm); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1687 | Register temp = temps.AcquireSameSizeAs(array); | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1688 | if (index.IsConstant()) { | 
|  | 1689 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1690 | destination = HeapOperand(array, offset); | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1691 | } else { | 
| Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 1692 | destination = HeapOperand(temp, | 
|  | 1693 | XRegisterFrom(index), | 
|  | 1694 | LSL, | 
|  | 1695 | Primitive::ComponentSizeShift(value_type)); | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1696 | } | 
|  | 1697 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1698 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 1699 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
|  | 1700 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
|  | 1701 |  | 
|  | 1702 | if (may_need_runtime_call) { | 
|  | 1703 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); | 
|  | 1704 | codegen_->AddSlowPath(slow_path); | 
|  | 1705 | if (instruction->GetValueCanBeNull()) { | 
|  | 1706 | vixl::Label non_zero; | 
|  | 1707 | __ Cbnz(Register(value), &non_zero); | 
|  | 1708 | if (!index.IsConstant()) { | 
|  | 1709 | __ Add(temp, array, offset); | 
|  | 1710 | } | 
|  | 1711 | __ Str(wzr, destination); | 
|  | 1712 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1713 | __ B(&done); | 
|  | 1714 | __ Bind(&non_zero); | 
|  | 1715 | } | 
|  | 1716 |  | 
|  | 1717 | Register temp2 = temps.AcquireSameSizeAs(array); | 
|  | 1718 | __ Ldr(temp, HeapOperand(array, class_offset)); | 
|  | 1719 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1720 | GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
|  | 1721 | __ Ldr(temp, HeapOperand(temp, component_offset)); | 
|  | 1722 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); | 
|  | 1723 | // No need to poison/unpoison, we're comparing two poisoned references. | 
|  | 1724 | __ Cmp(temp, temp2); | 
|  | 1725 | if (instruction->StaticTypeOfArrayIsObjectArray()) { | 
|  | 1726 | vixl::Label do_put; | 
|  | 1727 | __ B(eq, &do_put); | 
|  | 1728 | GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
|  | 1729 | __ Ldr(temp, HeapOperand(temp, super_offset)); | 
|  | 1730 | // No need to unpoison, we're comparing against null. | 
|  | 1731 | __ Cbnz(temp, slow_path->GetEntryLabel()); | 
|  | 1732 | __ Bind(&do_put); | 
|  | 1733 | } else { | 
|  | 1734 | __ B(ne, slow_path->GetEntryLabel()); | 
|  | 1735 | } | 
| Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 1736 | temps.Release(temp2); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1737 | } | 
|  | 1738 |  | 
|  | 1739 | if (kPoisonHeapReferences) { | 
| Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 1740 | Register temp2 = temps.AcquireSameSizeAs(array); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1741 | DCHECK(value.IsW()); | 
| Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 1742 | __ Mov(temp2, value.W()); | 
|  | 1743 | GetAssembler()->PoisonHeapReference(temp2); | 
|  | 1744 | source = temp2; | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1745 | } | 
|  | 1746 |  | 
|  | 1747 | if (!index.IsConstant()) { | 
|  | 1748 | __ Add(temp, array, offset); | 
|  | 1749 | } | 
| Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 1750 | __ Str(source, destination); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1751 |  | 
|  | 1752 | if (!may_need_runtime_call) { | 
|  | 1753 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 1754 | } | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1755 | } | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1756 |  | 
|  | 1757 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); | 
|  | 1758 |  | 
|  | 1759 | if (done.IsLinked()) { | 
|  | 1760 | __ Bind(&done); | 
|  | 1761 | } | 
|  | 1762 |  | 
|  | 1763 | if (slow_path != nullptr) { | 
|  | 1764 | __ Bind(slow_path->GetExitLabel()); | 
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1765 | } | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1766 | } | 
|  | 1767 | } | 
|  | 1768 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1769 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1770 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 1771 | ? LocationSummary::kCallOnSlowPath | 
|  | 1772 | : LocationSummary::kNoCall; | 
|  | 1773 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1774 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 1775 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1776 | if (instruction->HasUses()) { | 
|  | 1777 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 1778 | } | 
|  | 1779 | } | 
|  | 1780 |  | 
|  | 1781 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1782 | BoundsCheckSlowPathARM64* slow_path = | 
|  | 1783 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1784 | codegen_->AddSlowPath(slow_path); | 
|  | 1785 |  | 
|  | 1786 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); | 
|  | 1787 | __ B(slow_path->GetEntryLabel(), hs); | 
|  | 1788 | } | 
|  | 1789 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1790 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { | 
|  | 1791 | LocationSummary* locations = | 
|  | 1792 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); | 
|  | 1793 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1794 | if (check->HasUses()) { | 
|  | 1795 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 1796 | } | 
|  | 1797 | } | 
|  | 1798 |  | 
|  | 1799 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { | 
|  | 1800 | // We assume the class is not null. | 
|  | 1801 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( | 
|  | 1802 | check->GetLoadClass(), check, check->GetDexPc(), true); | 
|  | 1803 | codegen_->AddSlowPath(slow_path); | 
|  | 1804 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); | 
|  | 1805 | } | 
|  | 1806 |  | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1807 | static bool IsFloatingPointZeroConstant(HInstruction* instruction) { | 
|  | 1808 | return (instruction->IsFloatConstant() && (instruction->AsFloatConstant()->GetValue() == 0.0f)) | 
|  | 1809 | || (instruction->IsDoubleConstant() && (instruction->AsDoubleConstant()->GetValue() == 0.0)); | 
|  | 1810 | } | 
|  | 1811 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1812 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1813 | LocationSummary* locations = | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1814 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); | 
|  | 1815 | Primitive::Type in_type = compare->InputAt(0)->GetType(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1816 | switch (in_type) { | 
|  | 1817 | case Primitive::kPrimLong: { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1818 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1819 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1820 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 1821 | break; | 
|  | 1822 | } | 
|  | 1823 | case Primitive::kPrimFloat: | 
|  | 1824 | case Primitive::kPrimDouble: { | 
|  | 1825 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1826 | locations->SetInAt(1, | 
|  | 1827 | IsFloatingPointZeroConstant(compare->InputAt(1)) | 
|  | 1828 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) | 
|  | 1829 | : Location::RequiresFpuRegister()); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1830 | locations->SetOut(Location::RequiresRegister()); | 
|  | 1831 | break; | 
|  | 1832 | } | 
|  | 1833 | default: | 
|  | 1834 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; | 
|  | 1835 | } | 
|  | 1836 | } | 
|  | 1837 |  | 
|  | 1838 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { | 
|  | 1839 | Primitive::Type in_type = compare->InputAt(0)->GetType(); | 
|  | 1840 |  | 
|  | 1841 | //  0 if: left == right | 
|  | 1842 | //  1 if: left  > right | 
|  | 1843 | // -1 if: left  < right | 
|  | 1844 | switch (in_type) { | 
|  | 1845 | case Primitive::kPrimLong: { | 
|  | 1846 | Register result = OutputRegister(compare); | 
|  | 1847 | Register left = InputRegisterAt(compare, 0); | 
|  | 1848 | Operand right = InputOperandAt(compare, 1); | 
|  | 1849 |  | 
|  | 1850 | __ Cmp(left, right); | 
|  | 1851 | __ Cset(result, ne); | 
|  | 1852 | __ Cneg(result, result, lt); | 
|  | 1853 | break; | 
|  | 1854 | } | 
|  | 1855 | case Primitive::kPrimFloat: | 
|  | 1856 | case Primitive::kPrimDouble: { | 
|  | 1857 | Register result = OutputRegister(compare); | 
|  | 1858 | FPRegister left = InputFPRegisterAt(compare, 0); | 
| Alexandre Rames | 9341546 | 2015-02-17 15:08:20 +0000 | [diff] [blame] | 1859 | if (compare->GetLocations()->InAt(1).IsConstant()) { | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1860 | DCHECK(IsFloatingPointZeroConstant(compare->GetLocations()->InAt(1).GetConstant())); | 
|  | 1861 | // 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] | 1862 | __ Fcmp(left, 0.0); | 
|  | 1863 | } else { | 
|  | 1864 | __ Fcmp(left, InputFPRegisterAt(compare, 1)); | 
|  | 1865 | } | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1866 | if (compare->IsGtBias()) { | 
|  | 1867 | __ Cset(result, ne); | 
|  | 1868 | } else { | 
|  | 1869 | __ Csetm(result, ne); | 
|  | 1870 | } | 
|  | 1871 | __ Cneg(result, result, compare->IsGtBias() ? mi : gt); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1872 | break; | 
|  | 1873 | } | 
|  | 1874 | default: | 
|  | 1875 | LOG(FATAL) << "Unimplemented compare type " << in_type; | 
|  | 1876 | } | 
|  | 1877 | } | 
|  | 1878 |  | 
|  | 1879 | void LocationsBuilderARM64::VisitCondition(HCondition* instruction) { | 
|  | 1880 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1881 |  | 
|  | 1882 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { | 
|  | 1883 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 1884 | locations->SetInAt(1, | 
|  | 1885 | IsFloatingPointZeroConstant(instruction->InputAt(1)) | 
|  | 1886 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) | 
|  | 1887 | : Location::RequiresFpuRegister()); | 
|  | 1888 | } else { | 
|  | 1889 | // Integer cases. | 
|  | 1890 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1891 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); | 
|  | 1892 | } | 
|  | 1893 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1894 | if (instruction->NeedsMaterialization()) { | 
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1895 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1896 | } | 
|  | 1897 | } | 
|  | 1898 |  | 
|  | 1899 | void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) { | 
|  | 1900 | if (!instruction->NeedsMaterialization()) { | 
|  | 1901 | return; | 
|  | 1902 | } | 
|  | 1903 |  | 
|  | 1904 | LocationSummary* locations = instruction->GetLocations(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1905 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1906 | IfCondition if_cond = instruction->GetCondition(); | 
|  | 1907 | Condition arm64_cond = ARM64Condition(if_cond); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1908 |  | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1909 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { | 
|  | 1910 | FPRegister lhs = InputFPRegisterAt(instruction, 0); | 
|  | 1911 | if (locations->InAt(1).IsConstant()) { | 
|  | 1912 | DCHECK(IsFloatingPointZeroConstant(locations->InAt(1).GetConstant())); | 
|  | 1913 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. | 
|  | 1914 | __ Fcmp(lhs, 0.0); | 
|  | 1915 | } else { | 
|  | 1916 | __ Fcmp(lhs, InputFPRegisterAt(instruction, 1)); | 
|  | 1917 | } | 
|  | 1918 | __ Cset(res, arm64_cond); | 
|  | 1919 | if (instruction->IsFPConditionTrueIfNaN()) { | 
|  | 1920 | // res = IsUnordered(arm64_cond) ? 1 : res  <=>  res = IsNotUnordered(arm64_cond) ? res : 1 | 
|  | 1921 | __ Csel(res, res, Operand(1), vc);  // VC for "not unordered". | 
|  | 1922 | } else if (instruction->IsFPConditionFalseIfNaN()) { | 
|  | 1923 | // res = IsUnordered(arm64_cond) ? 0 : res  <=>  res = IsNotUnordered(arm64_cond) ? res : 0 | 
|  | 1924 | __ Csel(res, res, Operand(0), vc);  // VC for "not unordered". | 
|  | 1925 | } | 
|  | 1926 | } else { | 
|  | 1927 | // Integer cases. | 
|  | 1928 | Register lhs = InputRegisterAt(instruction, 0); | 
|  | 1929 | Operand rhs = InputOperandAt(instruction, 1); | 
|  | 1930 | __ Cmp(lhs, rhs); | 
|  | 1931 | __ Cset(res, arm64_cond); | 
|  | 1932 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1933 | } | 
|  | 1934 |  | 
|  | 1935 | #define FOR_EACH_CONDITION_INSTRUCTION(M)                                                \ | 
|  | 1936 | M(Equal)                                                                               \ | 
|  | 1937 | M(NotEqual)                                                                            \ | 
|  | 1938 | M(LessThan)                                                                            \ | 
|  | 1939 | M(LessThanOrEqual)                                                                     \ | 
|  | 1940 | M(GreaterThan)                                                                         \ | 
|  | 1941 | M(GreaterThanOrEqual) | 
|  | 1942 | #define DEFINE_CONDITION_VISITORS(Name)                                                  \ | 
|  | 1943 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }         \ | 
|  | 1944 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } | 
|  | 1945 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1946 | #undef DEFINE_CONDITION_VISITORS | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1947 | #undef FOR_EACH_CONDITION_INSTRUCTION | 
|  | 1948 |  | 
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1949 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { | 
|  | 1950 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 1951 |  | 
|  | 1952 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1953 | Location second = locations->InAt(1); | 
|  | 1954 | DCHECK(second.IsConstant()); | 
|  | 1955 |  | 
|  | 1956 | Register out = OutputRegister(instruction); | 
|  | 1957 | Register dividend = InputRegisterAt(instruction, 0); | 
|  | 1958 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 1959 | DCHECK(imm == 1 || imm == -1); | 
|  | 1960 |  | 
|  | 1961 | if (instruction->IsRem()) { | 
|  | 1962 | __ Mov(out, 0); | 
|  | 1963 | } else { | 
|  | 1964 | if (imm == 1) { | 
|  | 1965 | __ Mov(out, dividend); | 
|  | 1966 | } else { | 
|  | 1967 | __ Neg(out, dividend); | 
|  | 1968 | } | 
|  | 1969 | } | 
|  | 1970 | } | 
|  | 1971 |  | 
|  | 1972 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { | 
|  | 1973 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 1974 |  | 
|  | 1975 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 1976 | Location second = locations->InAt(1); | 
|  | 1977 | DCHECK(second.IsConstant()); | 
|  | 1978 |  | 
|  | 1979 | Register out = OutputRegister(instruction); | 
|  | 1980 | Register dividend = InputRegisterAt(instruction, 0); | 
|  | 1981 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
| Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 1982 | uint64_t abs_imm = static_cast<uint64_t>(std::abs(imm)); | 
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1983 | DCHECK(IsPowerOfTwo(abs_imm)); | 
|  | 1984 | int ctz_imm = CTZ(abs_imm); | 
|  | 1985 |  | 
|  | 1986 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 1987 | Register temp = temps.AcquireSameSizeAs(out); | 
|  | 1988 |  | 
|  | 1989 | if (instruction->IsDiv()) { | 
|  | 1990 | __ Add(temp, dividend, abs_imm - 1); | 
|  | 1991 | __ Cmp(dividend, 0); | 
|  | 1992 | __ Csel(out, temp, dividend, lt); | 
|  | 1993 | if (imm > 0) { | 
|  | 1994 | __ Asr(out, out, ctz_imm); | 
|  | 1995 | } else { | 
|  | 1996 | __ Neg(out, Operand(out, ASR, ctz_imm)); | 
|  | 1997 | } | 
|  | 1998 | } else { | 
|  | 1999 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; | 
|  | 2000 | __ Asr(temp, dividend, bits - 1); | 
|  | 2001 | __ Lsr(temp, temp, bits - ctz_imm); | 
|  | 2002 | __ Add(out, dividend, temp); | 
|  | 2003 | __ And(out, out, abs_imm - 1); | 
|  | 2004 | __ Sub(out, out, temp); | 
|  | 2005 | } | 
|  | 2006 | } | 
|  | 2007 |  | 
|  | 2008 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { | 
|  | 2009 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2010 |  | 
|  | 2011 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2012 | Location second = locations->InAt(1); | 
|  | 2013 | DCHECK(second.IsConstant()); | 
|  | 2014 |  | 
|  | 2015 | Register out = OutputRegister(instruction); | 
|  | 2016 | Register dividend = InputRegisterAt(instruction, 0); | 
|  | 2017 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 2018 |  | 
|  | 2019 | Primitive::Type type = instruction->GetResultType(); | 
|  | 2020 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); | 
|  | 2021 |  | 
|  | 2022 | int64_t magic; | 
|  | 2023 | int shift; | 
|  | 2024 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); | 
|  | 2025 |  | 
|  | 2026 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 2027 | Register temp = temps.AcquireSameSizeAs(out); | 
|  | 2028 |  | 
|  | 2029 | // temp = get_high(dividend * magic) | 
|  | 2030 | __ Mov(temp, magic); | 
|  | 2031 | if (type == Primitive::kPrimLong) { | 
|  | 2032 | __ Smulh(temp, dividend, temp); | 
|  | 2033 | } else { | 
|  | 2034 | __ Smull(temp.X(), dividend, temp); | 
|  | 2035 | __ Lsr(temp.X(), temp.X(), 32); | 
|  | 2036 | } | 
|  | 2037 |  | 
|  | 2038 | if (imm > 0 && magic < 0) { | 
|  | 2039 | __ Add(temp, temp, dividend); | 
|  | 2040 | } else if (imm < 0 && magic > 0) { | 
|  | 2041 | __ Sub(temp, temp, dividend); | 
|  | 2042 | } | 
|  | 2043 |  | 
|  | 2044 | if (shift != 0) { | 
|  | 2045 | __ Asr(temp, temp, shift); | 
|  | 2046 | } | 
|  | 2047 |  | 
|  | 2048 | if (instruction->IsDiv()) { | 
|  | 2049 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); | 
|  | 2050 | } else { | 
|  | 2051 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); | 
|  | 2052 | // TODO: Strength reduction for msub. | 
|  | 2053 | Register temp_imm = temps.AcquireSameSizeAs(out); | 
|  | 2054 | __ Mov(temp_imm, imm); | 
|  | 2055 | __ Msub(out, temp, temp_imm, dividend); | 
|  | 2056 | } | 
|  | 2057 | } | 
|  | 2058 |  | 
|  | 2059 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { | 
|  | 2060 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 2061 | Primitive::Type type = instruction->GetResultType(); | 
|  | 2062 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); | 
|  | 2063 |  | 
|  | 2064 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2065 | Register out = OutputRegister(instruction); | 
|  | 2066 | Location second = locations->InAt(1); | 
|  | 2067 |  | 
|  | 2068 | if (second.IsConstant()) { | 
|  | 2069 | int64_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 2070 |  | 
|  | 2071 | if (imm == 0) { | 
|  | 2072 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. | 
|  | 2073 | } else if (imm == 1 || imm == -1) { | 
|  | 2074 | DivRemOneOrMinusOne(instruction); | 
|  | 2075 | } else if (IsPowerOfTwo(std::abs(imm))) { | 
|  | 2076 | DivRemByPowerOfTwo(instruction); | 
|  | 2077 | } else { | 
|  | 2078 | DCHECK(imm <= -2 || imm >= 2); | 
|  | 2079 | GenerateDivRemWithAnyConstant(instruction); | 
|  | 2080 | } | 
|  | 2081 | } else { | 
|  | 2082 | Register dividend = InputRegisterAt(instruction, 0); | 
|  | 2083 | Register divisor = InputRegisterAt(instruction, 1); | 
|  | 2084 | if (instruction->IsDiv()) { | 
|  | 2085 | __ Sdiv(out, dividend, divisor); | 
|  | 2086 | } else { | 
|  | 2087 | UseScratchRegisterScope temps(GetVIXLAssembler()); | 
|  | 2088 | Register temp = temps.AcquireSameSizeAs(out); | 
|  | 2089 | __ Sdiv(temp, dividend, divisor); | 
|  | 2090 | __ Msub(out, temp, divisor, dividend); | 
|  | 2091 | } | 
|  | 2092 | } | 
|  | 2093 | } | 
|  | 2094 |  | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2095 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { | 
|  | 2096 | LocationSummary* locations = | 
|  | 2097 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); | 
|  | 2098 | switch (div->GetResultType()) { | 
|  | 2099 | case Primitive::kPrimInt: | 
|  | 2100 | case Primitive::kPrimLong: | 
|  | 2101 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2102 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2103 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2104 | break; | 
|  | 2105 |  | 
|  | 2106 | case Primitive::kPrimFloat: | 
|  | 2107 | case Primitive::kPrimDouble: | 
|  | 2108 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2109 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 2110 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 2111 | break; | 
|  | 2112 |  | 
|  | 2113 | default: | 
|  | 2114 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); | 
|  | 2115 | } | 
|  | 2116 | } | 
|  | 2117 |  | 
|  | 2118 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { | 
|  | 2119 | Primitive::Type type = div->GetResultType(); | 
|  | 2120 | switch (type) { | 
|  | 2121 | case Primitive::kPrimInt: | 
|  | 2122 | case Primitive::kPrimLong: | 
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2123 | GenerateDivRemIntegral(div); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2124 | break; | 
|  | 2125 |  | 
|  | 2126 | case Primitive::kPrimFloat: | 
|  | 2127 | case Primitive::kPrimDouble: | 
|  | 2128 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); | 
|  | 2129 | break; | 
|  | 2130 |  | 
|  | 2131 | default: | 
|  | 2132 | LOG(FATAL) << "Unexpected div type " << type; | 
|  | 2133 | } | 
|  | 2134 | } | 
|  | 2135 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2136 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2137 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 2138 | ? LocationSummary::kCallOnSlowPath | 
|  | 2139 | : LocationSummary::kNoCall; | 
|  | 2140 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2141 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
|  | 2142 | if (instruction->HasUses()) { | 
|  | 2143 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2144 | } | 
|  | 2145 | } | 
|  | 2146 |  | 
|  | 2147 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
|  | 2148 | SlowPathCodeARM64* slow_path = | 
|  | 2149 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); | 
|  | 2150 | codegen_->AddSlowPath(slow_path); | 
|  | 2151 | Location value = instruction->GetLocations()->InAt(0); | 
|  | 2152 |  | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2153 | Primitive::Type type = instruction->GetType(); | 
|  | 2154 |  | 
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2155 | if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) { | 
|  | 2156 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2157 | return; | 
|  | 2158 | } | 
|  | 2159 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2160 | if (value.IsConstant()) { | 
|  | 2161 | int64_t divisor = Int64ConstantFrom(value); | 
|  | 2162 | if (divisor == 0) { | 
|  | 2163 | __ B(slow_path->GetEntryLabel()); | 
|  | 2164 | } else { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2165 | // A division by a non-null constant is valid. We don't need to perform | 
|  | 2166 | // any check, so simply fall through. | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2167 | } | 
|  | 2168 | } else { | 
|  | 2169 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); | 
|  | 2170 | } | 
|  | 2171 | } | 
|  | 2172 |  | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2173 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { | 
|  | 2174 | LocationSummary* locations = | 
|  | 2175 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
|  | 2176 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2177 | } | 
|  | 2178 |  | 
|  | 2179 | void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) { | 
|  | 2180 | UNUSED(constant); | 
|  | 2181 | // Will be generated at use site. | 
|  | 2182 | } | 
|  | 2183 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2184 | void LocationsBuilderARM64::VisitExit(HExit* exit) { | 
|  | 2185 | exit->SetLocations(nullptr); | 
|  | 2186 | } | 
|  | 2187 |  | 
|  | 2188 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) { | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2189 | UNUSED(exit); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2190 | } | 
|  | 2191 |  | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2192 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { | 
|  | 2193 | LocationSummary* locations = | 
|  | 2194 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
|  | 2195 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2196 | } | 
|  | 2197 |  | 
|  | 2198 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) { | 
|  | 2199 | UNUSED(constant); | 
|  | 2200 | // Will be generated at use site. | 
|  | 2201 | } | 
|  | 2202 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2203 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2204 | DCHECK(!successor->IsExitBlock()); | 
|  | 2205 | HBasicBlock* block = got->GetBlock(); | 
|  | 2206 | HInstruction* previous = got->GetPrevious(); | 
|  | 2207 | HLoopInformation* info = block->GetLoopInformation(); | 
|  | 2208 |  | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2209 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2210 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); | 
|  | 2211 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); | 
|  | 2212 | return; | 
|  | 2213 | } | 
|  | 2214 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { | 
|  | 2215 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); | 
|  | 2216 | } | 
|  | 2217 | if (!codegen_->GoesToNextBlock(block, successor)) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2218 | __ B(codegen_->GetLabelOf(successor)); | 
|  | 2219 | } | 
|  | 2220 | } | 
|  | 2221 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2222 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { | 
|  | 2223 | got->SetLocations(nullptr); | 
|  | 2224 | } | 
|  | 2225 |  | 
|  | 2226 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { | 
|  | 2227 | HandleGoto(got, got->GetSuccessor()); | 
|  | 2228 | } | 
|  | 2229 |  | 
|  | 2230 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 2231 | try_boundary->SetLocations(nullptr); | 
|  | 2232 | } | 
|  | 2233 |  | 
|  | 2234 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 2235 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); | 
|  | 2236 | if (!successor->IsExitBlock()) { | 
|  | 2237 | HandleGoto(try_boundary, successor); | 
|  | 2238 | } | 
|  | 2239 | } | 
|  | 2240 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2241 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, | 
|  | 2242 | vixl::Label* true_target, | 
|  | 2243 | vixl::Label* false_target, | 
|  | 2244 | vixl::Label* always_true_target) { | 
|  | 2245 | HInstruction* cond = instruction->InputAt(0); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2246 | HCondition* condition = cond->AsCondition(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2247 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2248 | if (cond->IsIntConstant()) { | 
|  | 2249 | int32_t cond_value = cond->AsIntConstant()->GetValue(); | 
|  | 2250 | if (cond_value == 1) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2251 | if (always_true_target != nullptr) { | 
|  | 2252 | __ B(always_true_target); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2253 | } | 
|  | 2254 | return; | 
|  | 2255 | } else { | 
|  | 2256 | DCHECK_EQ(cond_value, 0); | 
|  | 2257 | } | 
|  | 2258 | } else if (!cond->IsCondition() || condition->NeedsMaterialization()) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2259 | // The condition instruction has been materialized, compare the output to 0. | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2260 | Location cond_val = instruction->GetLocations()->InAt(0); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2261 | DCHECK(cond_val.IsRegister()); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2262 | __ Cbnz(InputRegisterAt(instruction, 0), true_target); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2263 | } else { | 
|  | 2264 | // The condition instruction has not been materialized, use its inputs as | 
|  | 2265 | // the comparison and its condition as the branch condition. | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2266 | Primitive::Type type = | 
|  | 2267 | cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; | 
|  | 2268 |  | 
|  | 2269 | if (Primitive::IsFloatingPointType(type)) { | 
|  | 2270 | // FP compares don't like null false_targets. | 
|  | 2271 | if (false_target == nullptr) { | 
|  | 2272 | false_target = codegen_->GetLabelOf(instruction->AsIf()->IfFalseSuccessor()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2273 | } | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2274 | FPRegister lhs = InputFPRegisterAt(condition, 0); | 
|  | 2275 | if (condition->GetLocations()->InAt(1).IsConstant()) { | 
|  | 2276 | DCHECK(IsFloatingPointZeroConstant(condition->GetLocations()->InAt(1).GetConstant())); | 
|  | 2277 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. | 
|  | 2278 | __ Fcmp(lhs, 0.0); | 
|  | 2279 | } else { | 
|  | 2280 | __ Fcmp(lhs, InputFPRegisterAt(condition, 1)); | 
|  | 2281 | } | 
|  | 2282 | if (condition->IsFPConditionTrueIfNaN()) { | 
|  | 2283 | __ B(vs, true_target);  // VS for unordered. | 
|  | 2284 | } else if (condition->IsFPConditionFalseIfNaN()) { | 
|  | 2285 | __ B(vs, false_target);  // VS for unordered. | 
|  | 2286 | } | 
|  | 2287 | __ B(ARM64Condition(condition->GetCondition()), true_target); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2288 | } else { | 
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2289 | // Integer cases. | 
|  | 2290 | Register lhs = InputRegisterAt(condition, 0); | 
|  | 2291 | Operand rhs = InputOperandAt(condition, 1); | 
|  | 2292 | Condition arm64_cond = ARM64Condition(condition->GetCondition()); | 
|  | 2293 | if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) { | 
|  | 2294 | switch (arm64_cond) { | 
|  | 2295 | case eq: | 
|  | 2296 | __ Cbz(lhs, true_target); | 
|  | 2297 | break; | 
|  | 2298 | case ne: | 
|  | 2299 | __ Cbnz(lhs, true_target); | 
|  | 2300 | break; | 
|  | 2301 | case lt: | 
|  | 2302 | // Test the sign bit and branch accordingly. | 
|  | 2303 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target); | 
|  | 2304 | break; | 
|  | 2305 | case ge: | 
|  | 2306 | // Test the sign bit and branch accordingly. | 
|  | 2307 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target); | 
|  | 2308 | break; | 
|  | 2309 | default: | 
|  | 2310 | // Without the `static_cast` the compiler throws an error for | 
|  | 2311 | // `-Werror=sign-promo`. | 
|  | 2312 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); | 
|  | 2313 | } | 
|  | 2314 | } else { | 
|  | 2315 | __ Cmp(lhs, rhs); | 
|  | 2316 | __ B(arm64_cond, true_target); | 
|  | 2317 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2318 | } | 
|  | 2319 | } | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2320 | if (false_target != nullptr) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2321 | __ B(false_target); | 
|  | 2322 | } | 
|  | 2323 | } | 
|  | 2324 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2325 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { | 
|  | 2326 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); | 
|  | 2327 | HInstruction* cond = if_instr->InputAt(0); | 
|  | 2328 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { | 
|  | 2329 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2330 | } | 
|  | 2331 | } | 
|  | 2332 |  | 
|  | 2333 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { | 
|  | 2334 | vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); | 
|  | 2335 | vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); | 
|  | 2336 | vixl::Label* always_true_target = true_target; | 
|  | 2337 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), | 
|  | 2338 | if_instr->IfTrueSuccessor())) { | 
|  | 2339 | always_true_target = nullptr; | 
|  | 2340 | } | 
|  | 2341 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), | 
|  | 2342 | if_instr->IfFalseSuccessor())) { | 
|  | 2343 | false_target = nullptr; | 
|  | 2344 | } | 
|  | 2345 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); | 
|  | 2346 | } | 
|  | 2347 |  | 
|  | 2348 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { | 
|  | 2349 | LocationSummary* locations = new (GetGraph()->GetArena()) | 
|  | 2350 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); | 
|  | 2351 | HInstruction* cond = deoptimize->InputAt(0); | 
|  | 2352 | DCHECK(cond->IsCondition()); | 
|  | 2353 | if (cond->AsCondition()->NeedsMaterialization()) { | 
|  | 2354 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2355 | } | 
|  | 2356 | } | 
|  | 2357 |  | 
|  | 2358 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { | 
|  | 2359 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) | 
|  | 2360 | DeoptimizationSlowPathARM64(deoptimize); | 
|  | 2361 | codegen_->AddSlowPath(slow_path); | 
|  | 2362 | vixl::Label* slow_path_entry = slow_path->GetEntryLabel(); | 
|  | 2363 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); | 
|  | 2364 | } | 
|  | 2365 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2366 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2367 | HandleFieldGet(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2368 | } | 
|  | 2369 |  | 
|  | 2370 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2371 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2372 | } | 
|  | 2373 |  | 
|  | 2374 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2375 | HandleFieldSet(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2376 | } | 
|  | 2377 |  | 
|  | 2378 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2379 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2380 | } | 
|  | 2381 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2382 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2383 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; | 
|  | 2384 | switch (instruction->GetTypeCheckKind()) { | 
|  | 2385 | case TypeCheckKind::kExactCheck: | 
|  | 2386 | case TypeCheckKind::kAbstractClassCheck: | 
|  | 2387 | case TypeCheckKind::kClassHierarchyCheck: | 
|  | 2388 | case TypeCheckKind::kArrayObjectCheck: | 
|  | 2389 | call_kind = LocationSummary::kNoCall; | 
|  | 2390 | break; | 
|  | 2391 | case TypeCheckKind::kInterfaceCheck: | 
|  | 2392 | call_kind = LocationSummary::kCall; | 
|  | 2393 | break; | 
|  | 2394 | case TypeCheckKind::kArrayCheck: | 
|  | 2395 | call_kind = LocationSummary::kCallOnSlowPath; | 
|  | 2396 | break; | 
|  | 2397 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2398 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2399 | if (call_kind != LocationSummary::kCall) { | 
|  | 2400 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2401 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2402 | // The out register is used as a temporary, so it overlaps with the inputs. | 
|  | 2403 | // Note that TypeCheckSlowPathARM64 uses this register too. | 
|  | 2404 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 2405 | } else { | 
|  | 2406 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 2407 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(0))); | 
|  | 2408 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); | 
|  | 2409 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); | 
|  | 2410 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2411 | } | 
|  | 2412 |  | 
|  | 2413 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { | 
|  | 2414 | LocationSummary* locations = instruction->GetLocations(); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2415 | Register obj = InputRegisterAt(instruction, 0); | 
|  | 2416 | Register cls = InputRegisterAt(instruction, 1); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2417 | Register out = OutputRegister(instruction); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2418 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 2419 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
|  | 2420 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
|  | 2421 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2422 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2423 | vixl::Label done, zero; | 
|  | 2424 | SlowPathCodeARM64* slow_path = nullptr; | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2425 |  | 
|  | 2426 | // Return 0 if `obj` is null. | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2427 | // Avoid null check if we know `obj` is not null. | 
|  | 2428 | if (instruction->MustDoNullCheck()) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2429 | __ Cbz(obj, &zero); | 
|  | 2430 | } | 
|  | 2431 |  | 
|  | 2432 | // In case of an interface check, we put the object class into the object register. | 
|  | 2433 | // This is safe, as the register is caller-save, and the object must be in another | 
|  | 2434 | // register if it survives the runtime call. | 
|  | 2435 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) | 
|  | 2436 | ? obj | 
|  | 2437 | : out; | 
|  | 2438 | __ Ldr(target, HeapOperand(obj.W(), class_offset)); | 
|  | 2439 | GetAssembler()->MaybeUnpoisonHeapReference(target); | 
|  | 2440 |  | 
|  | 2441 | switch (instruction->GetTypeCheckKind()) { | 
|  | 2442 | case TypeCheckKind::kExactCheck: { | 
|  | 2443 | __ Cmp(out, cls); | 
|  | 2444 | __ Cset(out, eq); | 
|  | 2445 | if (zero.IsLinked()) { | 
|  | 2446 | __ B(&done); | 
|  | 2447 | } | 
|  | 2448 | break; | 
|  | 2449 | } | 
|  | 2450 | case TypeCheckKind::kAbstractClassCheck: { | 
|  | 2451 | // If the class is abstract, we eagerly fetch the super class of the | 
|  | 2452 | // object to avoid doing a comparison we know will fail. | 
|  | 2453 | vixl::Label loop, success; | 
|  | 2454 | __ Bind(&loop); | 
|  | 2455 | __ Ldr(out, HeapOperand(out, super_offset)); | 
|  | 2456 | GetAssembler()->MaybeUnpoisonHeapReference(out); | 
|  | 2457 | // If `out` is null, we use it for the result, and jump to `done`. | 
|  | 2458 | __ Cbz(out, &done); | 
|  | 2459 | __ Cmp(out, cls); | 
|  | 2460 | __ B(ne, &loop); | 
|  | 2461 | __ Mov(out, 1); | 
|  | 2462 | if (zero.IsLinked()) { | 
|  | 2463 | __ B(&done); | 
|  | 2464 | } | 
|  | 2465 | break; | 
|  | 2466 | } | 
|  | 2467 | case TypeCheckKind::kClassHierarchyCheck: { | 
|  | 2468 | // Walk over the class hierarchy to find a match. | 
|  | 2469 | vixl::Label loop, success; | 
|  | 2470 | __ Bind(&loop); | 
|  | 2471 | __ Cmp(out, cls); | 
|  | 2472 | __ B(eq, &success); | 
|  | 2473 | __ Ldr(out, HeapOperand(out, super_offset)); | 
|  | 2474 | GetAssembler()->MaybeUnpoisonHeapReference(out); | 
|  | 2475 | __ Cbnz(out, &loop); | 
|  | 2476 | // If `out` is null, we use it for the result, and jump to `done`. | 
|  | 2477 | __ B(&done); | 
|  | 2478 | __ Bind(&success); | 
|  | 2479 | __ Mov(out, 1); | 
|  | 2480 | if (zero.IsLinked()) { | 
|  | 2481 | __ B(&done); | 
|  | 2482 | } | 
|  | 2483 | break; | 
|  | 2484 | } | 
|  | 2485 | case TypeCheckKind::kArrayObjectCheck: { | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2486 | // Do an exact check. | 
|  | 2487 | vixl::Label exact_check; | 
|  | 2488 | __ Cmp(out, cls); | 
|  | 2489 | __ B(eq, &exact_check); | 
|  | 2490 | // Otherwise, we need to check that the object's class is a non primitive array. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2491 | __ Ldr(out, HeapOperand(out, component_offset)); | 
|  | 2492 | GetAssembler()->MaybeUnpoisonHeapReference(out); | 
|  | 2493 | // If `out` is null, we use it for the result, and jump to `done`. | 
|  | 2494 | __ Cbz(out, &done); | 
|  | 2495 | __ Ldrh(out, HeapOperand(out, primitive_offset)); | 
|  | 2496 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); | 
|  | 2497 | __ Cbnz(out, &zero); | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2498 | __ Bind(&exact_check); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2499 | __ Mov(out, 1); | 
|  | 2500 | __ B(&done); | 
|  | 2501 | break; | 
|  | 2502 | } | 
|  | 2503 | case TypeCheckKind::kArrayCheck: { | 
|  | 2504 | __ Cmp(out, cls); | 
|  | 2505 | DCHECK(locations->OnlyCallsOnSlowPath()); | 
|  | 2506 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64( | 
|  | 2507 | instruction, /* is_fatal */ false); | 
|  | 2508 | codegen_->AddSlowPath(slow_path); | 
|  | 2509 | __ B(ne, slow_path->GetEntryLabel()); | 
|  | 2510 | __ Mov(out, 1); | 
|  | 2511 | if (zero.IsLinked()) { | 
|  | 2512 | __ B(&done); | 
|  | 2513 | } | 
|  | 2514 | break; | 
|  | 2515 | } | 
|  | 2516 |  | 
|  | 2517 | case TypeCheckKind::kInterfaceCheck: | 
|  | 2518 | default: { | 
|  | 2519 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), | 
|  | 2520 | instruction, | 
|  | 2521 | instruction->GetDexPc(), | 
|  | 2522 | nullptr); | 
|  | 2523 | if (zero.IsLinked()) { | 
|  | 2524 | __ B(&done); | 
|  | 2525 | } | 
|  | 2526 | break; | 
|  | 2527 | } | 
|  | 2528 | } | 
|  | 2529 |  | 
|  | 2530 | if (zero.IsLinked()) { | 
|  | 2531 | __ Bind(&zero); | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2532 | __ Mov(out, 0); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2533 | } | 
|  | 2534 |  | 
|  | 2535 | if (done.IsLinked()) { | 
|  | 2536 | __ Bind(&done); | 
|  | 2537 | } | 
|  | 2538 |  | 
|  | 2539 | if (slow_path != nullptr) { | 
|  | 2540 | __ Bind(slow_path->GetExitLabel()); | 
|  | 2541 | } | 
|  | 2542 | } | 
|  | 2543 |  | 
|  | 2544 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { | 
|  | 2545 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; | 
|  | 2546 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); | 
|  | 2547 |  | 
|  | 2548 | switch (instruction->GetTypeCheckKind()) { | 
|  | 2549 | case TypeCheckKind::kExactCheck: | 
|  | 2550 | case TypeCheckKind::kAbstractClassCheck: | 
|  | 2551 | case TypeCheckKind::kClassHierarchyCheck: | 
|  | 2552 | case TypeCheckKind::kArrayObjectCheck: | 
|  | 2553 | call_kind = throws_into_catch | 
|  | 2554 | ? LocationSummary::kCallOnSlowPath | 
|  | 2555 | : LocationSummary::kNoCall; | 
|  | 2556 | break; | 
|  | 2557 | case TypeCheckKind::kInterfaceCheck: | 
|  | 2558 | call_kind = LocationSummary::kCall; | 
|  | 2559 | break; | 
|  | 2560 | case TypeCheckKind::kArrayCheck: | 
|  | 2561 | call_kind = LocationSummary::kCallOnSlowPath; | 
|  | 2562 | break; | 
|  | 2563 | } | 
|  | 2564 |  | 
|  | 2565 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
|  | 2566 | instruction, call_kind); | 
|  | 2567 | if (call_kind != LocationSummary::kCall) { | 
|  | 2568 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2569 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2570 | // Note that TypeCheckSlowPathARM64 uses this register too. | 
|  | 2571 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 2572 | } else { | 
|  | 2573 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 2574 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(0))); | 
|  | 2575 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); | 
|  | 2576 | } | 
|  | 2577 | } | 
|  | 2578 |  | 
|  | 2579 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { | 
|  | 2580 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 2581 | Register obj = InputRegisterAt(instruction, 0); | 
|  | 2582 | Register cls = InputRegisterAt(instruction, 1); | 
|  | 2583 | Register temp; | 
|  | 2584 | if (!locations->WillCall()) { | 
|  | 2585 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); | 
|  | 2586 | } | 
|  | 2587 |  | 
|  | 2588 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 2589 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
|  | 2590 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
|  | 2591 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); | 
|  | 2592 | SlowPathCodeARM64* slow_path = nullptr; | 
|  | 2593 |  | 
|  | 2594 | if (!locations->WillCall()) { | 
|  | 2595 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64( | 
|  | 2596 | instruction, !locations->CanCall()); | 
|  | 2597 | codegen_->AddSlowPath(slow_path); | 
|  | 2598 | } | 
|  | 2599 |  | 
|  | 2600 | vixl::Label done; | 
|  | 2601 | // Avoid null check if we know obj is not null. | 
|  | 2602 | if (instruction->MustDoNullCheck()) { | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2603 | __ Cbz(obj, &done); | 
|  | 2604 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2605 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2606 | if (locations->WillCall()) { | 
|  | 2607 | __ Ldr(obj, HeapOperand(obj, class_offset)); | 
|  | 2608 | GetAssembler()->MaybeUnpoisonHeapReference(obj); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2609 | } else { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2610 | __ Ldr(temp, HeapOperand(obj, class_offset)); | 
|  | 2611 | GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
| Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 2612 | } | 
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 2613 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2614 | switch (instruction->GetTypeCheckKind()) { | 
|  | 2615 | case TypeCheckKind::kExactCheck: | 
|  | 2616 | case TypeCheckKind::kArrayCheck: { | 
|  | 2617 | __ Cmp(temp, cls); | 
|  | 2618 | // Jump to slow path for throwing the exception or doing a | 
|  | 2619 | // more involved array check. | 
|  | 2620 | __ B(ne, slow_path->GetEntryLabel()); | 
|  | 2621 | break; | 
|  | 2622 | } | 
|  | 2623 | case TypeCheckKind::kAbstractClassCheck: { | 
|  | 2624 | // If the class is abstract, we eagerly fetch the super class of the | 
|  | 2625 | // object to avoid doing a comparison we know will fail. | 
|  | 2626 | vixl::Label loop; | 
|  | 2627 | __ Bind(&loop); | 
|  | 2628 | __ Ldr(temp, HeapOperand(temp, super_offset)); | 
|  | 2629 | GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
|  | 2630 | // Jump to the slow path to throw the exception. | 
|  | 2631 | __ Cbz(temp, slow_path->GetEntryLabel()); | 
|  | 2632 | __ Cmp(temp, cls); | 
|  | 2633 | __ B(ne, &loop); | 
|  | 2634 | break; | 
|  | 2635 | } | 
|  | 2636 | case TypeCheckKind::kClassHierarchyCheck: { | 
|  | 2637 | // Walk over the class hierarchy to find a match. | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2638 | vixl::Label loop; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2639 | __ Bind(&loop); | 
|  | 2640 | __ Cmp(temp, cls); | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2641 | __ B(eq, &done); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2642 | __ Ldr(temp, HeapOperand(temp, super_offset)); | 
|  | 2643 | GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
|  | 2644 | __ Cbnz(temp, &loop); | 
|  | 2645 | // Jump to the slow path to throw the exception. | 
|  | 2646 | __ B(slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2647 | break; | 
|  | 2648 | } | 
|  | 2649 | case TypeCheckKind::kArrayObjectCheck: { | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2650 | // Do an exact check. | 
|  | 2651 | __ Cmp(temp, cls); | 
|  | 2652 | __ B(eq, &done); | 
|  | 2653 | // Otherwise, we need to check that the object's class is a non primitive array. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2654 | __ Ldr(temp, HeapOperand(temp, component_offset)); | 
|  | 2655 | GetAssembler()->MaybeUnpoisonHeapReference(temp); | 
|  | 2656 | __ Cbz(temp, slow_path->GetEntryLabel()); | 
|  | 2657 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); | 
|  | 2658 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); | 
|  | 2659 | __ Cbnz(temp, slow_path->GetEntryLabel()); | 
|  | 2660 | break; | 
|  | 2661 | } | 
|  | 2662 | case TypeCheckKind::kInterfaceCheck: | 
|  | 2663 | default: | 
|  | 2664 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), | 
|  | 2665 | instruction, | 
|  | 2666 | instruction->GetDexPc(), | 
|  | 2667 | nullptr); | 
|  | 2668 | break; | 
|  | 2669 | } | 
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 2670 | __ Bind(&done); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2671 |  | 
|  | 2672 | if (slow_path != nullptr) { | 
|  | 2673 | __ Bind(slow_path->GetExitLabel()); | 
|  | 2674 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2675 | } | 
|  | 2676 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2677 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { | 
|  | 2678 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 2679 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2680 | } | 
|  | 2681 |  | 
|  | 2682 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) { | 
|  | 2683 | // Will be generated at use site. | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2684 | UNUSED(constant); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2685 | } | 
|  | 2686 |  | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2687 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { | 
|  | 2688 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 2689 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2690 | } | 
|  | 2691 |  | 
|  | 2692 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) { | 
|  | 2693 | // Will be generated at use site. | 
|  | 2694 | UNUSED(constant); | 
|  | 2695 | } | 
|  | 2696 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2697 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 2698 | // The trampoline uses the same calling convention as dex calling conventions, | 
|  | 2699 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain | 
|  | 2700 | // the method_idx. | 
|  | 2701 | HandleInvoke(invoke); | 
|  | 2702 | } | 
|  | 2703 |  | 
|  | 2704 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 2705 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); | 
|  | 2706 | } | 
|  | 2707 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2708 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2709 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2710 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2711 | } | 
|  | 2712 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2713 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 2714 | HandleInvoke(invoke); | 
|  | 2715 | } | 
|  | 2716 |  | 
|  | 2717 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 2718 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2719 | Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0)); | 
|  | 2720 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( | 
|  | 2721 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value(); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2722 | Location receiver = invoke->GetLocations()->InAt(0); | 
|  | 2723 | Offset class_offset = mirror::Object::ClassOffset(); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2724 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2725 |  | 
|  | 2726 | // The register ip1 is required to be used for the hidden argument in | 
|  | 2727 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2728 | MacroAssembler* masm = GetVIXLAssembler(); | 
|  | 2729 | UseScratchRegisterScope scratch_scope(masm); | 
|  | 2730 | BlockPoolsScope block_pools(masm); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2731 | scratch_scope.Exclude(ip1); | 
|  | 2732 | __ Mov(ip1, invoke->GetDexMethodIndex()); | 
|  | 2733 |  | 
|  | 2734 | // temp = object->GetClass(); | 
|  | 2735 | if (receiver.IsStackSlot()) { | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2736 | __ Ldr(temp.W(), StackOperandFrom(receiver)); | 
|  | 2737 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2738 | } else { | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2739 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2740 | } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2741 | codegen_->MaybeRecordImplicitNullCheck(invoke); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2742 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2743 | // temp = temp->GetImtEntryAt(method_offset); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2744 | __ Ldr(temp, MemOperand(temp, method_offset)); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2745 | // lr = temp->GetEntryPoint(); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2746 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2747 | // lr(); | 
|  | 2748 | __ Blr(lr); | 
|  | 2749 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 2750 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 2751 | } | 
|  | 2752 |  | 
|  | 2753 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2754 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); | 
|  | 2755 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 2756 | return; | 
|  | 2757 | } | 
|  | 2758 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2759 | HandleInvoke(invoke); | 
|  | 2760 | } | 
|  | 2761 |  | 
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2762 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2763 | // When we do not run baseline, explicit clinit checks triggered by static | 
|  | 2764 | // invokes must have been pruned by art::PrepareForRegisterAllocation. | 
|  | 2765 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); | 
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2766 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2767 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); | 
|  | 2768 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 2769 | return; | 
|  | 2770 | } | 
|  | 2771 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2772 | HandleInvoke(invoke); | 
|  | 2773 | } | 
|  | 2774 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2775 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { | 
|  | 2776 | if (invoke->GetLocations()->Intrinsified()) { | 
|  | 2777 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); | 
|  | 2778 | intrinsic.Dispatch(invoke); | 
|  | 2779 | return true; | 
|  | 2780 | } | 
|  | 2781 | return false; | 
|  | 2782 | } | 
|  | 2783 |  | 
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2784 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2785 | // For better instruction scheduling we load the direct code pointer before the method pointer. | 
|  | 2786 | bool direct_code_loaded = false; | 
|  | 2787 | switch (invoke->GetCodePtrLocation()) { | 
|  | 2788 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
|  | 2789 | // LR = code address from literal pool with link-time patch. | 
|  | 2790 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); | 
|  | 2791 | direct_code_loaded = true; | 
|  | 2792 | break; | 
|  | 2793 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: | 
|  | 2794 | // LR = invoke->GetDirectCodePtr(); | 
|  | 2795 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); | 
|  | 2796 | direct_code_loaded = true; | 
|  | 2797 | break; | 
|  | 2798 | default: | 
|  | 2799 | break; | 
|  | 2800 | } | 
|  | 2801 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2802 | // 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] | 2803 | Location callee_method = temp;  // For all kinds except kRecursive, callee will be in temp. | 
|  | 2804 | switch (invoke->GetMethodLoadKind()) { | 
|  | 2805 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: | 
|  | 2806 | // temp = thread->string_init_entrypoint | 
|  | 2807 | __ Ldr(XRegisterFrom(temp).X(), MemOperand(tr, invoke->GetStringInitOffset())); | 
|  | 2808 | break; | 
|  | 2809 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: | 
|  | 2810 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); | 
|  | 2811 | break; | 
|  | 2812 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: | 
|  | 2813 | // Load method address from literal pool. | 
|  | 2814 | __ Ldr(XRegisterFrom(temp).X(), DeduplicateUint64Literal(invoke->GetMethodAddress())); | 
|  | 2815 | break; | 
|  | 2816 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: | 
|  | 2817 | // Load method address from literal pool with a link-time patch. | 
|  | 2818 | __ Ldr(XRegisterFrom(temp).X(), | 
|  | 2819 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); | 
|  | 2820 | break; | 
|  | 2821 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { | 
|  | 2822 | // Add ADRP with its PC-relative DexCache access patch. | 
|  | 2823 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, | 
|  | 2824 | invoke->GetDexCacheArrayOffset()); | 
|  | 2825 | vixl::Label* pc_insn_label = &pc_rel_dex_cache_patches_.back().label; | 
|  | 2826 | { | 
|  | 2827 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); | 
|  | 2828 | __ adrp(XRegisterFrom(temp).X(), 0); | 
|  | 2829 | } | 
|  | 2830 | __ Bind(pc_insn_label);  // Bind after ADRP. | 
|  | 2831 | pc_rel_dex_cache_patches_.back().pc_insn_label = pc_insn_label; | 
|  | 2832 | // Add LDR with its PC-relative DexCache access patch. | 
|  | 2833 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, | 
|  | 2834 | invoke->GetDexCacheArrayOffset()); | 
|  | 2835 | __ Ldr(XRegisterFrom(temp).X(), MemOperand(XRegisterFrom(temp).X(), 0)); | 
|  | 2836 | __ Bind(&pc_rel_dex_cache_patches_.back().label);  // Bind after LDR. | 
|  | 2837 | pc_rel_dex_cache_patches_.back().pc_insn_label = pc_insn_label; | 
|  | 2838 | break; | 
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 2839 | } | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2840 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { | 
|  | 2841 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); | 
|  | 2842 | Register reg = XRegisterFrom(temp); | 
|  | 2843 | Register method_reg; | 
|  | 2844 | if (current_method.IsRegister()) { | 
|  | 2845 | method_reg = XRegisterFrom(current_method); | 
|  | 2846 | } else { | 
|  | 2847 | DCHECK(invoke->GetLocations()->Intrinsified()); | 
|  | 2848 | DCHECK(!current_method.IsValid()); | 
|  | 2849 | method_reg = reg; | 
|  | 2850 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); | 
|  | 2851 | } | 
| Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 2852 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2853 | // temp = current_method->dex_cache_resolved_methods_; | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2854 | __ Ldr(reg.X(), | 
|  | 2855 | MemOperand(method_reg.X(), | 
|  | 2856 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64WordSize).Int32Value())); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2857 | // temp = temp[index_in_cache]; | 
|  | 2858 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; | 
|  | 2859 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); | 
|  | 2860 | break; | 
|  | 2861 | } | 
|  | 2862 | } | 
|  | 2863 |  | 
|  | 2864 | switch (invoke->GetCodePtrLocation()) { | 
|  | 2865 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: | 
|  | 2866 | __ Bl(&frame_entry_label_); | 
|  | 2867 | break; | 
|  | 2868 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { | 
|  | 2869 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); | 
|  | 2870 | vixl::Label* label = &relative_call_patches_.back().label; | 
|  | 2871 | __ Bl(label);  // Arbitrarily branch to the instruction after BL, override at link time. | 
|  | 2872 | __ Bind(label);  // Bind after BL. | 
|  | 2873 | break; | 
|  | 2874 | } | 
|  | 2875 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
|  | 2876 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: | 
|  | 2877 | // LR prepared above for better instruction scheduling. | 
|  | 2878 | DCHECK(direct_code_loaded); | 
|  | 2879 | // lr() | 
|  | 2880 | __ Blr(lr); | 
|  | 2881 | break; | 
|  | 2882 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: | 
|  | 2883 | // LR = callee_method->entry_point_from_quick_compiled_code_; | 
|  | 2884 | __ Ldr(lr, MemOperand( | 
|  | 2885 | XRegisterFrom(callee_method).X(), | 
|  | 2886 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value())); | 
|  | 2887 | // lr() | 
|  | 2888 | __ Blr(lr); | 
|  | 2889 | break; | 
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2890 | } | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2891 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2892 | DCHECK(!IsLeafMethod()); | 
|  | 2893 | } | 
|  | 2894 |  | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2895 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { | 
|  | 2896 | LocationSummary* locations = invoke->GetLocations(); | 
|  | 2897 | Location receiver = locations->InAt(0); | 
|  | 2898 | Register temp = XRegisterFrom(temp_in); | 
|  | 2899 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
|  | 2900 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); | 
|  | 2901 | Offset class_offset = mirror::Object::ClassOffset(); | 
|  | 2902 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); | 
|  | 2903 |  | 
|  | 2904 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
|  | 2905 |  | 
|  | 2906 | DCHECK(receiver.IsRegister()); | 
|  | 2907 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); | 
|  | 2908 | MaybeRecordImplicitNullCheck(invoke); | 
|  | 2909 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); | 
|  | 2910 | // temp = temp->GetMethodAt(method_offset); | 
|  | 2911 | __ Ldr(temp, MemOperand(temp, method_offset)); | 
|  | 2912 | // lr = temp->GetEntryPoint(); | 
|  | 2913 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); | 
|  | 2914 | // lr(); | 
|  | 2915 | __ Blr(lr); | 
|  | 2916 | } | 
|  | 2917 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2918 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { | 
|  | 2919 | DCHECK(linker_patches->empty()); | 
|  | 2920 | size_t size = | 
|  | 2921 | method_patches_.size() + | 
|  | 2922 | call_patches_.size() + | 
|  | 2923 | relative_call_patches_.size() + | 
|  | 2924 | pc_rel_dex_cache_patches_.size(); | 
|  | 2925 | linker_patches->reserve(size); | 
|  | 2926 | for (const auto& entry : method_patches_) { | 
|  | 2927 | const MethodReference& target_method = entry.first; | 
|  | 2928 | vixl::Literal<uint64_t>* literal = entry.second; | 
|  | 2929 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->offset(), | 
|  | 2930 | target_method.dex_file, | 
|  | 2931 | target_method.dex_method_index)); | 
|  | 2932 | } | 
|  | 2933 | for (const auto& entry : call_patches_) { | 
|  | 2934 | const MethodReference& target_method = entry.first; | 
|  | 2935 | vixl::Literal<uint64_t>* literal = entry.second; | 
|  | 2936 | linker_patches->push_back(LinkerPatch::CodePatch(literal->offset(), | 
|  | 2937 | target_method.dex_file, | 
|  | 2938 | target_method.dex_method_index)); | 
|  | 2939 | } | 
|  | 2940 | for (const MethodPatchInfo<vixl::Label>& info : relative_call_patches_) { | 
|  | 2941 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.location() - 4u, | 
|  | 2942 | info.target_method.dex_file, | 
|  | 2943 | info.target_method.dex_method_index)); | 
|  | 2944 | } | 
|  | 2945 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { | 
|  | 2946 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.location() - 4u, | 
|  | 2947 | &info.target_dex_file, | 
|  | 2948 | info.pc_insn_label->location() - 4u, | 
|  | 2949 | info.element_offset)); | 
|  | 2950 | } | 
|  | 2951 | } | 
|  | 2952 |  | 
|  | 2953 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { | 
|  | 2954 | // Look up the literal for value. | 
|  | 2955 | auto lb = uint64_literals_.lower_bound(value); | 
|  | 2956 | if (lb != uint64_literals_.end() && !uint64_literals_.key_comp()(value, lb->first)) { | 
|  | 2957 | return lb->second; | 
|  | 2958 | } | 
|  | 2959 | // We don't have a literal for this value, insert a new one. | 
|  | 2960 | vixl::Literal<uint64_t>* literal = __ CreateLiteralDestroyedWithPool<uint64_t>(value); | 
|  | 2961 | uint64_literals_.PutBefore(lb, value, literal); | 
|  | 2962 | return literal; | 
|  | 2963 | } | 
|  | 2964 |  | 
|  | 2965 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( | 
|  | 2966 | MethodReference target_method, | 
|  | 2967 | MethodToLiteralMap* map) { | 
|  | 2968 | // Look up the literal for target_method. | 
|  | 2969 | auto lb = map->lower_bound(target_method); | 
|  | 2970 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { | 
|  | 2971 | return lb->second; | 
|  | 2972 | } | 
|  | 2973 | // We don't have a literal for this method yet, insert a new one. | 
|  | 2974 | vixl::Literal<uint64_t>* literal = __ CreateLiteralDestroyedWithPool<uint64_t>(0u); | 
|  | 2975 | map->PutBefore(lb, target_method, literal); | 
|  | 2976 | return literal; | 
|  | 2977 | } | 
|  | 2978 |  | 
|  | 2979 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( | 
|  | 2980 | MethodReference target_method) { | 
|  | 2981 | return DeduplicateMethodLiteral(target_method, &method_patches_); | 
|  | 2982 | } | 
|  | 2983 |  | 
|  | 2984 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( | 
|  | 2985 | MethodReference target_method) { | 
|  | 2986 | return DeduplicateMethodLiteral(target_method, &call_patches_); | 
|  | 2987 | } | 
|  | 2988 |  | 
|  | 2989 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2990 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2991 | // When we do not run baseline, explicit clinit checks triggered by static | 
|  | 2992 | // invokes must have been pruned by art::PrepareForRegisterAllocation. | 
|  | 2993 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); | 
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2994 |  | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2995 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 2996 | return; | 
|  | 2997 | } | 
|  | 2998 |  | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2999 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3000 | LocationSummary* locations = invoke->GetLocations(); | 
|  | 3001 | codegen_->GenerateStaticOrDirectCall( | 
|  | 3002 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3003 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3004 | } | 
|  | 3005 |  | 
|  | 3006 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3007 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 3008 | return; | 
|  | 3009 | } | 
|  | 3010 |  | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3011 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3012 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 3013 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 3014 | } | 
|  | 3015 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3016 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { | 
|  | 3017 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath | 
|  | 3018 | : LocationSummary::kNoCall; | 
|  | 3019 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3020 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3021 | locations->SetOut(Location::RequiresRegister()); | 
|  | 3022 | } | 
|  | 3023 |  | 
|  | 3024 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { | 
|  | 3025 | Register out = OutputRegister(cls); | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3026 | Register current_method = InputRegisterAt(cls, 0); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3027 | if (cls->IsReferrersClass()) { | 
|  | 3028 | DCHECK(!cls->CanCallRuntime()); | 
|  | 3029 | DCHECK(!cls->MustGenerateClinitCheck()); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3030 | __ Ldr(out, MemOperand(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3031 | } else { | 
|  | 3032 | DCHECK(cls->CanCallRuntime()); | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3033 | MemberOffset resolved_types_offset = ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); | 
|  | 3034 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); | 
|  | 3035 | __ Ldr(out, MemOperand(out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); | 
|  | 3036 | // TODO: We will need a read barrier here. | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3037 |  | 
|  | 3038 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( | 
|  | 3039 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); | 
|  | 3040 | codegen_->AddSlowPath(slow_path); | 
|  | 3041 | __ Cbz(out, slow_path->GetEntryLabel()); | 
|  | 3042 | if (cls->MustGenerateClinitCheck()) { | 
|  | 3043 | GenerateClassInitializationCheck(slow_path, out); | 
|  | 3044 | } else { | 
|  | 3045 | __ Bind(slow_path->GetExitLabel()); | 
|  | 3046 | } | 
|  | 3047 | } | 
|  | 3048 | } | 
|  | 3049 |  | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3050 | static MemOperand GetExceptionTlsAddress() { | 
|  | 3051 | return MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); | 
|  | 3052 | } | 
|  | 3053 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3054 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { | 
|  | 3055 | LocationSummary* locations = | 
|  | 3056 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); | 
|  | 3057 | locations->SetOut(Location::RequiresRegister()); | 
|  | 3058 | } | 
|  | 3059 |  | 
|  | 3060 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3061 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); | 
|  | 3062 | } | 
|  | 3063 |  | 
|  | 3064 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { | 
|  | 3065 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); | 
|  | 3066 | } | 
|  | 3067 |  | 
|  | 3068 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { | 
|  | 3069 | __ Str(wzr, GetExceptionTlsAddress()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3070 | } | 
|  | 3071 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3072 | void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) { | 
|  | 3073 | load->SetLocations(nullptr); | 
|  | 3074 | } | 
|  | 3075 |  | 
|  | 3076 | void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) { | 
|  | 3077 | // Nothing to do, this is driven by the code generator. | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3078 | UNUSED(load); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3079 | } | 
|  | 3080 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3081 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { | 
|  | 3082 | LocationSummary* locations = | 
|  | 3083 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); | 
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 3084 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3085 | locations->SetOut(Location::RequiresRegister()); | 
|  | 3086 | } | 
|  | 3087 |  | 
|  | 3088 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { | 
|  | 3089 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); | 
|  | 3090 | codegen_->AddSlowPath(slow_path); | 
|  | 3091 |  | 
|  | 3092 | Register out = OutputRegister(load); | 
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 3093 | Register current_method = InputRegisterAt(load, 0); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3094 | __ Ldr(out, MemOperand(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3095 | __ Ldr(out.X(), HeapOperand(out, mirror::Class::DexCacheStringsOffset())); | 
|  | 3096 | __ Ldr(out, MemOperand(out.X(), CodeGenerator::GetCacheOffset(load->GetStringIndex()))); | 
|  | 3097 | // TODO: We will need a read barrier here. | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3098 | __ Cbz(out, slow_path->GetEntryLabel()); | 
|  | 3099 | __ Bind(slow_path->GetExitLabel()); | 
|  | 3100 | } | 
|  | 3101 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3102 | void LocationsBuilderARM64::VisitLocal(HLocal* local) { | 
|  | 3103 | local->SetLocations(nullptr); | 
|  | 3104 | } | 
|  | 3105 |  | 
|  | 3106 | void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) { | 
|  | 3107 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); | 
|  | 3108 | } | 
|  | 3109 |  | 
|  | 3110 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { | 
|  | 3111 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); | 
|  | 3112 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 3113 | } | 
|  | 3114 |  | 
|  | 3115 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) { | 
|  | 3116 | // Will be generated at use site. | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3117 | UNUSED(constant); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3118 | } | 
|  | 3119 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3120 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { | 
|  | 3121 | LocationSummary* locations = | 
|  | 3122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 3123 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3124 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); | 
|  | 3125 | } | 
|  | 3126 |  | 
|  | 3127 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { | 
|  | 3128 | codegen_->InvokeRuntime(instruction->IsEnter() | 
|  | 3129 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), | 
|  | 3130 | instruction, | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3131 | instruction->GetDexPc(), | 
|  | 3132 | nullptr); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3133 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3134 | } | 
|  | 3135 |  | 
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3136 | void LocationsBuilderARM64::VisitMul(HMul* mul) { | 
|  | 3137 | LocationSummary* locations = | 
|  | 3138 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); | 
|  | 3139 | switch (mul->GetResultType()) { | 
|  | 3140 | case Primitive::kPrimInt: | 
|  | 3141 | case Primitive::kPrimLong: | 
|  | 3142 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3143 | locations->SetInAt(1, Location::RequiresRegister()); | 
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3144 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3145 | break; | 
|  | 3146 |  | 
|  | 3147 | case Primitive::kPrimFloat: | 
|  | 3148 | case Primitive::kPrimDouble: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3149 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3150 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3151 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3152 | break; | 
|  | 3153 |  | 
|  | 3154 | default: | 
|  | 3155 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
|  | 3156 | } | 
|  | 3157 | } | 
|  | 3158 |  | 
|  | 3159 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { | 
|  | 3160 | switch (mul->GetResultType()) { | 
|  | 3161 | case Primitive::kPrimInt: | 
|  | 3162 | case Primitive::kPrimLong: | 
|  | 3163 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); | 
|  | 3164 | break; | 
|  | 3165 |  | 
|  | 3166 | case Primitive::kPrimFloat: | 
|  | 3167 | case Primitive::kPrimDouble: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3168 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); | 
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3169 | break; | 
|  | 3170 |  | 
|  | 3171 | default: | 
|  | 3172 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
|  | 3173 | } | 
|  | 3174 | } | 
|  | 3175 |  | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3176 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { | 
|  | 3177 | LocationSummary* locations = | 
|  | 3178 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); | 
|  | 3179 | switch (neg->GetResultType()) { | 
|  | 3180 | case Primitive::kPrimInt: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3181 | case Primitive::kPrimLong: | 
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3182 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3183 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3184 | break; | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3185 |  | 
|  | 3186 | case Primitive::kPrimFloat: | 
|  | 3187 | case Primitive::kPrimDouble: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3188 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3189 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3190 | break; | 
|  | 3191 |  | 
|  | 3192 | default: | 
|  | 3193 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
|  | 3194 | } | 
|  | 3195 | } | 
|  | 3196 |  | 
|  | 3197 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { | 
|  | 3198 | switch (neg->GetResultType()) { | 
|  | 3199 | case Primitive::kPrimInt: | 
|  | 3200 | case Primitive::kPrimLong: | 
|  | 3201 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); | 
|  | 3202 | break; | 
|  | 3203 |  | 
|  | 3204 | case Primitive::kPrimFloat: | 
|  | 3205 | case Primitive::kPrimDouble: | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3206 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3207 | break; | 
|  | 3208 |  | 
|  | 3209 | default: | 
|  | 3210 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
|  | 3211 | } | 
|  | 3212 | } | 
|  | 3213 |  | 
|  | 3214 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { | 
|  | 3215 | LocationSummary* locations = | 
|  | 3216 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 3217 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3218 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3219 | locations->SetOut(LocationFrom(x0)); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3220 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); | 
| Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3221 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3222 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3223 | void*, uint32_t, int32_t, ArtMethod*>(); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3224 | } | 
|  | 3225 |  | 
|  | 3226 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { | 
|  | 3227 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3228 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3229 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); | 
|  | 3230 | DCHECK(type_index.Is(w0)); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3231 | __ Mov(type_index, instruction->GetTypeIndex()); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3232 | // Note: if heap poisoning is enabled, the entry point takes cares | 
|  | 3233 | // of poisoning the reference. | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3234 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), | 
|  | 3235 | instruction, | 
|  | 3236 | instruction->GetDexPc(), | 
|  | 3237 | nullptr); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3238 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); | 
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3239 | } | 
|  | 3240 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3241 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { | 
|  | 3242 | LocationSummary* locations = | 
|  | 3243 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 3244 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3245 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); | 
| Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3246 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3247 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3248 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3249 | } | 
|  | 3250 |  | 
|  | 3251 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { | 
|  | 3252 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3253 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); | 
|  | 3254 | DCHECK(type_index.Is(w0)); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3255 | __ Mov(type_index, instruction->GetTypeIndex()); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3256 | // Note: if heap poisoning is enabled, the entry point takes cares | 
|  | 3257 | // of poisoning the reference. | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3258 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), | 
|  | 3259 | instruction, | 
|  | 3260 | instruction->GetDexPc(), | 
|  | 3261 | nullptr); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3262 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3263 | } | 
|  | 3264 |  | 
|  | 3265 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { | 
|  | 3266 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
| Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 3267 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3268 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3269 | } | 
|  | 3270 |  | 
|  | 3271 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { | 
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3272 | switch (instruction->GetResultType()) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3273 | case Primitive::kPrimInt: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3274 | case Primitive::kPrimLong: | 
| Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 3275 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3276 | break; | 
|  | 3277 |  | 
|  | 3278 | default: | 
|  | 3279 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); | 
|  | 3280 | } | 
|  | 3281 | } | 
|  | 3282 |  | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3283 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { | 
|  | 3284 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3285 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3286 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3287 | } | 
|  | 3288 |  | 
|  | 3289 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3290 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1)); | 
|  | 3291 | } | 
|  | 3292 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3293 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3294 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
|  | 3295 | ? LocationSummary::kCallOnSlowPath | 
|  | 3296 | : LocationSummary::kNoCall; | 
|  | 3297 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3298 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3299 | if (instruction->HasUses()) { | 
|  | 3300 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3301 | } | 
|  | 3302 | } | 
|  | 3303 |  | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3304 | void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3305 | if (codegen_->CanMoveNullCheckToUser(instruction)) { | 
|  | 3306 | return; | 
|  | 3307 | } | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3308 |  | 
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3309 | BlockPoolsScope block_pools(GetVIXLAssembler()); | 
|  | 3310 | Location obj = instruction->GetLocations()->InAt(0); | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3311 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); | 
|  | 3312 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
|  | 3313 | } | 
|  | 3314 |  | 
|  | 3315 | void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3316 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); | 
|  | 3317 | codegen_->AddSlowPath(slow_path); | 
|  | 3318 |  | 
|  | 3319 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3320 | Location obj = locations->InAt(0); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3321 |  | 
|  | 3322 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3323 | } | 
|  | 3324 |  | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3325 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3326 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3327 | GenerateImplicitNullCheck(instruction); | 
|  | 3328 | } else { | 
|  | 3329 | GenerateExplicitNullCheck(instruction); | 
|  | 3330 | } | 
|  | 3331 | } | 
|  | 3332 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3333 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { | 
|  | 3334 | HandleBinaryOp(instruction); | 
|  | 3335 | } | 
|  | 3336 |  | 
|  | 3337 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { | 
|  | 3338 | HandleBinaryOp(instruction); | 
|  | 3339 | } | 
|  | 3340 |  | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3341 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { | 
|  | 3342 | LOG(FATAL) << "Unreachable"; | 
|  | 3343 | } | 
|  | 3344 |  | 
|  | 3345 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { | 
|  | 3346 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); | 
|  | 3347 | } | 
|  | 3348 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3349 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { | 
|  | 3350 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3351 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); | 
|  | 3352 | if (location.IsStackSlot()) { | 
|  | 3353 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 3354 | } else if (location.IsDoubleStackSlot()) { | 
|  | 3355 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 3356 | } | 
|  | 3357 | locations->SetOut(location); | 
|  | 3358 | } | 
|  | 3359 |  | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3360 | void InstructionCodeGeneratorARM64::VisitParameterValue( | 
|  | 3361 | HParameterValue* instruction ATTRIBUTE_UNUSED) { | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3362 | // Nothing to do, the parameter is already at its location. | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3363 | } | 
|  | 3364 |  | 
|  | 3365 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { | 
|  | 3366 | LocationSummary* locations = | 
|  | 3367 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3368 | locations->SetOut(LocationFrom(kArtMethodRegister)); | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3369 | } | 
|  | 3370 |  | 
|  | 3371 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( | 
|  | 3372 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { | 
|  | 3373 | // Nothing to do, the method is already at its location. | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3374 | } | 
|  | 3375 |  | 
|  | 3376 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { | 
|  | 3377 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3378 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { | 
|  | 3379 | locations->SetInAt(i, Location::Any()); | 
|  | 3380 | } | 
|  | 3381 | locations->SetOut(Location::Any()); | 
|  | 3382 | } | 
|  | 3383 |  | 
|  | 3384 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) { | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3385 | UNUSED(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3386 | LOG(FATAL) << "Unreachable"; | 
|  | 3387 | } | 
|  | 3388 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3389 | void LocationsBuilderARM64::VisitRem(HRem* rem) { | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3390 | Primitive::Type type = rem->GetResultType(); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3391 | LocationSummary::CallKind call_kind = | 
|  | 3392 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3393 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); | 
|  | 3394 |  | 
|  | 3395 | switch (type) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3396 | case Primitive::kPrimInt: | 
|  | 3397 | case Primitive::kPrimLong: | 
|  | 3398 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3399 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3400 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3401 | break; | 
|  | 3402 |  | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3403 | case Primitive::kPrimFloat: | 
|  | 3404 | case Primitive::kPrimDouble: { | 
|  | 3405 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3406 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); | 
|  | 3407 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); | 
|  | 3408 | locations->SetOut(calling_convention.GetReturnLocation(type)); | 
|  | 3409 |  | 
|  | 3410 | break; | 
|  | 3411 | } | 
|  | 3412 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3413 | default: | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3414 | LOG(FATAL) << "Unexpected rem type " << type; | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3415 | } | 
|  | 3416 | } | 
|  | 3417 |  | 
|  | 3418 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { | 
|  | 3419 | Primitive::Type type = rem->GetResultType(); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3420 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3421 | switch (type) { | 
|  | 3422 | case Primitive::kPrimInt: | 
|  | 3423 | case Primitive::kPrimLong: { | 
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3424 | GenerateDivRemIntegral(rem); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3425 | break; | 
|  | 3426 | } | 
|  | 3427 |  | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3428 | case Primitive::kPrimFloat: | 
|  | 3429 | case Primitive::kPrimDouble: { | 
|  | 3430 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) | 
|  | 3431 | : QUICK_ENTRY_POINT(pFmod); | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3432 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); | 
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3433 | break; | 
|  | 3434 | } | 
|  | 3435 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3436 | default: | 
|  | 3437 | LOG(FATAL) << "Unexpected rem type " << type; | 
|  | 3438 | } | 
|  | 3439 | } | 
|  | 3440 |  | 
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3441 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 3442 | memory_barrier->SetLocations(nullptr); | 
|  | 3443 | } | 
|  | 3444 |  | 
|  | 3445 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 3446 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); | 
|  | 3447 | } | 
|  | 3448 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3449 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { | 
|  | 3450 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
|  | 3451 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3452 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3453 | } | 
|  | 3454 |  | 
|  | 3455 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3456 | UNUSED(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3457 | codegen_->GenerateFrameExit(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3458 | } | 
|  | 3459 |  | 
|  | 3460 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { | 
|  | 3461 | instruction->SetLocations(nullptr); | 
|  | 3462 | } | 
|  | 3463 |  | 
|  | 3464 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) { | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3465 | UNUSED(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3466 | codegen_->GenerateFrameExit(); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3467 | } | 
|  | 3468 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3469 | void LocationsBuilderARM64::VisitShl(HShl* shl) { | 
|  | 3470 | HandleShift(shl); | 
|  | 3471 | } | 
|  | 3472 |  | 
|  | 3473 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { | 
|  | 3474 | HandleShift(shl); | 
|  | 3475 | } | 
|  | 3476 |  | 
|  | 3477 | void LocationsBuilderARM64::VisitShr(HShr* shr) { | 
|  | 3478 | HandleShift(shr); | 
|  | 3479 | } | 
|  | 3480 |  | 
|  | 3481 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { | 
|  | 3482 | HandleShift(shr); | 
|  | 3483 | } | 
|  | 3484 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3485 | void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) { | 
|  | 3486 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); | 
|  | 3487 | Primitive::Type field_type = store->InputAt(1)->GetType(); | 
|  | 3488 | switch (field_type) { | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3489 | case Primitive::kPrimNot: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3490 | case Primitive::kPrimBoolean: | 
|  | 3491 | case Primitive::kPrimByte: | 
|  | 3492 | case Primitive::kPrimChar: | 
|  | 3493 | case Primitive::kPrimShort: | 
|  | 3494 | case Primitive::kPrimInt: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3495 | case Primitive::kPrimFloat: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3496 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); | 
|  | 3497 | break; | 
|  | 3498 |  | 
|  | 3499 | case Primitive::kPrimLong: | 
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3500 | case Primitive::kPrimDouble: | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3501 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); | 
|  | 3502 | break; | 
|  | 3503 |  | 
|  | 3504 | default: | 
|  | 3505 | LOG(FATAL) << "Unimplemented local type " << field_type; | 
|  | 3506 | } | 
|  | 3507 | } | 
|  | 3508 |  | 
|  | 3509 | void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) { | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3510 | UNUSED(store); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3511 | } | 
|  | 3512 |  | 
|  | 3513 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3514 | HandleBinaryOp(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3515 | } | 
|  | 3516 |  | 
|  | 3517 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3518 | HandleBinaryOp(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3519 | } | 
|  | 3520 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3521 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3522 | HandleFieldGet(instruction); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3523 | } | 
|  | 3524 |  | 
|  | 3525 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3526 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3527 | } | 
|  | 3528 |  | 
|  | 3529 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3530 | HandleFieldSet(instruction); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3531 | } | 
|  | 3532 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3533 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3534 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3535 | } | 
|  | 3536 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 3537 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( | 
|  | 3538 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 3539 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3540 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3541 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3542 | } | 
|  | 3543 |  | 
|  | 3544 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( | 
|  | 3545 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 3546 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3547 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3548 | instruction->GetFieldType(), | 
|  | 3549 | instruction->GetFieldIndex(), | 
|  | 3550 | instruction->GetDexPc(), | 
|  | 3551 | calling_convention); | 
|  | 3552 | } | 
|  | 3553 |  | 
|  | 3554 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( | 
|  | 3555 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 3556 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3557 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3558 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3559 | } | 
|  | 3560 |  | 
|  | 3561 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( | 
|  | 3562 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 3563 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3564 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3565 | instruction->GetFieldType(), | 
|  | 3566 | instruction->GetFieldIndex(), | 
|  | 3567 | instruction->GetDexPc(), | 
|  | 3568 | calling_convention); | 
|  | 3569 | } | 
|  | 3570 |  | 
|  | 3571 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( | 
|  | 3572 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 3573 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3574 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3575 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3576 | } | 
|  | 3577 |  | 
|  | 3578 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( | 
|  | 3579 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 3580 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3581 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3582 | instruction->GetFieldType(), | 
|  | 3583 | instruction->GetFieldIndex(), | 
|  | 3584 | instruction->GetDexPc(), | 
|  | 3585 | calling_convention); | 
|  | 3586 | } | 
|  | 3587 |  | 
|  | 3588 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( | 
|  | 3589 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 3590 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3591 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 3592 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 3593 | } | 
|  | 3594 |  | 
|  | 3595 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( | 
|  | 3596 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 3597 | FieldAccessCallingConventionARM64 calling_convention; | 
|  | 3598 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 3599 | instruction->GetFieldType(), | 
|  | 3600 | instruction->GetFieldIndex(), | 
|  | 3601 | instruction->GetDexPc(), | 
|  | 3602 | calling_convention); | 
|  | 3603 | } | 
|  | 3604 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3605 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { | 
|  | 3606 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); | 
|  | 3607 | } | 
|  | 3608 |  | 
|  | 3609 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3610 | HBasicBlock* block = instruction->GetBlock(); | 
|  | 3611 | if (block->GetLoopInformation() != nullptr) { | 
|  | 3612 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); | 
|  | 3613 | // The back edge will generate the suspend check. | 
|  | 3614 | return; | 
|  | 3615 | } | 
|  | 3616 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { | 
|  | 3617 | // The goto will generate the suspend check. | 
|  | 3618 | return; | 
|  | 3619 | } | 
|  | 3620 | GenerateSuspendCheck(instruction, nullptr); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3621 | } | 
|  | 3622 |  | 
|  | 3623 | void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) { | 
|  | 3624 | temp->SetLocations(nullptr); | 
|  | 3625 | } | 
|  | 3626 |  | 
|  | 3627 | void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) { | 
|  | 3628 | // Nothing to do, this is driven by the code generator. | 
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3629 | UNUSED(temp); | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3630 | } | 
|  | 3631 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3632 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { | 
|  | 3633 | LocationSummary* locations = | 
|  | 3634 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
|  | 3635 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3636 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); | 
|  | 3637 | } | 
|  | 3638 |  | 
|  | 3639 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { | 
|  | 3640 | codegen_->InvokeRuntime( | 
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3641 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3642 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3643 | } | 
|  | 3644 |  | 
|  | 3645 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 3646 | LocationSummary* locations = | 
|  | 3647 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); | 
|  | 3648 | Primitive::Type input_type = conversion->GetInputType(); | 
|  | 3649 | Primitive::Type result_type = conversion->GetResultType(); | 
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3650 | DCHECK_NE(input_type, result_type); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3651 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || | 
|  | 3652 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { | 
|  | 3653 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; | 
|  | 3654 | } | 
|  | 3655 |  | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3656 | if (Primitive::IsFloatingPointType(input_type)) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3657 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3658 | } else { | 
|  | 3659 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3660 | } | 
|  | 3661 |  | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3662 | if (Primitive::IsFloatingPointType(result_type)) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3663 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 3664 | } else { | 
|  | 3665 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3666 | } | 
|  | 3667 | } | 
|  | 3668 |  | 
|  | 3669 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 3670 | Primitive::Type result_type = conversion->GetResultType(); | 
|  | 3671 | Primitive::Type input_type = conversion->GetInputType(); | 
|  | 3672 |  | 
|  | 3673 | DCHECK_NE(input_type, result_type); | 
|  | 3674 |  | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3675 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3676 | int result_size = Primitive::ComponentSize(result_type); | 
|  | 3677 | int input_size = Primitive::ComponentSize(input_type); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3678 | int min_size = std::min(result_size, input_size); | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3679 | Register output = OutputRegister(conversion); | 
|  | 3680 | Register source = InputRegisterAt(conversion, 0); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3681 | if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) { | 
|  | 3682 | __ Ubfx(output, source, 0, result_size * kBitsPerByte); | 
| Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 3683 | } else if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { | 
|  | 3684 | // 'int' values are used directly as W registers, discarding the top | 
|  | 3685 | // bits, so we don't need to sign-extend and can just perform a move. | 
|  | 3686 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the | 
|  | 3687 | // top 32 bits of the target register. We theoretically could leave those | 
|  | 3688 | // bits unchanged, but we would have to make sure that no code uses a | 
|  | 3689 | // 32bit input value as a 64bit value assuming that the top 32 bits are | 
|  | 3690 | // zero. | 
|  | 3691 | __ Mov(output.W(), source.W()); | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3692 | } else if ((result_type == Primitive::kPrimChar) || | 
|  | 3693 | ((input_type == Primitive::kPrimChar) && (result_size > input_size))) { | 
|  | 3694 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3695 | } else { | 
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3696 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3697 | } | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3698 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3699 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3700 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3701 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); | 
|  | 3702 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); | 
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3703 | } else if (Primitive::IsFloatingPointType(result_type) && | 
|  | 3704 | Primitive::IsFloatingPointType(input_type)) { | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3705 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); | 
|  | 3706 | } else { | 
|  | 3707 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type | 
|  | 3708 | << " to " << result_type; | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3709 | } | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3710 | } | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3711 |  | 
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3712 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { | 
|  | 3713 | HandleShift(ushr); | 
|  | 3714 | } | 
|  | 3715 |  | 
|  | 3716 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { | 
|  | 3717 | HandleShift(ushr); | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3718 | } | 
|  | 3719 |  | 
|  | 3720 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { | 
|  | 3721 | HandleBinaryOp(instruction); | 
|  | 3722 | } | 
|  | 3723 |  | 
|  | 3724 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { | 
|  | 3725 | HandleBinaryOp(instruction); | 
|  | 3726 | } | 
|  | 3727 |  | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3728 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) { | 
|  | 3729 | // Nothing to do, this should be removed during prepare for register allocator. | 
|  | 3730 | UNUSED(instruction); | 
|  | 3731 | LOG(FATAL) << "Unreachable"; | 
|  | 3732 | } | 
|  | 3733 |  | 
|  | 3734 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) { | 
|  | 3735 | // Nothing to do, this should be removed during prepare for register allocator. | 
|  | 3736 | UNUSED(instruction); | 
|  | 3737 | LOG(FATAL) << "Unreachable"; | 
|  | 3738 | } | 
|  | 3739 |  | 
| Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3740 | void LocationsBuilderARM64::VisitFakeString(HFakeString* instruction) { | 
|  | 3741 | DCHECK(codegen_->IsBaseline()); | 
|  | 3742 | LocationSummary* locations = | 
|  | 3743 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
|  | 3744 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); | 
|  | 3745 | } | 
|  | 3746 |  | 
|  | 3747 | void InstructionCodeGeneratorARM64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { | 
|  | 3748 | DCHECK(codegen_->IsBaseline()); | 
|  | 3749 | // Will be generated at use site. | 
|  | 3750 | } | 
|  | 3751 |  | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3752 | // Simple implementation of packed switch - generate cascaded compare/jumps. | 
|  | 3753 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 3754 | LocationSummary* locations = | 
|  | 3755 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
|  | 3756 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3757 | } | 
|  | 3758 |  | 
|  | 3759 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 3760 | int32_t lower_bound = switch_instr->GetStartValue(); | 
|  | 3761 | int32_t num_entries = switch_instr->GetNumEntries(); | 
|  | 3762 | Register value_reg = InputRegisterAt(switch_instr, 0); | 
|  | 3763 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); | 
|  | 3764 |  | 
|  | 3765 | // Create a series of compare/jumps. | 
|  | 3766 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); | 
|  | 3767 | for (int32_t i = 0; i < num_entries; i++) { | 
|  | 3768 | int32_t case_value = lower_bound + i; | 
|  | 3769 | vixl::Label* succ = codegen_->GetLabelOf(successors.at(i)); | 
|  | 3770 | if (case_value == 0) { | 
|  | 3771 | __ Cbz(value_reg, succ); | 
|  | 3772 | } else { | 
|  | 3773 | __ Cmp(value_reg, vixl::Operand(case_value)); | 
|  | 3774 | __ B(eq, succ); | 
|  | 3775 | } | 
|  | 3776 | } | 
|  | 3777 |  | 
|  | 3778 | // And the default for any other value. | 
|  | 3779 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { | 
|  | 3780 | __ B(codegen_->GetLabelOf(default_block)); | 
|  | 3781 | } | 
|  | 3782 | } | 
|  | 3783 |  | 
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3784 | #undef __ | 
|  | 3785 | #undef QUICK_ENTRY_POINT | 
|  | 3786 |  | 
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3787 | }  // namespace arm64 | 
|  | 3788 | }  // namespace art |