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