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 | |
| 51 | bool Is64BitType(Primitive::Type type) { |
| 52 | return type == Primitive::kPrimLong || type == Primitive::kPrimDouble; |
| 53 | } |
| 54 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 55 | // Convenience helpers to ease conversion to and from VIXL operands. |
| 56 | |
| 57 | int VIXLRegCodeFromART(int code) { |
| 58 | // TODO: static check? |
| 59 | DCHECK_EQ(SP, 31); |
| 60 | DCHECK_EQ(WSP, 31); |
| 61 | DCHECK_EQ(XZR, 32); |
| 62 | DCHECK_EQ(WZR, 32); |
| 63 | if (code == SP) { |
| 64 | return vixl::kSPRegInternalCode; |
| 65 | } |
| 66 | if (code == XZR) { |
| 67 | return vixl::kZeroRegCode; |
| 68 | } |
| 69 | return code; |
| 70 | } |
| 71 | |
| 72 | int ARTRegCodeFromVIXL(int code) { |
| 73 | // TODO: static check? |
| 74 | DCHECK_EQ(SP, 31); |
| 75 | DCHECK_EQ(WSP, 31); |
| 76 | DCHECK_EQ(XZR, 32); |
| 77 | DCHECK_EQ(WZR, 32); |
| 78 | if (code == vixl::kSPRegInternalCode) { |
| 79 | return SP; |
| 80 | } |
| 81 | if (code == vixl::kZeroRegCode) { |
| 82 | return XZR; |
| 83 | } |
| 84 | return code; |
| 85 | } |
| 86 | |
| 87 | Register XRegisterFrom(Location location) { |
| 88 | return Register::XRegFromCode(VIXLRegCodeFromART(location.reg())); |
| 89 | } |
| 90 | |
| 91 | Register WRegisterFrom(Location location) { |
| 92 | return Register::WRegFromCode(VIXLRegCodeFromART(location.reg())); |
| 93 | } |
| 94 | |
| 95 | Register RegisterFrom(Location location, Primitive::Type type) { |
| 96 | DCHECK(type != Primitive::kPrimVoid && !IsFPType(type)); |
| 97 | return type == Primitive::kPrimLong ? XRegisterFrom(location) : WRegisterFrom(location); |
| 98 | } |
| 99 | |
| 100 | Register OutputRegister(HInstruction* instr) { |
| 101 | return RegisterFrom(instr->GetLocations()->Out(), instr->GetType()); |
| 102 | } |
| 103 | |
| 104 | Register InputRegisterAt(HInstruction* instr, int input_index) { |
| 105 | return RegisterFrom(instr->GetLocations()->InAt(input_index), |
| 106 | instr->InputAt(input_index)->GetType()); |
| 107 | } |
| 108 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 109 | FPRegister DRegisterFrom(Location location) { |
| 110 | return FPRegister::DRegFromCode(location.reg()); |
| 111 | } |
| 112 | |
| 113 | FPRegister SRegisterFrom(Location location) { |
| 114 | return FPRegister::SRegFromCode(location.reg()); |
| 115 | } |
| 116 | |
| 117 | FPRegister FPRegisterFrom(Location location, Primitive::Type type) { |
| 118 | DCHECK(IsFPType(type)); |
| 119 | return type == Primitive::kPrimDouble ? DRegisterFrom(location) : SRegisterFrom(location); |
| 120 | } |
| 121 | |
| 122 | FPRegister OutputFPRegister(HInstruction* instr) { |
| 123 | return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType()); |
| 124 | } |
| 125 | |
| 126 | FPRegister InputFPRegisterAt(HInstruction* instr, int input_index) { |
| 127 | return FPRegisterFrom(instr->GetLocations()->InAt(input_index), |
| 128 | instr->InputAt(input_index)->GetType()); |
| 129 | } |
| 130 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 131 | int64_t Int64ConstantFrom(Location location) { |
| 132 | HConstant* instr = location.GetConstant(); |
| 133 | return instr->IsIntConstant() ? instr->AsIntConstant()->GetValue() |
| 134 | : instr->AsLongConstant()->GetValue(); |
| 135 | } |
| 136 | |
| 137 | Operand OperandFrom(Location location, Primitive::Type type) { |
| 138 | if (location.IsRegister()) { |
| 139 | return Operand(RegisterFrom(location, type)); |
| 140 | } else { |
| 141 | return Operand(Int64ConstantFrom(location)); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | Operand InputOperandAt(HInstruction* instr, int input_index) { |
| 146 | return OperandFrom(instr->GetLocations()->InAt(input_index), |
| 147 | instr->InputAt(input_index)->GetType()); |
| 148 | } |
| 149 | |
| 150 | MemOperand StackOperandFrom(Location location) { |
| 151 | return MemOperand(sp, location.GetStackIndex()); |
| 152 | } |
| 153 | |
| 154 | MemOperand HeapOperand(const Register& base, Offset offset) { |
| 155 | // A heap reference must be 32bit, so fit in a W register. |
| 156 | DCHECK(base.IsW()); |
| 157 | return MemOperand(base.X(), offset.SizeValue()); |
| 158 | } |
| 159 | |
| 160 | MemOperand HeapOperandFrom(Location location, Primitive::Type type, Offset offset) { |
| 161 | return HeapOperand(RegisterFrom(location, type), offset); |
| 162 | } |
| 163 | |
| 164 | Location LocationFrom(const Register& reg) { |
| 165 | return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.code())); |
| 166 | } |
| 167 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 168 | Location LocationFrom(const FPRegister& fpreg) { |
| 169 | return Location::FpuRegisterLocation(fpreg.code()); |
| 170 | } |
| 171 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 172 | } // namespace |
| 173 | |
| 174 | inline Condition ARM64Condition(IfCondition cond) { |
| 175 | switch (cond) { |
| 176 | case kCondEQ: return eq; |
| 177 | case kCondNE: return ne; |
| 178 | case kCondLT: return lt; |
| 179 | case kCondLE: return le; |
| 180 | case kCondGT: return gt; |
| 181 | case kCondGE: return ge; |
| 182 | default: |
| 183 | LOG(FATAL) << "Unknown if condition"; |
| 184 | } |
| 185 | return nv; // Unreachable. |
| 186 | } |
| 187 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 188 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
| 189 | DCHECK_NE(return_type, Primitive::kPrimVoid); |
| 190 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 191 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 192 | // but we use the exact registers for clarity. |
| 193 | if (return_type == Primitive::kPrimFloat) { |
| 194 | return LocationFrom(s0); |
| 195 | } else if (return_type == Primitive::kPrimDouble) { |
| 196 | return LocationFrom(d0); |
| 197 | } else if (return_type == Primitive::kPrimLong) { |
| 198 | return LocationFrom(x0); |
| 199 | } else { |
| 200 | return LocationFrom(w0); |
| 201 | } |
| 202 | } |
| 203 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 204 | static const Register kRuntimeParameterCoreRegisters[] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 205 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 206 | arraysize(kRuntimeParameterCoreRegisters); |
| 207 | static const FPRegister kRuntimeParameterFpuRegisters[] = { }; |
| 208 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
| 209 | |
| 210 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FPRegister> { |
| 211 | public: |
| 212 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 213 | |
| 214 | InvokeRuntimeCallingConvention() |
| 215 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 216 | kRuntimeParameterCoreRegistersLength, |
| 217 | kRuntimeParameterFpuRegisters, |
| 218 | kRuntimeParameterFpuRegistersLength) {} |
| 219 | |
| 220 | Location GetReturnLocation(Primitive::Type return_type); |
| 221 | |
| 222 | private: |
| 223 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 224 | }; |
| 225 | |
| 226 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 227 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | #define __ reinterpret_cast<Arm64Assembler*>(codegen->GetAssembler())->vixl_masm_-> |
| 231 | |
| 232 | class SlowPathCodeARM64 : public SlowPathCode { |
| 233 | public: |
| 234 | SlowPathCodeARM64() : entry_label_(), exit_label_() {} |
| 235 | |
| 236 | vixl::Label* GetEntryLabel() { return &entry_label_; } |
| 237 | vixl::Label* GetExitLabel() { return &exit_label_; } |
| 238 | |
| 239 | private: |
| 240 | vixl::Label entry_label_; |
| 241 | vixl::Label exit_label_; |
| 242 | |
| 243 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM64); |
| 244 | }; |
| 245 | |
| 246 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 247 | public: |
| 248 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction, |
| 249 | Location index_location, |
| 250 | Location length_location) |
| 251 | : instruction_(instruction), |
| 252 | index_location_(index_location), |
| 253 | length_location_(length_location) {} |
| 254 | |
| 255 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 256 | CodeGeneratorARM64* arm64_codegen = reinterpret_cast<CodeGeneratorARM64*>(codegen); |
| 257 | __ Bind(GetEntryLabel()); |
| 258 | InvokeRuntimeCallingConvention calling_convention; |
| 259 | arm64_codegen->MoveHelper(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 260 | index_location_, Primitive::kPrimInt); |
| 261 | arm64_codegen->MoveHelper(LocationFrom(calling_convention.GetRegisterAt(1)), |
| 262 | length_location_, Primitive::kPrimInt); |
| 263 | size_t offset = QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pThrowArrayBounds).SizeValue(); |
| 264 | __ Ldr(lr, MemOperand(tr, offset)); |
| 265 | __ Blr(lr); |
| 266 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 267 | } |
| 268 | |
| 269 | private: |
| 270 | HBoundsCheck* const instruction_; |
| 271 | const Location index_location_; |
| 272 | const Location length_location_; |
| 273 | |
| 274 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 275 | }; |
| 276 | |
| 277 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 278 | public: |
| 279 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {} |
| 280 | |
| 281 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 282 | __ Bind(GetEntryLabel()); |
| 283 | int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pThrowNullPointer).Int32Value(); |
| 284 | __ Ldr(lr, MemOperand(tr, offset)); |
| 285 | __ Blr(lr); |
| 286 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 287 | } |
| 288 | |
| 289 | private: |
| 290 | HNullCheck* const instruction_; |
| 291 | |
| 292 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 293 | }; |
| 294 | |
| 295 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 296 | public: |
| 297 | explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction, |
| 298 | HBasicBlock* successor) |
| 299 | : instruction_(instruction), successor_(successor) {} |
| 300 | |
| 301 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 302 | size_t offset = QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pTestSuspend).SizeValue(); |
| 303 | __ Bind(GetEntryLabel()); |
| 304 | __ Ldr(lr, MemOperand(tr, offset)); |
| 305 | __ Blr(lr); |
| 306 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 307 | __ B(GetReturnLabel()); |
| 308 | } |
| 309 | |
| 310 | vixl::Label* GetReturnLabel() { |
| 311 | DCHECK(successor_ == nullptr); |
| 312 | return &return_label_; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | private: |
| 317 | HSuspendCheck* const instruction_; |
| 318 | // If not null, the block to branch to after the suspend check. |
| 319 | HBasicBlock* const successor_; |
| 320 | |
| 321 | // If `successor_` is null, the label to branch to after the suspend check. |
| 322 | vixl::Label return_label_; |
| 323 | |
| 324 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 325 | }; |
| 326 | |
| 327 | #undef __ |
| 328 | |
| 329 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 330 | Location next_location; |
| 331 | if (type == Primitive::kPrimVoid) { |
| 332 | LOG(FATAL) << "Unreachable type " << type; |
| 333 | } |
| 334 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 335 | if (IsFPType(type) && (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 336 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++)); |
| 337 | } else if (!IsFPType(type) && (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 338 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 339 | } else { |
| 340 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 341 | next_location = Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 342 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 345 | // Space on the stack is reserved for all arguments. |
| 346 | stack_index_ += Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 347 | return next_location; |
| 348 | } |
| 349 | |
| 350 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph) |
| 351 | : CodeGenerator(graph, |
| 352 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 353 | kNumberOfAllocatableFPRegisters, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 354 | kNumberOfAllocatableRegisterPairs), |
| 355 | block_labels_(nullptr), |
| 356 | location_builder_(graph, this), |
| 357 | instruction_visitor_(graph, this) {} |
| 358 | |
| 359 | #define __ reinterpret_cast<Arm64Assembler*>(GetAssembler())->vixl_masm_-> |
| 360 | |
| 361 | void CodeGeneratorARM64::GenerateFrameEntry() { |
| 362 | // TODO: Add proper support for the stack overflow check. |
| 363 | UseScratchRegisterScope temps(assembler_.vixl_masm_); |
| 364 | Register temp = temps.AcquireX(); |
| 365 | __ Add(temp, sp, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
| 366 | __ Ldr(temp, MemOperand(temp, 0)); |
| 367 | RecordPcInfo(nullptr, 0); |
| 368 | |
| 369 | CPURegList preserved_regs = GetFramePreservedRegisters(); |
| 370 | int frame_size = GetFrameSize(); |
| 371 | core_spill_mask_ |= preserved_regs.list(); |
| 372 | |
| 373 | __ Str(w0, MemOperand(sp, -frame_size, PreIndex)); |
| 374 | __ PokeCPURegList(preserved_regs, frame_size - preserved_regs.TotalSizeInBytes()); |
| 375 | |
| 376 | // Stack layout: |
| 377 | // sp[frame_size - 8] : lr. |
| 378 | // ... : other preserved registers. |
| 379 | // sp[frame_size - regs_size]: first preserved register. |
| 380 | // ... : reserved frame space. |
| 381 | // sp[0] : context pointer. |
| 382 | } |
| 383 | |
| 384 | void CodeGeneratorARM64::GenerateFrameExit() { |
| 385 | int frame_size = GetFrameSize(); |
| 386 | CPURegList preserved_regs = GetFramePreservedRegisters(); |
| 387 | __ PeekCPURegList(preserved_regs, frame_size - preserved_regs.TotalSizeInBytes()); |
| 388 | __ Drop(frame_size); |
| 389 | } |
| 390 | |
| 391 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 392 | __ Bind(GetLabelOf(block)); |
| 393 | } |
| 394 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 395 | void CodeGeneratorARM64::Move(HInstruction* instruction, |
| 396 | Location location, |
| 397 | HInstruction* move_for) { |
| 398 | LocationSummary* locations = instruction->GetLocations(); |
| 399 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | Primitive::Type type = instruction->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 404 | DCHECK_NE(type, Primitive::kPrimVoid); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 405 | |
| 406 | if (instruction->IsIntConstant() || instruction->IsLongConstant()) { |
| 407 | int64_t value = instruction->IsIntConstant() ? instruction->AsIntConstant()->GetValue() |
| 408 | : instruction->AsLongConstant()->GetValue(); |
| 409 | if (location.IsRegister()) { |
| 410 | Register dst = RegisterFrom(location, type); |
| 411 | DCHECK((instruction->IsIntConstant() && dst.Is32Bits()) || |
| 412 | (instruction->IsLongConstant() && dst.Is64Bits())); |
| 413 | __ Mov(dst, value); |
| 414 | } else { |
| 415 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); |
| 416 | UseScratchRegisterScope temps(assembler_.vixl_masm_); |
| 417 | Register temp = instruction->IsIntConstant() ? temps.AcquireW() : temps.AcquireX(); |
| 418 | __ Mov(temp, value); |
| 419 | __ Str(temp, StackOperandFrom(location)); |
| 420 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 421 | } else if (instruction->IsTemporary()) { |
| 422 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 423 | MoveHelper(location, temp_location, type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | } else if (instruction->IsLoadLocal()) { |
| 425 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 426 | if (Is64BitType(type)) { |
| 427 | MoveHelper(location, Location::DoubleStackSlot(stack_slot), type); |
| 428 | } else { |
| 429 | MoveHelper(location, Location::StackSlot(stack_slot), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | } else { |
| 433 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
| 434 | MoveHelper(location, locations->Out(), type); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | size_t CodeGeneratorARM64::FrameEntrySpillSize() const { |
| 439 | return GetFramePreservedRegistersSize(); |
| 440 | } |
| 441 | |
| 442 | Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const { |
| 443 | Primitive::Type type = load->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 444 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 445 | switch (type) { |
| 446 | case Primitive::kPrimNot: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 447 | case Primitive::kPrimInt: |
| 448 | case Primitive::kPrimFloat: |
| 449 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 450 | |
| 451 | case Primitive::kPrimLong: |
| 452 | case Primitive::kPrimDouble: |
| 453 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 454 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 455 | case Primitive::kPrimBoolean: |
| 456 | case Primitive::kPrimByte: |
| 457 | case Primitive::kPrimChar: |
| 458 | case Primitive::kPrimShort: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 459 | case Primitive::kPrimVoid: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 460 | LOG(FATAL) << "Unexpected type " << type; |
| 461 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 462 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 463 | LOG(FATAL) << "Unreachable"; |
| 464 | return Location::NoLocation(); |
| 465 | } |
| 466 | |
| 467 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value) { |
| 468 | UseScratchRegisterScope temps(assembler_.vixl_masm_); |
| 469 | Register card = temps.AcquireX(); |
| 470 | Register temp = temps.AcquireX(); |
| 471 | vixl::Label done; |
| 472 | __ Cbz(value, &done); |
| 473 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 474 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 475 | __ Strb(card, MemOperand(card, temp)); |
| 476 | __ Bind(&done); |
| 477 | } |
| 478 | |
| 479 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
| 480 | // Block reserved registers: |
| 481 | // ip0 (VIXL temporary) |
| 482 | // ip1 (VIXL temporary) |
| 483 | // xSuspend (Suspend counter) |
| 484 | // lr |
| 485 | // 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] | 486 | // TODO: Avoid blocking callee-saved registers, and instead preserve them |
| 487 | // where necessary. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 488 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 489 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 490 | reserved_core_registers.Combine(quick_callee_saved_registers); |
| 491 | while (!reserved_core_registers.IsEmpty()) { |
| 492 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 493 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 494 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
| 495 | reserved_fp_registers.Combine(CPURegList::GetCalleeSavedFP()); |
| 496 | while (!reserved_core_registers.IsEmpty()) { |
| 497 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 498 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const { |
| 502 | if (type == Primitive::kPrimVoid) { |
| 503 | LOG(FATAL) << "Unreachable type " << type; |
| 504 | } |
| 505 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 506 | if (IsFPType(type)) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 507 | ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters); |
| 508 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 509 | return Location::FpuRegisterLocation(reg); |
| 510 | } else { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 511 | ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters); |
| 512 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 513 | return Location::RegisterLocation(reg); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 518 | stream << Arm64ManagedRegister::FromXRegister(XRegister(reg)); |
| 519 | } |
| 520 | |
| 521 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 522 | stream << Arm64ManagedRegister::FromDRegister(DRegister(reg)); |
| 523 | } |
| 524 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 525 | void CodeGeneratorARM64::MoveHelper(Location destination, |
| 526 | Location source, |
| 527 | Primitive::Type type) { |
| 528 | if (source.Equals(destination)) { |
| 529 | return; |
| 530 | } |
| 531 | if (destination.IsRegister()) { |
| 532 | Register dst = RegisterFrom(destination, type); |
| 533 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 534 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 535 | __ Ldr(dst, StackOperandFrom(source)); |
| 536 | } else { |
| 537 | __ Mov(dst, OperandFrom(source, type)); |
| 538 | } |
| 539 | } else if (destination.IsFpuRegister()) { |
| 540 | FPRegister dst = FPRegisterFrom(destination, type); |
| 541 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 542 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 543 | __ Ldr(dst, StackOperandFrom(source)); |
| 544 | } else if (source.IsFpuRegister()) { |
| 545 | __ Fmov(dst, FPRegisterFrom(source, type)); |
| 546 | } else { |
| 547 | HConstant* cst = source.GetConstant(); |
| 548 | if (cst->IsFloatConstant()) { |
| 549 | __ Fmov(dst, cst->AsFloatConstant()->GetValue()); |
| 550 | } else { |
| 551 | DCHECK(cst->IsDoubleConstant()); |
| 552 | __ Fmov(dst, cst->AsDoubleConstant()->GetValue()); |
| 553 | } |
| 554 | } |
| 555 | } else { |
| 556 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 557 | if (source.IsRegister()) { |
| 558 | __ Str(RegisterFrom(source, type), StackOperandFrom(destination)); |
| 559 | } else if (source.IsFpuRegister()) { |
| 560 | __ Str(FPRegisterFrom(source, type), StackOperandFrom(destination)); |
| 561 | } else { |
| 562 | UseScratchRegisterScope temps(assembler_.vixl_masm_); |
| 563 | Register temp = destination.IsDoubleStackSlot() ? temps.AcquireX() : temps.AcquireW(); |
| 564 | __ Ldr(temp, StackOperandFrom(source)); |
| 565 | __ Str(temp, StackOperandFrom(destination)); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | void CodeGeneratorARM64::Load(Primitive::Type type, |
| 571 | vixl::Register dst, |
| 572 | const vixl::MemOperand& src) { |
| 573 | switch (type) { |
| 574 | case Primitive::kPrimBoolean: |
| 575 | __ Ldrb(dst, src); |
| 576 | break; |
| 577 | case Primitive::kPrimByte: |
| 578 | __ Ldrsb(dst, src); |
| 579 | break; |
| 580 | case Primitive::kPrimShort: |
| 581 | __ Ldrsh(dst, src); |
| 582 | break; |
| 583 | case Primitive::kPrimChar: |
| 584 | __ Ldrh(dst, src); |
| 585 | break; |
| 586 | case Primitive::kPrimInt: |
| 587 | case Primitive::kPrimNot: |
| 588 | case Primitive::kPrimLong: |
| 589 | DCHECK(dst.Is64Bits() == (type == Primitive::kPrimLong)); |
| 590 | __ Ldr(dst, src); |
| 591 | break; |
| 592 | case Primitive::kPrimFloat: |
| 593 | case Primitive::kPrimDouble: |
| 594 | case Primitive::kPrimVoid: |
| 595 | LOG(FATAL) << "Unreachable type " << type; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | void CodeGeneratorARM64::Store(Primitive::Type type, |
| 600 | vixl::Register rt, |
| 601 | const vixl::MemOperand& dst) { |
| 602 | switch (type) { |
| 603 | case Primitive::kPrimBoolean: |
| 604 | case Primitive::kPrimByte: |
| 605 | __ Strb(rt, dst); |
| 606 | break; |
| 607 | case Primitive::kPrimChar: |
| 608 | case Primitive::kPrimShort: |
| 609 | __ Strh(rt, dst); |
| 610 | break; |
| 611 | case Primitive::kPrimInt: |
| 612 | case Primitive::kPrimNot: |
| 613 | case Primitive::kPrimLong: |
| 614 | DCHECK(rt.Is64Bits() == (type == Primitive::kPrimLong)); |
| 615 | __ Str(rt, dst); |
| 616 | break; |
| 617 | case Primitive::kPrimFloat: |
| 618 | case Primitive::kPrimDouble: |
| 619 | case Primitive::kPrimVoid: |
| 620 | LOG(FATAL) << "Unreachable type " << type; |
| 621 | } |
| 622 | } |
| 623 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 624 | #undef __ |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 625 | #define __ GetAssembler()->vixl_masm_-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 626 | |
| 627 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 628 | CodeGeneratorARM64* codegen) |
| 629 | : HGraphVisitor(graph), |
| 630 | assembler_(codegen->GetAssembler()), |
| 631 | codegen_(codegen) {} |
| 632 | |
| 633 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 634 | M(ClinitCheck) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 635 | M(DivZeroCheck) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 636 | M(InvokeInterface) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 637 | M(LoadClass) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 638 | M(LoadException) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 639 | M(LoadString) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 640 | M(ParallelMove) \ |
| 641 | M(StaticFieldGet) \ |
| 642 | M(StaticFieldSet) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 643 | M(Throw) \ |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 644 | M(TypeCheck) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 645 | M(TypeConversion) \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 646 | |
| 647 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 648 | |
| 649 | enum UnimplementedInstructionBreakCode { |
| 650 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 651 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 652 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 653 | }; |
| 654 | |
| 655 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
| 656 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \ |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 657 | UNUSED(instr); \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 658 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 659 | } \ |
| 660 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 661 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 662 | locations->SetOut(Location::Any()); \ |
| 663 | } |
| 664 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 665 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 666 | |
| 667 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
| 668 | |
| 669 | void LocationsBuilderARM64::HandleAddSub(HBinaryOperation* instr) { |
| 670 | DCHECK(instr->IsAdd() || instr->IsSub()); |
| 671 | DCHECK_EQ(instr->InputCount(), 2U); |
| 672 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 673 | Primitive::Type type = instr->GetResultType(); |
| 674 | switch (type) { |
| 675 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 676 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 677 | locations->SetInAt(0, Location::RequiresRegister()); |
| 678 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 679 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 680 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 681 | |
| 682 | case Primitive::kPrimFloat: |
| 683 | case Primitive::kPrimDouble: |
| 684 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 685 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 686 | locations->SetOut(Location::RequiresFpuRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 687 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 688 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 689 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 690 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
| 694 | void InstructionCodeGeneratorARM64::HandleAddSub(HBinaryOperation* instr) { |
| 695 | DCHECK(instr->IsAdd() || instr->IsSub()); |
| 696 | |
| 697 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 698 | |
| 699 | switch (type) { |
| 700 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 701 | case Primitive::kPrimLong: { |
| 702 | Register dst = OutputRegister(instr); |
| 703 | Register lhs = InputRegisterAt(instr, 0); |
| 704 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 705 | if (instr->IsAdd()) { |
| 706 | __ Add(dst, lhs, rhs); |
| 707 | } else { |
| 708 | __ Sub(dst, lhs, rhs); |
| 709 | } |
| 710 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 711 | } |
| 712 | case Primitive::kPrimFloat: |
| 713 | case Primitive::kPrimDouble: { |
| 714 | FPRegister dst = OutputFPRegister(instr); |
| 715 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 716 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 717 | if (instr->IsAdd()) { |
| 718 | __ Fadd(dst, lhs, rhs); |
| 719 | } else { |
| 720 | __ Fsub(dst, lhs, rhs); |
| 721 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 722 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 723 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 724 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 725 | LOG(FATAL) << "Unexpected add/sub type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
| 730 | HandleAddSub(instruction); |
| 731 | } |
| 732 | |
| 733 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
| 734 | HandleAddSub(instruction); |
| 735 | } |
| 736 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 737 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| 738 | LocationSummary* locations = |
| 739 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 740 | locations->SetInAt(0, Location::RequiresRegister()); |
| 741 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 742 | locations->SetOut(Location::RequiresRegister()); |
| 743 | } |
| 744 | |
| 745 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| 746 | LocationSummary* locations = instruction->GetLocations(); |
| 747 | Primitive::Type type = instruction->GetType(); |
| 748 | Register obj = InputRegisterAt(instruction, 0); |
| 749 | Register out = OutputRegister(instruction); |
| 750 | Location index = locations->InAt(1); |
| 751 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
| 752 | MemOperand source(obj); |
| 753 | UseScratchRegisterScope temps(GetAssembler()->vixl_masm_); |
| 754 | |
| 755 | if (index.IsConstant()) { |
| 756 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 757 | source = MemOperand(obj, offset); |
| 758 | } else { |
| 759 | Register temp = temps.AcquireSameSizeAs(obj); |
| 760 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 761 | __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type))); |
| 762 | source = MemOperand(temp, offset); |
| 763 | } |
| 764 | |
| 765 | codegen_->Load(type, out, source); |
| 766 | } |
| 767 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 768 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 769 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 770 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 771 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
| 775 | __ Ldr(OutputRegister(instruction), |
| 776 | HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset())); |
| 777 | } |
| 778 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 779 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
| 780 | Primitive::Type value_type = instruction->GetComponentType(); |
| 781 | bool is_object = value_type == Primitive::kPrimNot; |
| 782 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 783 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 784 | if (is_object) { |
| 785 | InvokeRuntimeCallingConvention calling_convention; |
| 786 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 787 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 788 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 789 | } else { |
| 790 | locations->SetInAt(0, Location::RequiresRegister()); |
| 791 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 792 | locations->SetInAt(2, Location::RequiresRegister()); |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 797 | Primitive::Type value_type = instruction->GetComponentType(); |
| 798 | if (value_type == Primitive::kPrimNot) { |
| 799 | __ Ldr(lr, MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAputObject).Int32Value())); |
| 800 | __ Blr(lr); |
| 801 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 802 | DCHECK(!codegen_->IsLeafMethod()); |
| 803 | } else { |
| 804 | LocationSummary* locations = instruction->GetLocations(); |
| 805 | Register obj = InputRegisterAt(instruction, 0); |
| 806 | Register value = InputRegisterAt(instruction, 2); |
| 807 | Location index = locations->InAt(1); |
| 808 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 809 | MemOperand destination(obj); |
| 810 | UseScratchRegisterScope temps(GetAssembler()->vixl_masm_); |
| 811 | |
| 812 | if (index.IsConstant()) { |
| 813 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 814 | destination = MemOperand(obj, offset); |
| 815 | } else { |
| 816 | Register temp = temps.AcquireSameSizeAs(obj); |
| 817 | Register index_reg = InputRegisterAt(instruction, 1); |
| 818 | __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type))); |
| 819 | destination = MemOperand(temp, offset); |
| 820 | } |
| 821 | |
| 822 | codegen_->Store(value_type, value, destination); |
| 823 | } |
| 824 | } |
| 825 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 826 | void LocationsBuilderARM64::VisitCompare(HCompare* instruction) { |
| 827 | LocationSummary* locations = |
| 828 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 830 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 831 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* instruction) { |
| 835 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 836 | |
| 837 | DCHECK_EQ(in_type, Primitive::kPrimLong); |
| 838 | switch (in_type) { |
| 839 | case Primitive::kPrimLong: { |
| 840 | vixl::Label done; |
| 841 | Register result = OutputRegister(instruction); |
| 842 | Register left = InputRegisterAt(instruction, 0); |
| 843 | Operand right = InputOperandAt(instruction, 1); |
| 844 | __ Subs(result, left, right); |
| 845 | __ B(eq, &done); |
| 846 | __ Mov(result, 1); |
| 847 | __ Cneg(result, result, le); |
| 848 | __ Bind(&done); |
| 849 | break; |
| 850 | } |
| 851 | default: |
| 852 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | void LocationsBuilderARM64::VisitCondition(HCondition* instruction) { |
| 857 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 858 | locations->SetInAt(0, Location::RequiresRegister()); |
| 859 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 860 | if (instruction->NeedsMaterialization()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 861 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
| 865 | void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) { |
| 866 | if (!instruction->NeedsMaterialization()) { |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | LocationSummary* locations = instruction->GetLocations(); |
| 871 | Register lhs = InputRegisterAt(instruction, 0); |
| 872 | Operand rhs = InputOperandAt(instruction, 1); |
| 873 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
| 874 | Condition cond = ARM64Condition(instruction->GetCondition()); |
| 875 | |
| 876 | __ Cmp(lhs, rhs); |
| 877 | __ Csel(res, vixl::Assembler::AppropriateZeroRegFor(res), Operand(1), InvertCondition(cond)); |
| 878 | } |
| 879 | |
| 880 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 881 | M(Equal) \ |
| 882 | M(NotEqual) \ |
| 883 | M(LessThan) \ |
| 884 | M(LessThanOrEqual) \ |
| 885 | M(GreaterThan) \ |
| 886 | M(GreaterThanOrEqual) |
| 887 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| 888 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \ |
| 889 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } |
| 890 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
| 891 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 892 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 893 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 894 | LocationSummary* locations = |
| 895 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 896 | switch (div->GetResultType()) { |
| 897 | case Primitive::kPrimInt: |
| 898 | case Primitive::kPrimLong: |
| 899 | locations->SetInAt(0, Location::RequiresRegister()); |
| 900 | locations->SetInAt(1, Location::RequiresRegister()); |
| 901 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 902 | break; |
| 903 | |
| 904 | case Primitive::kPrimFloat: |
| 905 | case Primitive::kPrimDouble: |
| 906 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 907 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 908 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 909 | break; |
| 910 | |
| 911 | default: |
| 912 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 917 | Primitive::Type type = div->GetResultType(); |
| 918 | switch (type) { |
| 919 | case Primitive::kPrimInt: |
| 920 | case Primitive::kPrimLong: |
| 921 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 922 | break; |
| 923 | |
| 924 | case Primitive::kPrimFloat: |
| 925 | case Primitive::kPrimDouble: |
| 926 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 927 | break; |
| 928 | |
| 929 | default: |
| 930 | LOG(FATAL) << "Unexpected div type " << type; |
| 931 | } |
| 932 | } |
| 933 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 934 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 935 | LocationSummary* locations = |
| 936 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 937 | locations->SetOut(Location::ConstantLocation(constant)); |
| 938 | } |
| 939 | |
| 940 | void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 941 | UNUSED(constant); |
| 942 | // Will be generated at use site. |
| 943 | } |
| 944 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 945 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 946 | exit->SetLocations(nullptr); |
| 947 | } |
| 948 | |
| 949 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 950 | UNUSED(exit); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 951 | if (kIsDebugBuild) { |
| 952 | down_cast<Arm64Assembler*>(GetAssembler())->Comment("Unreachable"); |
| 953 | __ Brk(0); // TODO: Introduce special markers for such code locations. |
| 954 | } |
| 955 | } |
| 956 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 957 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 958 | LocationSummary* locations = |
| 959 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 960 | locations->SetOut(Location::ConstantLocation(constant)); |
| 961 | } |
| 962 | |
| 963 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 964 | UNUSED(constant); |
| 965 | // Will be generated at use site. |
| 966 | } |
| 967 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 968 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 969 | got->SetLocations(nullptr); |
| 970 | } |
| 971 | |
| 972 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 973 | HBasicBlock* successor = got->GetSuccessor(); |
| 974 | // TODO: Support for suspend checks emission. |
| 975 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| 976 | __ B(codegen_->GetLabelOf(successor)); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 981 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 982 | HInstruction* cond = if_instr->InputAt(0); |
| 983 | DCHECK(cond->IsCondition()); |
| 984 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 985 | locations->SetInAt(0, Location::RequiresRegister()); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| 990 | HInstruction* cond = if_instr->InputAt(0); |
| 991 | DCHECK(cond->IsCondition()); |
| 992 | HCondition* condition = cond->AsCondition(); |
| 993 | vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 994 | vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 995 | |
| 996 | // TODO: Support constant condition input in VisitIf. |
| 997 | |
| 998 | if (condition->NeedsMaterialization()) { |
| 999 | // The condition instruction has been materialized, compare the output to 0. |
| 1000 | Location cond_val = if_instr->GetLocations()->InAt(0); |
| 1001 | DCHECK(cond_val.IsRegister()); |
| 1002 | __ Cbnz(InputRegisterAt(if_instr, 0), true_target); |
| 1003 | |
| 1004 | } else { |
| 1005 | // The condition instruction has not been materialized, use its inputs as |
| 1006 | // the comparison and its condition as the branch condition. |
| 1007 | Register lhs = InputRegisterAt(condition, 0); |
| 1008 | Operand rhs = InputOperandAt(condition, 1); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1009 | Condition arm64_cond = ARM64Condition(condition->GetCondition()); |
| 1010 | if ((arm64_cond == eq || arm64_cond == ne) && rhs.IsImmediate() && (rhs.immediate() == 0)) { |
| 1011 | if (arm64_cond == eq) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1012 | __ Cbz(lhs, true_target); |
| 1013 | } else { |
| 1014 | __ Cbnz(lhs, true_target); |
| 1015 | } |
| 1016 | } else { |
| 1017 | __ Cmp(lhs, rhs); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1018 | __ B(arm64_cond, true_target); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) { |
| 1023 | __ B(false_target); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1028 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1029 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1030 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1034 | MemOperand field = MemOperand(InputRegisterAt(instruction, 0), |
| 1035 | instruction->GetFieldOffset().Uint32Value()); |
| 1036 | codegen_->Load(instruction->GetType(), OutputRegister(instruction), field); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1040 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1041 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1042 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1043 | } |
| 1044 | |
| 1045 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1046 | Primitive::Type field_type = instruction->GetFieldType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1047 | Register value = InputRegisterAt(instruction, 1); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1048 | Register obj = InputRegisterAt(instruction, 0); |
| 1049 | codegen_->Store(field_type, value, MemOperand(obj, instruction->GetFieldOffset().Uint32Value())); |
| 1050 | if (field_type == Primitive::kPrimNot) { |
| 1051 | codegen_->MarkGCCard(obj, value); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 1056 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 1057 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1058 | } |
| 1059 | |
| 1060 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) { |
| 1061 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1062 | UNUSED(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | void LocationsBuilderARM64::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 1066 | HandleInvoke(invoke); |
| 1067 | } |
| 1068 | |
| 1069 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1070 | HandleInvoke(invoke); |
| 1071 | } |
| 1072 | |
| 1073 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
| 1074 | LocationSummary* locations = |
| 1075 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
| 1076 | locations->AddTemp(LocationFrom(x0)); |
| 1077 | |
| 1078 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
| 1079 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
| 1080 | HInstruction* input = invoke->InputAt(i); |
| 1081 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1082 | } |
| 1083 | |
| 1084 | Primitive::Type return_type = invoke->GetType(); |
| 1085 | if (return_type != Primitive::kPrimVoid) { |
| 1086 | locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type)); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | void InstructionCodeGeneratorARM64::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 1091 | Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 1092 | // Make sure that ArtMethod* is passed in W0 as per the calling convention |
| 1093 | DCHECK(temp.Is(w0)); |
| 1094 | size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() + |
| 1095 | invoke->GetIndexInDexCache() * kHeapRefSize; |
| 1096 | |
| 1097 | // TODO: Implement all kinds of calls: |
| 1098 | // 1) boot -> boot |
| 1099 | // 2) app -> boot |
| 1100 | // 3) app -> app |
| 1101 | // |
| 1102 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1103 | |
| 1104 | // temp = method; |
| 1105 | __ Ldr(temp, MemOperand(sp, kCurrentMethodStackOffset)); |
| 1106 | // temp = temp->dex_cache_resolved_methods_; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1107 | __ Ldr(temp, MemOperand(temp.X(), |
| 1108 | mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1109 | // temp = temp[index_in_cache]; |
| 1110 | __ Ldr(temp, MemOperand(temp.X(), index_in_cache)); |
| 1111 | // lr = temp->entry_point_from_quick_compiled_code_; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1112 | __ Ldr(lr, MemOperand(temp.X(), |
| 1113 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1114 | // lr(); |
| 1115 | __ Blr(lr); |
| 1116 | |
| 1117 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1118 | DCHECK(!codegen_->IsLeafMethod()); |
| 1119 | } |
| 1120 | |
| 1121 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1122 | LocationSummary* locations = invoke->GetLocations(); |
| 1123 | Location receiver = locations->InAt(0); |
| 1124 | Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 1125 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 1126 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1127 | Offset class_offset = mirror::Object::ClassOffset(); |
| 1128 | Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(); |
| 1129 | |
| 1130 | // temp = object->GetClass(); |
| 1131 | if (receiver.IsStackSlot()) { |
| 1132 | __ Ldr(temp.W(), MemOperand(sp, receiver.GetStackIndex())); |
| 1133 | __ Ldr(temp.W(), MemOperand(temp, class_offset.SizeValue())); |
| 1134 | } else { |
| 1135 | DCHECK(receiver.IsRegister()); |
| 1136 | __ Ldr(temp.W(), HeapOperandFrom(receiver, Primitive::kPrimNot, |
| 1137 | class_offset)); |
| 1138 | } |
| 1139 | // temp = temp->GetMethodAt(method_offset); |
| 1140 | __ Ldr(temp.W(), MemOperand(temp, method_offset)); |
| 1141 | // lr = temp->GetEntryPoint(); |
| 1142 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 1143 | // lr(); |
| 1144 | __ Blr(lr); |
| 1145 | DCHECK(!codegen_->IsLeafMethod()); |
| 1146 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1147 | } |
| 1148 | |
| 1149 | void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) { |
| 1150 | load->SetLocations(nullptr); |
| 1151 | } |
| 1152 | |
| 1153 | void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) { |
| 1154 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1155 | UNUSED(load); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | void LocationsBuilderARM64::VisitLocal(HLocal* local) { |
| 1159 | local->SetLocations(nullptr); |
| 1160 | } |
| 1161 | |
| 1162 | void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) { |
| 1163 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1164 | } |
| 1165 | |
| 1166 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 1167 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 1168 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1169 | } |
| 1170 | |
| 1171 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) { |
| 1172 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1173 | UNUSED(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1176 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 1177 | LocationSummary* locations = |
| 1178 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1179 | switch (mul->GetResultType()) { |
| 1180 | case Primitive::kPrimInt: |
| 1181 | case Primitive::kPrimLong: |
| 1182 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1183 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1184 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1185 | break; |
| 1186 | |
| 1187 | case Primitive::kPrimFloat: |
| 1188 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1189 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1190 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1191 | locations->SetOut(Location::RequiresFpuRegister()); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1192 | break; |
| 1193 | |
| 1194 | default: |
| 1195 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 1200 | switch (mul->GetResultType()) { |
| 1201 | case Primitive::kPrimInt: |
| 1202 | case Primitive::kPrimLong: |
| 1203 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 1204 | break; |
| 1205 | |
| 1206 | case Primitive::kPrimFloat: |
| 1207 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1208 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | |
| 1211 | default: |
| 1212 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 1213 | } |
| 1214 | } |
| 1215 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1216 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 1217 | LocationSummary* locations = |
| 1218 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1219 | switch (neg->GetResultType()) { |
| 1220 | case Primitive::kPrimInt: |
| 1221 | case Primitive::kPrimLong: { |
| 1222 | locations->SetInAt(0, Location::RegisterOrConstant(neg->InputAt(0))); |
| 1223 | locations->SetOut(Location::RequiresRegister()); |
| 1224 | break; |
| 1225 | } |
| 1226 | |
| 1227 | case Primitive::kPrimFloat: |
| 1228 | case Primitive::kPrimDouble: |
| 1229 | LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType(); |
| 1230 | break; |
| 1231 | |
| 1232 | default: |
| 1233 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 1238 | switch (neg->GetResultType()) { |
| 1239 | case Primitive::kPrimInt: |
| 1240 | case Primitive::kPrimLong: |
| 1241 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 1242 | break; |
| 1243 | |
| 1244 | case Primitive::kPrimFloat: |
| 1245 | case Primitive::kPrimDouble: |
| 1246 | LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType(); |
| 1247 | break; |
| 1248 | |
| 1249 | default: |
| 1250 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 1255 | LocationSummary* locations = |
| 1256 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1257 | InvokeRuntimeCallingConvention calling_convention; |
| 1258 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1259 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1260 | locations->SetOut(LocationFrom(x0)); |
| 1261 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1262 | } |
| 1263 | |
| 1264 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 1265 | LocationSummary* locations = instruction->GetLocations(); |
| 1266 | InvokeRuntimeCallingConvention calling_convention; |
| 1267 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 1268 | DCHECK(type_index.Is(w0)); |
| 1269 | Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot); |
| 1270 | DCHECK(current_method.Is(w1)); |
| 1271 | __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset)); |
| 1272 | __ Mov(type_index, instruction->GetTypeIndex()); |
| 1273 | int32_t quick_entrypoint_offset = |
| 1274 | QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAllocArrayWithAccessCheck).Int32Value(); |
| 1275 | __ Ldr(lr, MemOperand(tr, quick_entrypoint_offset)); |
| 1276 | __ Blr(lr); |
| 1277 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1278 | DCHECK(!codegen_->IsLeafMethod()); |
| 1279 | } |
| 1280 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1281 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 1282 | LocationSummary* locations = |
| 1283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1284 | InvokeRuntimeCallingConvention calling_convention; |
| 1285 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1286 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1287 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1288 | } |
| 1289 | |
| 1290 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| 1291 | LocationSummary* locations = instruction->GetLocations(); |
| 1292 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 1293 | DCHECK(type_index.Is(w0)); |
| 1294 | Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot); |
| 1295 | DCHECK(current_method.Is(w1)); |
| 1296 | __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset)); |
| 1297 | __ Mov(type_index, instruction->GetTypeIndex()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1298 | int32_t quick_entrypoint_offset = |
| 1299 | QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAllocObjectWithAccessCheck).Int32Value(); |
| 1300 | __ Ldr(lr, MemOperand(tr, quick_entrypoint_offset)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1301 | __ Blr(lr); |
| 1302 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1303 | DCHECK(!codegen_->IsLeafMethod()); |
| 1304 | } |
| 1305 | |
| 1306 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 1307 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 1308 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1309 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
| 1313 | switch (instruction->InputAt(0)->GetType()) { |
| 1314 | case Primitive::kPrimBoolean: |
| 1315 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), Operand(1)); |
| 1316 | break; |
| 1317 | |
| 1318 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1319 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 1320 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | default: |
| 1324 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
| 1329 | LocationSummary* locations = |
| 1330 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1332 | if (instruction->HasUses()) { |
| 1333 | locations->SetOut(Location::SameAsFirstInput()); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
| 1338 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
| 1339 | codegen_->AddSlowPath(slow_path); |
| 1340 | |
| 1341 | LocationSummary* locations = instruction->GetLocations(); |
| 1342 | Location obj = locations->InAt(0); |
| 1343 | if (obj.IsRegister()) { |
| 1344 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
| 1345 | } else { |
| 1346 | DCHECK(obj.IsConstant()) << obj; |
| 1347 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1348 | __ B(slow_path->GetEntryLabel()); |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 1353 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1354 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1355 | if (location.IsStackSlot()) { |
| 1356 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1357 | } else if (location.IsDoubleStackSlot()) { |
| 1358 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1359 | } |
| 1360 | locations->SetOut(location); |
| 1361 | } |
| 1362 | |
| 1363 | void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) { |
| 1364 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1365 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 1369 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1370 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1371 | locations->SetInAt(i, Location::Any()); |
| 1372 | } |
| 1373 | locations->SetOut(Location::Any()); |
| 1374 | } |
| 1375 | |
| 1376 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1377 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1378 | LOG(FATAL) << "Unreachable"; |
| 1379 | } |
| 1380 | |
| 1381 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 1382 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1383 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1384 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1388 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1389 | codegen_->GenerateFrameExit(); |
| 1390 | __ Br(lr); |
| 1391 | } |
| 1392 | |
| 1393 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 1394 | instruction->SetLocations(nullptr); |
| 1395 | } |
| 1396 | |
| 1397 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1398 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1399 | codegen_->GenerateFrameExit(); |
| 1400 | __ Br(lr); |
| 1401 | } |
| 1402 | |
| 1403 | void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) { |
| 1404 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 1405 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 1406 | switch (field_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1407 | case Primitive::kPrimNot: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1408 | case Primitive::kPrimBoolean: |
| 1409 | case Primitive::kPrimByte: |
| 1410 | case Primitive::kPrimChar: |
| 1411 | case Primitive::kPrimShort: |
| 1412 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1413 | case Primitive::kPrimFloat: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1414 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1415 | break; |
| 1416 | |
| 1417 | case Primitive::kPrimLong: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1418 | case Primitive::kPrimDouble: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1419 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1420 | break; |
| 1421 | |
| 1422 | default: |
| 1423 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1428 | UNUSED(store); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
| 1432 | HandleAddSub(instruction); |
| 1433 | } |
| 1434 | |
| 1435 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
| 1436 | HandleAddSub(instruction); |
| 1437 | } |
| 1438 | |
| 1439 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1440 | LocationSummary* locations = |
| 1441 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1443 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1444 | if (instruction->HasUses()) { |
| 1445 | locations->SetOut(Location::SameAsFirstInput()); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1450 | LocationSummary* locations = instruction->GetLocations(); |
| 1451 | BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64( |
| 1452 | instruction, locations->InAt(0), locations->InAt(1)); |
| 1453 | codegen_->AddSlowPath(slow_path); |
| 1454 | |
| 1455 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 1456 | __ B(slow_path->GetEntryLabel(), hs); |
| 1457 | } |
| 1458 | |
| 1459 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1460 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1461 | } |
| 1462 | |
| 1463 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1464 | // TODO: Improve support for suspend checks. |
| 1465 | SuspendCheckSlowPathARM64* slow_path = |
| 1466 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, nullptr); |
| 1467 | codegen_->AddSlowPath(slow_path); |
| 1468 | |
| 1469 | __ Subs(wSuspend, wSuspend, 1); |
| 1470 | __ B(slow_path->GetEntryLabel(), le); |
| 1471 | __ Bind(slow_path->GetReturnLabel()); |
| 1472 | } |
| 1473 | |
| 1474 | void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) { |
| 1475 | temp->SetLocations(nullptr); |
| 1476 | } |
| 1477 | |
| 1478 | void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) { |
| 1479 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1480 | UNUSED(temp); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | } // namespace arm64 |
| 1484 | } // namespace art |