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 | |
| 19 | #include "entrypoints/quick/quick_entrypoints.h" |
| 20 | #include "gc/accounting/card_table.h" |
| 21 | #include "mirror/array-inl.h" |
| 22 | #include "mirror/art_method.h" |
| 23 | #include "mirror/class.h" |
| 24 | #include "thread.h" |
| 25 | #include "utils/arm64/assembler_arm64.h" |
| 26 | #include "utils/assembler.h" |
| 27 | #include "utils/stack_checks.h" |
| 28 | |
| 29 | |
| 30 | using namespace vixl; // NOLINT(build/namespaces) |
| 31 | |
| 32 | #ifdef __ |
| 33 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | namespace art { |
| 38 | |
| 39 | namespace arm64 { |
| 40 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 41 | // TODO: clean-up some of the constant definitions. |
| 42 | static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>); |
| 43 | static constexpr int kCurrentMethodStackOffset = 0; |
| 44 | |
| 45 | namespace { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 46 | |
| 47 | bool IsFPType(Primitive::Type type) { |
| 48 | return type == Primitive::kPrimFloat || type == Primitive::kPrimDouble; |
| 49 | } |
| 50 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 51 | bool IsIntegralType(Primitive::Type type) { |
| 52 | switch (type) { |
| 53 | case Primitive::kPrimByte: |
| 54 | case Primitive::kPrimChar: |
| 55 | case Primitive::kPrimShort: |
| 56 | case Primitive::kPrimInt: |
| 57 | case Primitive::kPrimLong: |
| 58 | return true; |
| 59 | default: |
| 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 64 | bool Is64BitType(Primitive::Type type) { |
| 65 | return type == Primitive::kPrimLong || type == Primitive::kPrimDouble; |
| 66 | } |
| 67 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 68 | // Convenience helpers to ease conversion to and from VIXL operands. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 69 | static_assert((SP == 31) && (WSP == 31) && (XZR == 32) && (WZR == 32), |
| 70 | "Unexpected values for register codes."); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 71 | |
| 72 | int VIXLRegCodeFromART(int code) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 73 | if (code == SP) { |
| 74 | return vixl::kSPRegInternalCode; |
| 75 | } |
| 76 | if (code == XZR) { |
| 77 | return vixl::kZeroRegCode; |
| 78 | } |
| 79 | return code; |
| 80 | } |
| 81 | |
| 82 | int ARTRegCodeFromVIXL(int code) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 83 | if (code == vixl::kSPRegInternalCode) { |
| 84 | return SP; |
| 85 | } |
| 86 | if (code == vixl::kZeroRegCode) { |
| 87 | return XZR; |
| 88 | } |
| 89 | return code; |
| 90 | } |
| 91 | |
| 92 | Register XRegisterFrom(Location location) { |
| 93 | return Register::XRegFromCode(VIXLRegCodeFromART(location.reg())); |
| 94 | } |
| 95 | |
| 96 | Register WRegisterFrom(Location location) { |
| 97 | return Register::WRegFromCode(VIXLRegCodeFromART(location.reg())); |
| 98 | } |
| 99 | |
| 100 | Register RegisterFrom(Location location, Primitive::Type type) { |
| 101 | DCHECK(type != Primitive::kPrimVoid && !IsFPType(type)); |
| 102 | return type == Primitive::kPrimLong ? XRegisterFrom(location) : WRegisterFrom(location); |
| 103 | } |
| 104 | |
| 105 | Register OutputRegister(HInstruction* instr) { |
| 106 | return RegisterFrom(instr->GetLocations()->Out(), instr->GetType()); |
| 107 | } |
| 108 | |
| 109 | Register InputRegisterAt(HInstruction* instr, int input_index) { |
| 110 | return RegisterFrom(instr->GetLocations()->InAt(input_index), |
| 111 | instr->InputAt(input_index)->GetType()); |
| 112 | } |
| 113 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 114 | FPRegister DRegisterFrom(Location location) { |
| 115 | return FPRegister::DRegFromCode(location.reg()); |
| 116 | } |
| 117 | |
| 118 | FPRegister SRegisterFrom(Location location) { |
| 119 | return FPRegister::SRegFromCode(location.reg()); |
| 120 | } |
| 121 | |
| 122 | FPRegister FPRegisterFrom(Location location, Primitive::Type type) { |
| 123 | DCHECK(IsFPType(type)); |
| 124 | return type == Primitive::kPrimDouble ? DRegisterFrom(location) : SRegisterFrom(location); |
| 125 | } |
| 126 | |
| 127 | FPRegister OutputFPRegister(HInstruction* instr) { |
| 128 | return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType()); |
| 129 | } |
| 130 | |
| 131 | FPRegister InputFPRegisterAt(HInstruction* instr, int input_index) { |
| 132 | return FPRegisterFrom(instr->GetLocations()->InAt(input_index), |
| 133 | instr->InputAt(input_index)->GetType()); |
| 134 | } |
| 135 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 136 | CPURegister OutputCPURegister(HInstruction* instr) { |
| 137 | return IsFPType(instr->GetType()) ? static_cast<CPURegister>(OutputFPRegister(instr)) |
| 138 | : static_cast<CPURegister>(OutputRegister(instr)); |
| 139 | } |
| 140 | |
| 141 | CPURegister InputCPURegisterAt(HInstruction* instr, int index) { |
| 142 | return IsFPType(instr->InputAt(index)->GetType()) |
| 143 | ? static_cast<CPURegister>(InputFPRegisterAt(instr, index)) |
| 144 | : static_cast<CPURegister>(InputRegisterAt(instr, index)); |
| 145 | } |
| 146 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 147 | int64_t Int64ConstantFrom(Location location) { |
| 148 | HConstant* instr = location.GetConstant(); |
| 149 | return instr->IsIntConstant() ? instr->AsIntConstant()->GetValue() |
| 150 | : instr->AsLongConstant()->GetValue(); |
| 151 | } |
| 152 | |
| 153 | Operand OperandFrom(Location location, Primitive::Type type) { |
| 154 | if (location.IsRegister()) { |
| 155 | return Operand(RegisterFrom(location, type)); |
| 156 | } else { |
| 157 | return Operand(Int64ConstantFrom(location)); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | Operand InputOperandAt(HInstruction* instr, int input_index) { |
| 162 | return OperandFrom(instr->GetLocations()->InAt(input_index), |
| 163 | instr->InputAt(input_index)->GetType()); |
| 164 | } |
| 165 | |
| 166 | MemOperand StackOperandFrom(Location location) { |
| 167 | return MemOperand(sp, location.GetStackIndex()); |
| 168 | } |
| 169 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 170 | MemOperand HeapOperand(const Register& base, size_t offset) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 171 | // A heap reference must be 32bit, so fit in a W register. |
| 172 | DCHECK(base.IsW()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 173 | return MemOperand(base.X(), offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 176 | MemOperand HeapOperand(const Register& base, Offset offset) { |
| 177 | return HeapOperand(base, offset.SizeValue()); |
| 178 | } |
| 179 | |
| 180 | MemOperand HeapOperandFrom(Location location, Offset offset) { |
| 181 | return HeapOperand(RegisterFrom(location, Primitive::kPrimNot), offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | Location LocationFrom(const Register& reg) { |
| 185 | return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.code())); |
| 186 | } |
| 187 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 188 | Location LocationFrom(const FPRegister& fpreg) { |
| 189 | return Location::FpuRegisterLocation(fpreg.code()); |
| 190 | } |
| 191 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 192 | } // namespace |
| 193 | |
| 194 | inline Condition ARM64Condition(IfCondition cond) { |
| 195 | switch (cond) { |
| 196 | case kCondEQ: return eq; |
| 197 | case kCondNE: return ne; |
| 198 | case kCondLT: return lt; |
| 199 | case kCondLE: return le; |
| 200 | case kCondGT: return gt; |
| 201 | case kCondGE: return ge; |
| 202 | default: |
| 203 | LOG(FATAL) << "Unknown if condition"; |
| 204 | } |
| 205 | return nv; // Unreachable. |
| 206 | } |
| 207 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 208 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
| 209 | DCHECK_NE(return_type, Primitive::kPrimVoid); |
| 210 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 211 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 212 | // but we use the exact registers for clarity. |
| 213 | if (return_type == Primitive::kPrimFloat) { |
| 214 | return LocationFrom(s0); |
| 215 | } else if (return_type == Primitive::kPrimDouble) { |
| 216 | return LocationFrom(d0); |
| 217 | } else if (return_type == Primitive::kPrimLong) { |
| 218 | return LocationFrom(x0); |
| 219 | } else { |
| 220 | return LocationFrom(w0); |
| 221 | } |
| 222 | } |
| 223 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 224 | static const Register kRuntimeParameterCoreRegisters[] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 225 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 226 | arraysize(kRuntimeParameterCoreRegisters); |
| 227 | static const FPRegister kRuntimeParameterFpuRegisters[] = { }; |
| 228 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
| 229 | |
| 230 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FPRegister> { |
| 231 | public: |
| 232 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 233 | |
| 234 | InvokeRuntimeCallingConvention() |
| 235 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 236 | kRuntimeParameterCoreRegistersLength, |
| 237 | kRuntimeParameterFpuRegisters, |
| 238 | kRuntimeParameterFpuRegistersLength) {} |
| 239 | |
| 240 | Location GetReturnLocation(Primitive::Type return_type); |
| 241 | |
| 242 | private: |
| 243 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 244 | }; |
| 245 | |
| 246 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 247 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 250 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> |
| 251 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | |
| 253 | class SlowPathCodeARM64 : public SlowPathCode { |
| 254 | public: |
| 255 | SlowPathCodeARM64() : entry_label_(), exit_label_() {} |
| 256 | |
| 257 | vixl::Label* GetEntryLabel() { return &entry_label_; } |
| 258 | vixl::Label* GetExitLabel() { return &exit_label_; } |
| 259 | |
| 260 | private: |
| 261 | vixl::Label entry_label_; |
| 262 | vixl::Label exit_label_; |
| 263 | |
| 264 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM64); |
| 265 | }; |
| 266 | |
| 267 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 268 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | BoundsCheckSlowPathARM64() {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 270 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 271 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 272 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 273 | __ Brk(__LINE__); // TODO: Unimplemented BoundsCheckSlowPathARM64. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 277 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 278 | }; |
| 279 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 280 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 281 | public: |
| 282 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 283 | |
| 284 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 285 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 286 | __ Bind(GetEntryLabel()); |
| 287 | arm64_codegen->InvokeRuntime( |
| 288 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc()); |
| 289 | } |
| 290 | |
| 291 | private: |
| 292 | HDivZeroCheck* const instruction_; |
| 293 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 294 | }; |
| 295 | |
| 296 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 297 | public: |
| 298 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 299 | HInstruction* at, |
| 300 | uint32_t dex_pc, |
| 301 | bool do_clinit) |
| 302 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 303 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 304 | } |
| 305 | |
| 306 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 307 | LocationSummary* locations = at_->GetLocations(); |
| 308 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 309 | |
| 310 | __ Bind(GetEntryLabel()); |
| 311 | codegen->SaveLiveRegisters(locations); |
| 312 | |
| 313 | InvokeRuntimeCallingConvention calling_convention; |
| 314 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
| 315 | arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W()); |
| 316 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 317 | : QUICK_ENTRY_POINT(pInitializeType); |
| 318 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_); |
| 319 | |
| 320 | // Move the class to the desired location. |
| 321 | Location out = locations->Out(); |
| 322 | if (out.IsValid()) { |
| 323 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 324 | Primitive::Type type = at_->GetType(); |
| 325 | arm64_codegen->MoveHelper(out, calling_convention.GetReturnLocation(type), type); |
| 326 | } |
| 327 | |
| 328 | codegen->RestoreLiveRegisters(locations); |
| 329 | __ B(GetExitLabel()); |
| 330 | } |
| 331 | |
| 332 | private: |
| 333 | // The class this slow path will load. |
| 334 | HLoadClass* const cls_; |
| 335 | |
| 336 | // The instruction where this slow path is happening. |
| 337 | // (Might be the load class or an initialization check). |
| 338 | HInstruction* const at_; |
| 339 | |
| 340 | // The dex PC of `at_`. |
| 341 | const uint32_t dex_pc_; |
| 342 | |
| 343 | // Whether to initialize the class. |
| 344 | const bool do_clinit_; |
| 345 | |
| 346 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 347 | }; |
| 348 | |
| 349 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 350 | public: |
| 351 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {} |
| 352 | |
| 353 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 354 | LocationSummary* locations = instruction_->GetLocations(); |
| 355 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 356 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 357 | |
| 358 | __ Bind(GetEntryLabel()); |
| 359 | codegen->SaveLiveRegisters(locations); |
| 360 | |
| 361 | InvokeRuntimeCallingConvention calling_convention; |
| 362 | arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0).W()); |
| 363 | __ Mov(calling_convention.GetRegisterAt(1).W(), instruction_->GetStringIndex()); |
| 364 | arm64_codegen->InvokeRuntime( |
| 365 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc()); |
| 366 | Primitive::Type type = instruction_->GetType(); |
| 367 | arm64_codegen->MoveHelper(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 368 | |
| 369 | codegen->RestoreLiveRegisters(locations); |
| 370 | __ B(GetExitLabel()); |
| 371 | } |
| 372 | |
| 373 | private: |
| 374 | HLoadString* const instruction_; |
| 375 | |
| 376 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 377 | }; |
| 378 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 379 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 380 | public: |
| 381 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {} |
| 382 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 383 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 384 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 385 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 386 | arm64_codegen->InvokeRuntime( |
| 387 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | private: |
| 391 | HNullCheck* const instruction_; |
| 392 | |
| 393 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 394 | }; |
| 395 | |
| 396 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 397 | public: |
| 398 | explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction, |
| 399 | HBasicBlock* successor) |
| 400 | : instruction_(instruction), successor_(successor) {} |
| 401 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 402 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 403 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 404 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 405 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
| 406 | arm64_codegen->InvokeRuntime( |
| 407 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc()); |
| 408 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
| 409 | if (successor_ == nullptr) { |
| 410 | __ B(GetReturnLabel()); |
| 411 | } else { |
| 412 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 413 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | vixl::Label* GetReturnLabel() { |
| 417 | DCHECK(successor_ == nullptr); |
| 418 | return &return_label_; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | private: |
| 423 | HSuspendCheck* const instruction_; |
| 424 | // If not null, the block to branch to after the suspend check. |
| 425 | HBasicBlock* const successor_; |
| 426 | |
| 427 | // If `successor_` is null, the label to branch to after the suspend check. |
| 428 | vixl::Label return_label_; |
| 429 | |
| 430 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 431 | }; |
| 432 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 433 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 434 | public: |
| 435 | TypeCheckSlowPathARM64() {} |
| 436 | |
| 437 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 438 | __ Bind(GetEntryLabel()); |
| 439 | __ Brk(__LINE__); // TODO: Unimplemented TypeCheckSlowPathARM64. |
| 440 | __ b(GetExitLabel()); |
| 441 | } |
| 442 | |
| 443 | private: |
| 444 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 445 | }; |
| 446 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 447 | #undef __ |
| 448 | |
| 449 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 450 | Location next_location; |
| 451 | if (type == Primitive::kPrimVoid) { |
| 452 | LOG(FATAL) << "Unreachable type " << type; |
| 453 | } |
| 454 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 455 | if (IsFPType(type) && (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 456 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++)); |
| 457 | } else if (!IsFPType(type) && (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 458 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 459 | } else { |
| 460 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 461 | next_location = Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 462 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 465 | // Space on the stack is reserved for all arguments. |
| 466 | stack_index_ += Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 467 | return next_location; |
| 468 | } |
| 469 | |
| 470 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph) |
| 471 | : CodeGenerator(graph, |
| 472 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 473 | kNumberOfAllocatableFPRegisters, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 474 | kNumberOfAllocatableRegisterPairs), |
| 475 | block_labels_(nullptr), |
| 476 | location_builder_(graph, this), |
| 477 | instruction_visitor_(graph, this) {} |
| 478 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 479 | #undef __ |
| 480 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 481 | |
| 482 | void CodeGeneratorARM64::GenerateFrameEntry() { |
| 483 | // TODO: Add proper support for the stack overflow check. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 484 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 485 | Register temp = temps.AcquireX(); |
| 486 | __ Add(temp, sp, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
| 487 | __ Ldr(temp, MemOperand(temp, 0)); |
| 488 | RecordPcInfo(nullptr, 0); |
| 489 | |
| 490 | CPURegList preserved_regs = GetFramePreservedRegisters(); |
| 491 | int frame_size = GetFrameSize(); |
| 492 | core_spill_mask_ |= preserved_regs.list(); |
| 493 | |
| 494 | __ Str(w0, MemOperand(sp, -frame_size, PreIndex)); |
| 495 | __ PokeCPURegList(preserved_regs, frame_size - preserved_regs.TotalSizeInBytes()); |
| 496 | |
| 497 | // Stack layout: |
| 498 | // sp[frame_size - 8] : lr. |
| 499 | // ... : other preserved registers. |
| 500 | // sp[frame_size - regs_size]: first preserved register. |
| 501 | // ... : reserved frame space. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 502 | // sp[0] : current method. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void CodeGeneratorARM64::GenerateFrameExit() { |
| 506 | int frame_size = GetFrameSize(); |
| 507 | CPURegList preserved_regs = GetFramePreservedRegisters(); |
| 508 | __ PeekCPURegList(preserved_regs, frame_size - preserved_regs.TotalSizeInBytes()); |
| 509 | __ Drop(frame_size); |
| 510 | } |
| 511 | |
| 512 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 513 | __ Bind(GetLabelOf(block)); |
| 514 | } |
| 515 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 516 | void CodeGeneratorARM64::Move(HInstruction* instruction, |
| 517 | Location location, |
| 518 | HInstruction* move_for) { |
| 519 | LocationSummary* locations = instruction->GetLocations(); |
| 520 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 521 | return; |
| 522 | } |
| 523 | |
| 524 | Primitive::Type type = instruction->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 525 | DCHECK_NE(type, Primitive::kPrimVoid); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 526 | |
| 527 | if (instruction->IsIntConstant() || instruction->IsLongConstant()) { |
| 528 | int64_t value = instruction->IsIntConstant() ? instruction->AsIntConstant()->GetValue() |
| 529 | : instruction->AsLongConstant()->GetValue(); |
| 530 | if (location.IsRegister()) { |
| 531 | Register dst = RegisterFrom(location, type); |
| 532 | DCHECK((instruction->IsIntConstant() && dst.Is32Bits()) || |
| 533 | (instruction->IsLongConstant() && dst.Is64Bits())); |
| 534 | __ Mov(dst, value); |
| 535 | } else { |
| 536 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 537 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 538 | Register temp = instruction->IsIntConstant() ? temps.AcquireW() : temps.AcquireX(); |
| 539 | __ Mov(temp, value); |
| 540 | __ Str(temp, StackOperandFrom(location)); |
| 541 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 542 | } else if (instruction->IsTemporary()) { |
| 543 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 544 | MoveHelper(location, temp_location, type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 545 | } else if (instruction->IsLoadLocal()) { |
| 546 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 547 | if (Is64BitType(type)) { |
| 548 | MoveHelper(location, Location::DoubleStackSlot(stack_slot), type); |
| 549 | } else { |
| 550 | MoveHelper(location, Location::StackSlot(stack_slot), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | } else { |
| 554 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
| 555 | MoveHelper(location, locations->Out(), type); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | size_t CodeGeneratorARM64::FrameEntrySpillSize() const { |
| 560 | return GetFramePreservedRegistersSize(); |
| 561 | } |
| 562 | |
| 563 | Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const { |
| 564 | Primitive::Type type = load->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 565 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 566 | switch (type) { |
| 567 | case Primitive::kPrimNot: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 568 | case Primitive::kPrimInt: |
| 569 | case Primitive::kPrimFloat: |
| 570 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 571 | |
| 572 | case Primitive::kPrimLong: |
| 573 | case Primitive::kPrimDouble: |
| 574 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 575 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 576 | case Primitive::kPrimBoolean: |
| 577 | case Primitive::kPrimByte: |
| 578 | case Primitive::kPrimChar: |
| 579 | case Primitive::kPrimShort: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 580 | case Primitive::kPrimVoid: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 581 | LOG(FATAL) << "Unexpected type " << type; |
| 582 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 583 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 584 | LOG(FATAL) << "Unreachable"; |
| 585 | return Location::NoLocation(); |
| 586 | } |
| 587 | |
| 588 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 589 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 590 | Register card = temps.AcquireX(); |
| 591 | Register temp = temps.AcquireX(); |
| 592 | vixl::Label done; |
| 593 | __ Cbz(value, &done); |
| 594 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 595 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 596 | __ Strb(card, MemOperand(card, temp)); |
| 597 | __ Bind(&done); |
| 598 | } |
| 599 | |
| 600 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
| 601 | // Block reserved registers: |
| 602 | // ip0 (VIXL temporary) |
| 603 | // ip1 (VIXL temporary) |
| 604 | // xSuspend (Suspend counter) |
| 605 | // lr |
| 606 | // sp is not part of the allocatable registers, so we don't need to block it. |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 607 | // TODO: Avoid blocking callee-saved registers, and instead preserve them |
| 608 | // where necessary. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 609 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 610 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 611 | reserved_core_registers.Combine(quick_callee_saved_registers); |
| 612 | while (!reserved_core_registers.IsEmpty()) { |
| 613 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 614 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 615 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
| 616 | reserved_fp_registers.Combine(CPURegList::GetCalleeSavedFP()); |
| 617 | while (!reserved_core_registers.IsEmpty()) { |
| 618 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 619 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const { |
| 623 | if (type == Primitive::kPrimVoid) { |
| 624 | LOG(FATAL) << "Unreachable type " << type; |
| 625 | } |
| 626 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 627 | if (IsFPType(type)) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 628 | ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters); |
| 629 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 630 | return Location::FpuRegisterLocation(reg); |
| 631 | } else { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 632 | ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters); |
| 633 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 634 | return Location::RegisterLocation(reg); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 639 | stream << Arm64ManagedRegister::FromXRegister(XRegister(reg)); |
| 640 | } |
| 641 | |
| 642 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 643 | stream << Arm64ManagedRegister::FromDRegister(DRegister(reg)); |
| 644 | } |
| 645 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 646 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
| 647 | if (constant->IsIntConstant() || constant->IsLongConstant()) { |
| 648 | __ Mov(Register(destination), |
| 649 | constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 650 | : constant->AsLongConstant()->GetValue()); |
| 651 | } else if (constant->IsFloatConstant()) { |
| 652 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 653 | } else { |
| 654 | DCHECK(constant->IsDoubleConstant()); |
| 655 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 656 | } |
| 657 | } |
| 658 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 659 | void CodeGeneratorARM64::MoveHelper(Location destination, |
| 660 | Location source, |
| 661 | Primitive::Type type) { |
| 662 | if (source.Equals(destination)) { |
| 663 | return; |
| 664 | } |
| 665 | if (destination.IsRegister()) { |
| 666 | Register dst = RegisterFrom(destination, type); |
| 667 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 668 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 669 | __ Ldr(dst, StackOperandFrom(source)); |
| 670 | } else { |
| 671 | __ Mov(dst, OperandFrom(source, type)); |
| 672 | } |
| 673 | } else if (destination.IsFpuRegister()) { |
| 674 | FPRegister dst = FPRegisterFrom(destination, type); |
| 675 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 676 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 677 | __ Ldr(dst, StackOperandFrom(source)); |
| 678 | } else if (source.IsFpuRegister()) { |
| 679 | __ Fmov(dst, FPRegisterFrom(source, type)); |
| 680 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 681 | MoveConstant(dst, source.GetConstant()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 682 | } |
| 683 | } else { |
| 684 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 685 | if (source.IsRegister()) { |
| 686 | __ Str(RegisterFrom(source, type), StackOperandFrom(destination)); |
| 687 | } else if (source.IsFpuRegister()) { |
| 688 | __ Str(FPRegisterFrom(source, type), StackOperandFrom(destination)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 689 | } else if (source.IsConstant()) { |
| 690 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 691 | HConstant* cst = source.GetConstant(); |
| 692 | CPURegister temp; |
| 693 | if (cst->IsIntConstant() || cst->IsLongConstant()) { |
| 694 | temp = cst->IsIntConstant() ? temps.AcquireW() : temps.AcquireX(); |
| 695 | } else { |
| 696 | DCHECK(cst->IsFloatConstant() || cst->IsDoubleConstant()); |
| 697 | temp = cst->IsFloatConstant() ? temps.AcquireS() : temps.AcquireD(); |
| 698 | } |
| 699 | MoveConstant(temp, cst); |
| 700 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 701 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 702 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 703 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 704 | Register temp = destination.IsDoubleStackSlot() ? temps.AcquireX() : temps.AcquireW(); |
| 705 | __ Ldr(temp, StackOperandFrom(source)); |
| 706 | __ Str(temp, StackOperandFrom(destination)); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 712 | vixl::CPURegister dst, |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 713 | const vixl::MemOperand& src) { |
| 714 | switch (type) { |
| 715 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 716 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 717 | break; |
| 718 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 719 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 720 | break; |
| 721 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 722 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 723 | break; |
| 724 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 725 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 726 | break; |
| 727 | case Primitive::kPrimInt: |
| 728 | case Primitive::kPrimNot: |
| 729 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 730 | case Primitive::kPrimFloat: |
| 731 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 732 | DCHECK(dst.Is64Bits() == Is64BitType(type)); |
| 733 | __ Ldr(dst, src); |
| 734 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 735 | case Primitive::kPrimVoid: |
| 736 | LOG(FATAL) << "Unreachable type " << type; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 741 | vixl::CPURegister rt, |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 742 | const vixl::MemOperand& dst) { |
| 743 | switch (type) { |
| 744 | case Primitive::kPrimBoolean: |
| 745 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 746 | __ Strb(Register(rt), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 747 | break; |
| 748 | case Primitive::kPrimChar: |
| 749 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 750 | __ Strh(Register(rt), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 751 | break; |
| 752 | case Primitive::kPrimInt: |
| 753 | case Primitive::kPrimNot: |
| 754 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 755 | case Primitive::kPrimFloat: |
| 756 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 757 | DCHECK(rt.Is64Bits() == Is64BitType(type)); |
| 758 | __ Str(rt, dst); |
| 759 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 760 | case Primitive::kPrimVoid: |
| 761 | LOG(FATAL) << "Unreachable type " << type; |
| 762 | } |
| 763 | } |
| 764 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 765 | void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) { |
| 766 | DCHECK(current_method.IsW()); |
| 767 | __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset)); |
| 768 | } |
| 769 | |
| 770 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 771 | HInstruction* instruction, |
| 772 | uint32_t dex_pc) { |
| 773 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 774 | __ Blr(lr); |
| 775 | RecordPcInfo(instruction, dex_pc); |
| 776 | DCHECK(instruction->IsSuspendCheck() |
| 777 | || instruction->IsBoundsCheck() |
| 778 | || instruction->IsNullCheck() |
| 779 | || instruction->IsDivZeroCheck() |
| 780 | || !IsLeafMethod()); |
| 781 | } |
| 782 | |
| 783 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| 784 | vixl::Register class_reg) { |
| 785 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 786 | Register temp = temps.AcquireW(); |
| 787 | __ Ldr(temp, HeapOperand(class_reg, mirror::Class::StatusOffset())); |
| 788 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 789 | __ B(lt, slow_path->GetEntryLabel()); |
| 790 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 791 | // properly. Therefore, we do a memory fence. |
| 792 | __ Dmb(InnerShareable, BarrierAll); |
| 793 | __ Bind(slow_path->GetExitLabel()); |
| 794 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 795 | |
| 796 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 797 | CodeGeneratorARM64* codegen) |
| 798 | : HGraphVisitor(graph), |
| 799 | assembler_(codegen->GetAssembler()), |
| 800 | codegen_(codegen) {} |
| 801 | |
| 802 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 803 | M(ParallelMove) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 804 | M(Rem) \ |
| 805 | M(Shl) \ |
| 806 | M(Shr) \ |
| 807 | M(UShr) \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 808 | |
| 809 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 810 | |
| 811 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 812 | // Using a base helps identify when we hit such breakpoints. |
| 813 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 814 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 815 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 816 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 817 | }; |
| 818 | |
| 819 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
| 820 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \ |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 821 | UNUSED(instr); \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 822 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 823 | } \ |
| 824 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 825 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 826 | locations->SetOut(Location::Any()); \ |
| 827 | } |
| 828 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 829 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 830 | |
| 831 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 832 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 833 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 834 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 835 | DCHECK_EQ(instr->InputCount(), 2U); |
| 836 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 837 | Primitive::Type type = instr->GetResultType(); |
| 838 | switch (type) { |
| 839 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 840 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 841 | locations->SetInAt(0, Location::RequiresRegister()); |
| 842 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 843 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 844 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 845 | |
| 846 | case Primitive::kPrimFloat: |
| 847 | case Primitive::kPrimDouble: |
| 848 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 849 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 850 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 851 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 852 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 853 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 854 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 858 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 859 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 860 | |
| 861 | switch (type) { |
| 862 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 863 | case Primitive::kPrimLong: { |
| 864 | Register dst = OutputRegister(instr); |
| 865 | Register lhs = InputRegisterAt(instr, 0); |
| 866 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 867 | if (instr->IsAdd()) { |
| 868 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 869 | } else if (instr->IsAnd()) { |
| 870 | __ And(dst, lhs, rhs); |
| 871 | } else if (instr->IsOr()) { |
| 872 | __ Orr(dst, lhs, rhs); |
| 873 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 874 | __ Sub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 875 | } else { |
| 876 | DCHECK(instr->IsXor()); |
| 877 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 878 | } |
| 879 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 880 | } |
| 881 | case Primitive::kPrimFloat: |
| 882 | case Primitive::kPrimDouble: { |
| 883 | FPRegister dst = OutputFPRegister(instr); |
| 884 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 885 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 886 | if (instr->IsAdd()) { |
| 887 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 888 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 889 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 890 | } else { |
| 891 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 892 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 893 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 894 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 895 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 896 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
| 900 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 901 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 905 | HandleBinaryOp(instruction); |
| 906 | } |
| 907 | |
| 908 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 909 | HandleBinaryOp(instruction); |
| 910 | } |
| 911 | |
| 912 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 913 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 916 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| 917 | LocationSummary* locations = |
| 918 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 920 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 921 | locations->SetOut(Location::RequiresRegister()); |
| 922 | } |
| 923 | |
| 924 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| 925 | LocationSummary* locations = instruction->GetLocations(); |
| 926 | Primitive::Type type = instruction->GetType(); |
| 927 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 928 | Location index = locations->InAt(1); |
| 929 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
| 930 | MemOperand source(obj); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 931 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 932 | |
| 933 | if (index.IsConstant()) { |
| 934 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 935 | source = MemOperand(obj, offset); |
| 936 | } else { |
| 937 | Register temp = temps.AcquireSameSizeAs(obj); |
| 938 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 939 | __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type))); |
| 940 | source = MemOperand(temp, offset); |
| 941 | } |
| 942 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 943 | codegen_->Load(type, OutputCPURegister(instruction), source); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 946 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 947 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 948 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 949 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
| 953 | __ Ldr(OutputRegister(instruction), |
| 954 | HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset())); |
| 955 | } |
| 956 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 957 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
| 958 | Primitive::Type value_type = instruction->GetComponentType(); |
| 959 | bool is_object = value_type == Primitive::kPrimNot; |
| 960 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 961 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 962 | if (is_object) { |
| 963 | InvokeRuntimeCallingConvention calling_convention; |
| 964 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 965 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 966 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 967 | } else { |
| 968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 969 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 970 | locations->SetInAt(2, Location::RequiresRegister()); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 975 | Primitive::Type value_type = instruction->GetComponentType(); |
| 976 | if (value_type == Primitive::kPrimNot) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 977 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc()); |
| 978 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 979 | } else { |
| 980 | LocationSummary* locations = instruction->GetLocations(); |
| 981 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 982 | CPURegister value = InputCPURegisterAt(instruction, 2); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 983 | Location index = locations->InAt(1); |
| 984 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 985 | MemOperand destination(obj); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 986 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 987 | |
| 988 | if (index.IsConstant()) { |
| 989 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 990 | destination = MemOperand(obj, offset); |
| 991 | } else { |
| 992 | Register temp = temps.AcquireSameSizeAs(obj); |
| 993 | Register index_reg = InputRegisterAt(instruction, 1); |
| 994 | __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type))); |
| 995 | destination = MemOperand(temp, offset); |
| 996 | } |
| 997 | |
| 998 | codegen_->Store(value_type, value, destination); |
| 999 | } |
| 1000 | } |
| 1001 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1002 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1003 | LocationSummary* locations = |
| 1004 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1005 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1006 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1007 | if (instruction->HasUses()) { |
| 1008 | locations->SetOut(Location::SameAsFirstInput()); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1013 | BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(); |
| 1014 | codegen_->AddSlowPath(slow_path); |
| 1015 | |
| 1016 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 1017 | __ B(slow_path->GetEntryLabel(), hs); |
| 1018 | } |
| 1019 | |
| 1020 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 1021 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1022 | instruction, LocationSummary::kCallOnSlowPath); |
| 1023 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1024 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1025 | } |
| 1026 | |
| 1027 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
| 1028 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1029 | Register obj = InputRegisterAt(instruction, 0);; |
| 1030 | Register cls = InputRegisterAt(instruction, 1);; |
| 1031 | Register temp = temps.AcquireW(); |
| 1032 | |
| 1033 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(); |
| 1034 | codegen_->AddSlowPath(slow_path); |
| 1035 | |
| 1036 | // TODO: avoid this check if we know obj is not null. |
| 1037 | __ Cbz(obj, slow_path->GetExitLabel()); |
| 1038 | // Compare the class of `obj` with `cls`. |
| 1039 | __ Ldr(temp, HeapOperand(obj, mirror::Object::ClassOffset())); |
| 1040 | __ Cmp(temp, cls); |
| 1041 | __ B(ne, slow_path->GetEntryLabel()); |
| 1042 | __ Bind(slow_path->GetExitLabel()); |
| 1043 | } |
| 1044 | |
| 1045 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 1046 | LocationSummary* locations = |
| 1047 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 1048 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1049 | if (check->HasUses()) { |
| 1050 | locations->SetOut(Location::SameAsFirstInput()); |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 1055 | // We assume the class is not null. |
| 1056 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 1057 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 1058 | codegen_->AddSlowPath(slow_path); |
| 1059 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 1060 | } |
| 1061 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1062 | void LocationsBuilderARM64::VisitCompare(HCompare* instruction) { |
| 1063 | LocationSummary* locations = |
| 1064 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1065 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1066 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1067 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* instruction) { |
| 1071 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 1072 | |
| 1073 | DCHECK_EQ(in_type, Primitive::kPrimLong); |
| 1074 | switch (in_type) { |
| 1075 | case Primitive::kPrimLong: { |
| 1076 | vixl::Label done; |
| 1077 | Register result = OutputRegister(instruction); |
| 1078 | Register left = InputRegisterAt(instruction, 0); |
| 1079 | Operand right = InputOperandAt(instruction, 1); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1080 | __ Subs(result.X(), left, right); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1081 | __ B(eq, &done); |
| 1082 | __ Mov(result, 1); |
| 1083 | __ Cneg(result, result, le); |
| 1084 | __ Bind(&done); |
| 1085 | break; |
| 1086 | } |
| 1087 | default: |
| 1088 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | void LocationsBuilderARM64::VisitCondition(HCondition* instruction) { |
| 1093 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1094 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1095 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1096 | if (instruction->NeedsMaterialization()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) { |
| 1102 | if (!instruction->NeedsMaterialization()) { |
| 1103 | return; |
| 1104 | } |
| 1105 | |
| 1106 | LocationSummary* locations = instruction->GetLocations(); |
| 1107 | Register lhs = InputRegisterAt(instruction, 0); |
| 1108 | Operand rhs = InputOperandAt(instruction, 1); |
| 1109 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
| 1110 | Condition cond = ARM64Condition(instruction->GetCondition()); |
| 1111 | |
| 1112 | __ Cmp(lhs, rhs); |
| 1113 | __ Csel(res, vixl::Assembler::AppropriateZeroRegFor(res), Operand(1), InvertCondition(cond)); |
| 1114 | } |
| 1115 | |
| 1116 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 1117 | M(Equal) \ |
| 1118 | M(NotEqual) \ |
| 1119 | M(LessThan) \ |
| 1120 | M(LessThanOrEqual) \ |
| 1121 | M(GreaterThan) \ |
| 1122 | M(GreaterThanOrEqual) |
| 1123 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| 1124 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \ |
| 1125 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } |
| 1126 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1127 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1128 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 1129 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1130 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 1131 | LocationSummary* locations = |
| 1132 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1133 | switch (div->GetResultType()) { |
| 1134 | case Primitive::kPrimInt: |
| 1135 | case Primitive::kPrimLong: |
| 1136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1137 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1138 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1139 | break; |
| 1140 | |
| 1141 | case Primitive::kPrimFloat: |
| 1142 | case Primitive::kPrimDouble: |
| 1143 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1144 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1145 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1146 | break; |
| 1147 | |
| 1148 | default: |
| 1149 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 1154 | Primitive::Type type = div->GetResultType(); |
| 1155 | switch (type) { |
| 1156 | case Primitive::kPrimInt: |
| 1157 | case Primitive::kPrimLong: |
| 1158 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 1159 | break; |
| 1160 | |
| 1161 | case Primitive::kPrimFloat: |
| 1162 | case Primitive::kPrimDouble: |
| 1163 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 1164 | break; |
| 1165 | |
| 1166 | default: |
| 1167 | LOG(FATAL) << "Unexpected div type " << type; |
| 1168 | } |
| 1169 | } |
| 1170 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1171 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1172 | LocationSummary* locations = |
| 1173 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1174 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 1175 | if (instruction->HasUses()) { |
| 1176 | locations->SetOut(Location::SameAsFirstInput()); |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1181 | SlowPathCodeARM64* slow_path = |
| 1182 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 1183 | codegen_->AddSlowPath(slow_path); |
| 1184 | Location value = instruction->GetLocations()->InAt(0); |
| 1185 | |
| 1186 | if (value.IsConstant()) { |
| 1187 | int64_t divisor = Int64ConstantFrom(value); |
| 1188 | if (divisor == 0) { |
| 1189 | __ B(slow_path->GetEntryLabel()); |
| 1190 | } else { |
| 1191 | LOG(FATAL) << "Divisions by non-null constants should have been optimized away."; |
| 1192 | } |
| 1193 | } else { |
| 1194 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 1195 | } |
| 1196 | } |
| 1197 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1198 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1199 | LocationSummary* locations = |
| 1200 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1201 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1202 | } |
| 1203 | |
| 1204 | void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1205 | UNUSED(constant); |
| 1206 | // Will be generated at use site. |
| 1207 | } |
| 1208 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1209 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 1210 | exit->SetLocations(nullptr); |
| 1211 | } |
| 1212 | |
| 1213 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1214 | UNUSED(exit); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1215 | if (kIsDebugBuild) { |
| 1216 | down_cast<Arm64Assembler*>(GetAssembler())->Comment("Unreachable"); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1217 | __ Brk(__LINE__); // TODO: Introduce special markers for such code locations. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1221 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 1222 | LocationSummary* locations = |
| 1223 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1224 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1225 | } |
| 1226 | |
| 1227 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 1228 | UNUSED(constant); |
| 1229 | // Will be generated at use site. |
| 1230 | } |
| 1231 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1232 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 1233 | got->SetLocations(nullptr); |
| 1234 | } |
| 1235 | |
| 1236 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 1237 | HBasicBlock* successor = got->GetSuccessor(); |
| 1238 | // TODO: Support for suspend checks emission. |
| 1239 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| 1240 | __ B(codegen_->GetLabelOf(successor)); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 1245 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1246 | HInstruction* cond = if_instr->InputAt(0); |
| 1247 | DCHECK(cond->IsCondition()); |
| 1248 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1249 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| 1254 | HInstruction* cond = if_instr->InputAt(0); |
| 1255 | DCHECK(cond->IsCondition()); |
| 1256 | HCondition* condition = cond->AsCondition(); |
| 1257 | vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1258 | vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1259 | |
| 1260 | // TODO: Support constant condition input in VisitIf. |
| 1261 | |
| 1262 | if (condition->NeedsMaterialization()) { |
| 1263 | // The condition instruction has been materialized, compare the output to 0. |
| 1264 | Location cond_val = if_instr->GetLocations()->InAt(0); |
| 1265 | DCHECK(cond_val.IsRegister()); |
| 1266 | __ Cbnz(InputRegisterAt(if_instr, 0), true_target); |
| 1267 | |
| 1268 | } else { |
| 1269 | // The condition instruction has not been materialized, use its inputs as |
| 1270 | // the comparison and its condition as the branch condition. |
| 1271 | Register lhs = InputRegisterAt(condition, 0); |
| 1272 | Operand rhs = InputOperandAt(condition, 1); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1273 | Condition arm64_cond = ARM64Condition(condition->GetCondition()); |
| 1274 | if ((arm64_cond == eq || arm64_cond == ne) && rhs.IsImmediate() && (rhs.immediate() == 0)) { |
| 1275 | if (arm64_cond == eq) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1276 | __ Cbz(lhs, true_target); |
| 1277 | } else { |
| 1278 | __ Cbnz(lhs, true_target); |
| 1279 | } |
| 1280 | } else { |
| 1281 | __ Cmp(lhs, rhs); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1282 | __ B(arm64_cond, true_target); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) { |
| 1287 | __ B(false_target); |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1292 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1293 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1294 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1298 | MemOperand field = MemOperand(InputRegisterAt(instruction, 0), |
| 1299 | instruction->GetFieldOffset().Uint32Value()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1300 | codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1304 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1306 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1307 | } |
| 1308 | |
| 1309 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1310 | Primitive::Type field_type = instruction->GetFieldType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1311 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1312 | Register obj = InputRegisterAt(instruction, 0); |
| 1313 | codegen_->Store(field_type, value, MemOperand(obj, instruction->GetFieldOffset().Uint32Value())); |
| 1314 | if (field_type == Primitive::kPrimNot) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1315 | codegen_->MarkGCCard(obj, Register(value)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1319 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| 1320 | LocationSummary::CallKind call_kind = |
| 1321 | instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 1322 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 1323 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1324 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1325 | locations->SetOut(Location::RequiresRegister(), true); // The output does overlap inputs. |
| 1326 | } |
| 1327 | |
| 1328 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| 1329 | LocationSummary* locations = instruction->GetLocations(); |
| 1330 | Register obj = InputRegisterAt(instruction, 0);; |
| 1331 | Register cls = InputRegisterAt(instruction, 1);; |
| 1332 | Register out = OutputRegister(instruction); |
| 1333 | |
| 1334 | vixl::Label done; |
| 1335 | |
| 1336 | // Return 0 if `obj` is null. |
| 1337 | // TODO: Avoid this check if we know `obj` is not null. |
| 1338 | __ Mov(out, 0); |
| 1339 | __ Cbz(obj, &done); |
| 1340 | |
| 1341 | // Compare the class of `obj` with `cls`. |
| 1342 | __ Ldr(out, MemOperand(obj, mirror::Object::ClassOffset().Int32Value())); |
| 1343 | __ Cmp(out, cls); |
| 1344 | if (instruction->IsClassFinal()) { |
| 1345 | // Classes must be equal for the instanceof to succeed. |
| 1346 | __ Cset(out, eq); |
| 1347 | } else { |
| 1348 | // If the classes are not equal, we go into a slow path. |
| 1349 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 1350 | SlowPathCodeARM64* slow_path = |
| 1351 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(); |
| 1352 | codegen_->AddSlowPath(slow_path); |
| 1353 | __ B(ne, slow_path->GetEntryLabel()); |
| 1354 | __ Mov(out, 1); |
| 1355 | __ Bind(slow_path->GetExitLabel()); |
| 1356 | } |
| 1357 | |
| 1358 | __ Bind(&done); |
| 1359 | } |
| 1360 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1361 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 1362 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 1363 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1364 | } |
| 1365 | |
| 1366 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) { |
| 1367 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1368 | UNUSED(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1371 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
| 1372 | LocationSummary* locations = |
| 1373 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
| 1374 | locations->AddTemp(LocationFrom(x0)); |
| 1375 | |
| 1376 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
| 1377 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
| 1378 | HInstruction* input = invoke->InputAt(i); |
| 1379 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1380 | } |
| 1381 | |
| 1382 | Primitive::Type return_type = invoke->GetType(); |
| 1383 | if (return_type != Primitive::kPrimVoid) { |
| 1384 | locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type)); |
| 1385 | } |
| 1386 | } |
| 1387 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1388 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1389 | HandleInvoke(invoke); |
| 1390 | } |
| 1391 | |
| 1392 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1393 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1394 | Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 1395 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1396 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1397 | Location receiver = invoke->GetLocations()->InAt(0); |
| 1398 | Offset class_offset = mirror::Object::ClassOffset(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1399 | Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1400 | |
| 1401 | // The register ip1 is required to be used for the hidden argument in |
| 1402 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 1403 | UseScratchRegisterScope scratch_scope(GetVIXLAssembler()); |
| 1404 | scratch_scope.Exclude(ip1); |
| 1405 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 1406 | |
| 1407 | // temp = object->GetClass(); |
| 1408 | if (receiver.IsStackSlot()) { |
| 1409 | __ Ldr(temp, StackOperandFrom(receiver)); |
| 1410 | __ Ldr(temp, HeapOperand(temp, class_offset)); |
| 1411 | } else { |
| 1412 | __ Ldr(temp, HeapOperandFrom(receiver, class_offset)); |
| 1413 | } |
| 1414 | // temp = temp->GetImtEntryAt(method_offset); |
| 1415 | __ Ldr(temp, HeapOperand(temp, method_offset)); |
| 1416 | // lr = temp->GetEntryPoint(); |
| 1417 | __ Ldr(lr, HeapOperand(temp, entry_point)); |
| 1418 | // lr(); |
| 1419 | __ Blr(lr); |
| 1420 | DCHECK(!codegen_->IsLeafMethod()); |
| 1421 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1422 | } |
| 1423 | |
| 1424 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1425 | HandleInvoke(invoke); |
| 1426 | } |
| 1427 | |
| 1428 | void LocationsBuilderARM64::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 1429 | HandleInvoke(invoke); |
| 1430 | } |
| 1431 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1432 | void InstructionCodeGeneratorARM64::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 1433 | Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 1434 | // Make sure that ArtMethod* is passed in W0 as per the calling convention |
| 1435 | DCHECK(temp.Is(w0)); |
| 1436 | size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() + |
| 1437 | invoke->GetIndexInDexCache() * kHeapRefSize; |
| 1438 | |
| 1439 | // TODO: Implement all kinds of calls: |
| 1440 | // 1) boot -> boot |
| 1441 | // 2) app -> boot |
| 1442 | // 3) app -> app |
| 1443 | // |
| 1444 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1445 | |
| 1446 | // temp = method; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1447 | codegen_->LoadCurrentMethod(temp); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1448 | // temp = temp->dex_cache_resolved_methods_; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1449 | __ Ldr(temp, MemOperand(temp.X(), |
| 1450 | mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1451 | // temp = temp[index_in_cache]; |
| 1452 | __ Ldr(temp, MemOperand(temp.X(), index_in_cache)); |
| 1453 | // lr = temp->entry_point_from_quick_compiled_code_; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1454 | __ Ldr(lr, MemOperand(temp.X(), |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1455 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1456 | kArm64WordSize).SizeValue())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1457 | // lr(); |
| 1458 | __ Blr(lr); |
| 1459 | |
| 1460 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1461 | DCHECK(!codegen_->IsLeafMethod()); |
| 1462 | } |
| 1463 | |
| 1464 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1465 | LocationSummary* locations = invoke->GetLocations(); |
| 1466 | Location receiver = locations->InAt(0); |
| 1467 | Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 1468 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 1469 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1470 | Offset class_offset = mirror::Object::ClassOffset(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1471 | Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1472 | |
| 1473 | // temp = object->GetClass(); |
| 1474 | if (receiver.IsStackSlot()) { |
| 1475 | __ Ldr(temp.W(), MemOperand(sp, receiver.GetStackIndex())); |
| 1476 | __ Ldr(temp.W(), MemOperand(temp, class_offset.SizeValue())); |
| 1477 | } else { |
| 1478 | DCHECK(receiver.IsRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1479 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1480 | } |
| 1481 | // temp = temp->GetMethodAt(method_offset); |
| 1482 | __ Ldr(temp.W(), MemOperand(temp, method_offset)); |
| 1483 | // lr = temp->GetEntryPoint(); |
| 1484 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 1485 | // lr(); |
| 1486 | __ Blr(lr); |
| 1487 | DCHECK(!codegen_->IsLeafMethod()); |
| 1488 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1489 | } |
| 1490 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1491 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
| 1492 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath |
| 1493 | : LocationSummary::kNoCall; |
| 1494 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 1495 | locations->SetOut(Location::RequiresRegister()); |
| 1496 | } |
| 1497 | |
| 1498 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
| 1499 | Register out = OutputRegister(cls); |
| 1500 | if (cls->IsReferrersClass()) { |
| 1501 | DCHECK(!cls->CanCallRuntime()); |
| 1502 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 1503 | codegen_->LoadCurrentMethod(out); |
| 1504 | __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset())); |
| 1505 | } else { |
| 1506 | DCHECK(cls->CanCallRuntime()); |
| 1507 | codegen_->LoadCurrentMethod(out); |
| 1508 | __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset())); |
| 1509 | __ Ldr(out, MemOperand(out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 1510 | |
| 1511 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 1512 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 1513 | codegen_->AddSlowPath(slow_path); |
| 1514 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 1515 | if (cls->MustGenerateClinitCheck()) { |
| 1516 | GenerateClassInitializationCheck(slow_path, out); |
| 1517 | } else { |
| 1518 | __ Bind(slow_path->GetExitLabel()); |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 1524 | LocationSummary* locations = |
| 1525 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 1526 | locations->SetOut(Location::RequiresRegister()); |
| 1527 | } |
| 1528 | |
| 1529 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
| 1530 | MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); |
| 1531 | __ Ldr(OutputRegister(instruction), exception); |
| 1532 | __ Str(wzr, exception); |
| 1533 | } |
| 1534 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1535 | void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) { |
| 1536 | load->SetLocations(nullptr); |
| 1537 | } |
| 1538 | |
| 1539 | void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) { |
| 1540 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1541 | UNUSED(load); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1542 | } |
| 1543 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1544 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
| 1545 | LocationSummary* locations = |
| 1546 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 1547 | locations->SetOut(Location::RequiresRegister()); |
| 1548 | } |
| 1549 | |
| 1550 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
| 1551 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 1552 | codegen_->AddSlowPath(slow_path); |
| 1553 | |
| 1554 | Register out = OutputRegister(load); |
| 1555 | codegen_->LoadCurrentMethod(out); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 1556 | __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset())); |
| 1557 | __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1558 | __ Ldr(out, MemOperand(out.X(), CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 1559 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 1560 | __ Bind(slow_path->GetExitLabel()); |
| 1561 | } |
| 1562 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1563 | void LocationsBuilderARM64::VisitLocal(HLocal* local) { |
| 1564 | local->SetLocations(nullptr); |
| 1565 | } |
| 1566 | |
| 1567 | void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) { |
| 1568 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1569 | } |
| 1570 | |
| 1571 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 1572 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 1573 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1574 | } |
| 1575 | |
| 1576 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) { |
| 1577 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1578 | UNUSED(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1581 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 1582 | LocationSummary* locations = |
| 1583 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1584 | InvokeRuntimeCallingConvention calling_convention; |
| 1585 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1586 | } |
| 1587 | |
| 1588 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 1589 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 1590 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 1591 | instruction, |
| 1592 | instruction->GetDexPc()); |
| 1593 | } |
| 1594 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1595 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 1596 | LocationSummary* locations = |
| 1597 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1598 | switch (mul->GetResultType()) { |
| 1599 | case Primitive::kPrimInt: |
| 1600 | case Primitive::kPrimLong: |
| 1601 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1602 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1603 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1604 | break; |
| 1605 | |
| 1606 | case Primitive::kPrimFloat: |
| 1607 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1608 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1609 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1610 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1611 | break; |
| 1612 | |
| 1613 | default: |
| 1614 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 1619 | switch (mul->GetResultType()) { |
| 1620 | case Primitive::kPrimInt: |
| 1621 | case Primitive::kPrimLong: |
| 1622 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 1623 | break; |
| 1624 | |
| 1625 | case Primitive::kPrimFloat: |
| 1626 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1627 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1628 | break; |
| 1629 | |
| 1630 | default: |
| 1631 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 1632 | } |
| 1633 | } |
| 1634 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1635 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 1636 | LocationSummary* locations = |
| 1637 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1638 | switch (neg->GetResultType()) { |
| 1639 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1640 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1641 | locations->SetInAt(0, Location::RegisterOrConstant(neg->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1642 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1643 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1644 | |
| 1645 | case Primitive::kPrimFloat: |
| 1646 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1647 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1648 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1649 | break; |
| 1650 | |
| 1651 | default: |
| 1652 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 1657 | switch (neg->GetResultType()) { |
| 1658 | case Primitive::kPrimInt: |
| 1659 | case Primitive::kPrimLong: |
| 1660 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 1661 | break; |
| 1662 | |
| 1663 | case Primitive::kPrimFloat: |
| 1664 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1665 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1666 | break; |
| 1667 | |
| 1668 | default: |
| 1669 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 1674 | LocationSummary* locations = |
| 1675 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1676 | InvokeRuntimeCallingConvention calling_convention; |
| 1677 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1678 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1679 | locations->SetOut(LocationFrom(x0)); |
| 1680 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1681 | } |
| 1682 | |
| 1683 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 1684 | LocationSummary* locations = instruction->GetLocations(); |
| 1685 | InvokeRuntimeCallingConvention calling_convention; |
| 1686 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 1687 | DCHECK(type_index.Is(w0)); |
| 1688 | Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot); |
| 1689 | DCHECK(current_method.Is(w1)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1690 | codegen_->LoadCurrentMethod(current_method); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1691 | __ Mov(type_index, instruction->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1692 | codegen_->InvokeRuntime( |
| 1693 | QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1696 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 1697 | LocationSummary* locations = |
| 1698 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1699 | InvokeRuntimeCallingConvention calling_convention; |
| 1700 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1701 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1702 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1703 | } |
| 1704 | |
| 1705 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| 1706 | LocationSummary* locations = instruction->GetLocations(); |
| 1707 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 1708 | DCHECK(type_index.Is(w0)); |
| 1709 | Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot); |
| 1710 | DCHECK(current_method.Is(w1)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1711 | codegen_->LoadCurrentMethod(current_method); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1712 | __ Mov(type_index, instruction->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1713 | codegen_->InvokeRuntime( |
| 1714 | QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 1718 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 1719 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1720 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
| 1724 | switch (instruction->InputAt(0)->GetType()) { |
| 1725 | case Primitive::kPrimBoolean: |
| 1726 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), Operand(1)); |
| 1727 | break; |
| 1728 | |
| 1729 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1730 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 1731 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1732 | break; |
| 1733 | |
| 1734 | default: |
| 1735 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
| 1740 | LocationSummary* locations = |
| 1741 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1743 | if (instruction->HasUses()) { |
| 1744 | locations->SetOut(Location::SameAsFirstInput()); |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
| 1749 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
| 1750 | codegen_->AddSlowPath(slow_path); |
| 1751 | |
| 1752 | LocationSummary* locations = instruction->GetLocations(); |
| 1753 | Location obj = locations->InAt(0); |
| 1754 | if (obj.IsRegister()) { |
| 1755 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
| 1756 | } else { |
| 1757 | DCHECK(obj.IsConstant()) << obj; |
| 1758 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1759 | __ B(slow_path->GetEntryLabel()); |
| 1760 | } |
| 1761 | } |
| 1762 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1763 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 1764 | HandleBinaryOp(instruction); |
| 1765 | } |
| 1766 | |
| 1767 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 1768 | HandleBinaryOp(instruction); |
| 1769 | } |
| 1770 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1771 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 1772 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1773 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1774 | if (location.IsStackSlot()) { |
| 1775 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1776 | } else if (location.IsDoubleStackSlot()) { |
| 1777 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1778 | } |
| 1779 | locations->SetOut(location); |
| 1780 | } |
| 1781 | |
| 1782 | void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) { |
| 1783 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1784 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 1788 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1789 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1790 | locations->SetInAt(i, Location::Any()); |
| 1791 | } |
| 1792 | locations->SetOut(Location::Any()); |
| 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1796 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1797 | LOG(FATAL) << "Unreachable"; |
| 1798 | } |
| 1799 | |
| 1800 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 1801 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1802 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1803 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1807 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1808 | codegen_->GenerateFrameExit(); |
| 1809 | __ Br(lr); |
| 1810 | } |
| 1811 | |
| 1812 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 1813 | instruction->SetLocations(nullptr); |
| 1814 | } |
| 1815 | |
| 1816 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1817 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1818 | codegen_->GenerateFrameExit(); |
| 1819 | __ Br(lr); |
| 1820 | } |
| 1821 | |
| 1822 | void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) { |
| 1823 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 1824 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 1825 | switch (field_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1826 | case Primitive::kPrimNot: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1827 | case Primitive::kPrimBoolean: |
| 1828 | case Primitive::kPrimByte: |
| 1829 | case Primitive::kPrimChar: |
| 1830 | case Primitive::kPrimShort: |
| 1831 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1832 | case Primitive::kPrimFloat: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1833 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1834 | break; |
| 1835 | |
| 1836 | case Primitive::kPrimLong: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimDouble: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1838 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1839 | break; |
| 1840 | |
| 1841 | default: |
| 1842 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1847 | UNUSED(store); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1851 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1855 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1858 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 1859 | LocationSummary* locations = |
| 1860 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1861 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1862 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1863 | } |
| 1864 | |
| 1865 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 1866 | Register cls = InputRegisterAt(instruction, 0); |
| 1867 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1868 | codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), MemOperand(cls, offset)); |
| 1869 | } |
| 1870 | |
| 1871 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1872 | LocationSummary* locations = |
| 1873 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1875 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1878 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 1879 | CPURegister value = InputCPURegisterAt(instruction, 1); |
| 1880 | Register cls = InputRegisterAt(instruction, 0); |
| 1881 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1882 | Primitive::Type field_type = instruction->GetFieldType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1883 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1884 | codegen_->Store(field_type, value, MemOperand(cls, offset)); |
| 1885 | if (field_type == Primitive::kPrimNot) { |
| 1886 | codegen_->MarkGCCard(cls, Register(value)); |
| 1887 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1891 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1892 | } |
| 1893 | |
| 1894 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1895 | // TODO: Improve support for suspend checks. |
| 1896 | SuspendCheckSlowPathARM64* slow_path = |
| 1897 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, nullptr); |
| 1898 | codegen_->AddSlowPath(slow_path); |
| 1899 | |
| 1900 | __ Subs(wSuspend, wSuspend, 1); |
| 1901 | __ B(slow_path->GetEntryLabel(), le); |
| 1902 | __ Bind(slow_path->GetReturnLabel()); |
| 1903 | } |
| 1904 | |
| 1905 | void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) { |
| 1906 | temp->SetLocations(nullptr); |
| 1907 | } |
| 1908 | |
| 1909 | void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) { |
| 1910 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1911 | UNUSED(temp); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1912 | } |
| 1913 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1914 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 1915 | LocationSummary* locations = |
| 1916 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1917 | InvokeRuntimeCallingConvention calling_convention; |
| 1918 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1919 | } |
| 1920 | |
| 1921 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 1922 | codegen_->InvokeRuntime( |
| 1923 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc()); |
| 1924 | } |
| 1925 | |
| 1926 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1927 | LocationSummary* locations = |
| 1928 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1929 | Primitive::Type input_type = conversion->GetInputType(); |
| 1930 | Primitive::Type result_type = conversion->GetResultType(); |
| 1931 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 1932 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 1933 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 1934 | } |
| 1935 | |
| 1936 | if (IsFPType(input_type)) { |
| 1937 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1938 | } else { |
| 1939 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1940 | } |
| 1941 | |
| 1942 | if (IsFPType(result_type)) { |
| 1943 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1944 | } else { |
| 1945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1950 | Primitive::Type result_type = conversion->GetResultType(); |
| 1951 | Primitive::Type input_type = conversion->GetInputType(); |
| 1952 | |
| 1953 | DCHECK_NE(input_type, result_type); |
| 1954 | |
| 1955 | if (IsIntegralType(result_type) && IsIntegralType(input_type)) { |
| 1956 | int result_size = Primitive::ComponentSize(result_type); |
| 1957 | int input_size = Primitive::ComponentSize(input_type); |
| 1958 | int min_size = kBitsPerByte * std::min(result_size, input_size); |
| 1959 | if ((result_type == Primitive::kPrimChar) || |
| 1960 | ((input_type == Primitive::kPrimChar) && (result_size > input_size))) { |
| 1961 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, min_size); |
| 1962 | } else { |
| 1963 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, min_size); |
| 1964 | } |
| 1965 | return; |
| 1966 | } |
| 1967 | |
| 1968 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 1969 | << " to " << result_type; |
| 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 1973 | HandleBinaryOp(instruction); |
| 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 1977 | HandleBinaryOp(instruction); |
| 1978 | } |
| 1979 | |
| 1980 | #undef __ |
| 1981 | #undef QUICK_ENTRY_POINT |
| 1982 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1983 | } // namespace arm64 |
| 1984 | } // namespace art |