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