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