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