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