code_generator_arm.cc revision ddb7df25af45d7cd19ed1138e537973735cc78a5
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_arm.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/arm/assembler_arm.h" 26#include "utils/arm/managed_register_arm.h" 27#include "utils/assembler.h" 28#include "utils/stack_checks.h" 29 30namespace art { 31 32namespace arm { 33 34static DRegister FromLowSToD(SRegister reg) { 35 DCHECK_EQ(reg % 2, 0); 36 return static_cast<DRegister>(reg / 2); 37} 38 39static constexpr bool kExplicitStackOverflowCheck = false; 40 41static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7 42static constexpr int kCurrentMethodStackOffset = 0; 43 44static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 }; 45static constexpr size_t kRuntimeParameterCoreRegistersLength = 46 arraysize(kRuntimeParameterCoreRegisters); 47static constexpr SRegister kRuntimeParameterFpuRegisters[] = { }; 48static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; 49 50class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> { 51 public: 52 InvokeRuntimeCallingConvention() 53 : CallingConvention(kRuntimeParameterCoreRegisters, 54 kRuntimeParameterCoreRegistersLength, 55 kRuntimeParameterFpuRegisters, 56 kRuntimeParameterFpuRegistersLength) {} 57 58 private: 59 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); 60}; 61 62#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())-> 63#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() 64 65class SlowPathCodeARM : public SlowPathCode { 66 public: 67 SlowPathCodeARM() : entry_label_(), exit_label_() {} 68 69 Label* GetEntryLabel() { return &entry_label_; } 70 Label* GetExitLabel() { return &exit_label_; } 71 72 private: 73 Label entry_label_; 74 Label exit_label_; 75 76 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM); 77}; 78 79class NullCheckSlowPathARM : public SlowPathCodeARM { 80 public: 81 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} 82 83 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 84 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 85 __ Bind(GetEntryLabel()); 86 arm_codegen->InvokeRuntime( 87 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc()); 88 } 89 90 private: 91 HNullCheck* const instruction_; 92 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); 93}; 94 95class DivZeroCheckSlowPathARM : public SlowPathCodeARM { 96 public: 97 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} 98 99 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 100 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 101 __ Bind(GetEntryLabel()); 102 arm_codegen->InvokeRuntime( 103 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc()); 104 } 105 106 private: 107 HDivZeroCheck* const instruction_; 108 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); 109}; 110 111class StackOverflowCheckSlowPathARM : public SlowPathCodeARM { 112 public: 113 StackOverflowCheckSlowPathARM() {} 114 115 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 116 __ Bind(GetEntryLabel()); 117 __ LoadFromOffset(kLoadWord, PC, TR, 118 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value()); 119 } 120 121 private: 122 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM); 123}; 124 125class SuspendCheckSlowPathARM : public SlowPathCodeARM { 126 public: 127 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) 128 : instruction_(instruction), successor_(successor) {} 129 130 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 131 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 132 __ Bind(GetEntryLabel()); 133 codegen->SaveLiveRegisters(instruction_->GetLocations()); 134 arm_codegen->InvokeRuntime( 135 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc()); 136 codegen->RestoreLiveRegisters(instruction_->GetLocations()); 137 if (successor_ == nullptr) { 138 __ b(GetReturnLabel()); 139 } else { 140 __ b(arm_codegen->GetLabelOf(successor_)); 141 } 142 } 143 144 Label* GetReturnLabel() { 145 DCHECK(successor_ == nullptr); 146 return &return_label_; 147 } 148 149 private: 150 HSuspendCheck* const instruction_; 151 // If not null, the block to branch to after the suspend check. 152 HBasicBlock* const successor_; 153 154 // If `successor_` is null, the label to branch to after the suspend check. 155 Label return_label_; 156 157 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); 158}; 159 160class BoundsCheckSlowPathARM : public SlowPathCodeARM { 161 public: 162 BoundsCheckSlowPathARM(HBoundsCheck* instruction, 163 Location index_location, 164 Location length_location) 165 : instruction_(instruction), 166 index_location_(index_location), 167 length_location_(length_location) {} 168 169 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 170 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 171 __ Bind(GetEntryLabel()); 172 // We're moving two locations to locations that could overlap, so we need a parallel 173 // move resolver. 174 InvokeRuntimeCallingConvention calling_convention; 175 codegen->EmitParallelMoves( 176 index_location_, 177 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), 178 length_location_, 179 Location::RegisterLocation(calling_convention.GetRegisterAt(1))); 180 arm_codegen->InvokeRuntime( 181 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc()); 182 } 183 184 private: 185 HBoundsCheck* const instruction_; 186 const Location index_location_; 187 const Location length_location_; 188 189 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); 190}; 191 192class LoadClassSlowPathARM : public SlowPathCodeARM { 193 public: 194 LoadClassSlowPathARM(HLoadClass* cls, 195 HInstruction* at, 196 uint32_t dex_pc, 197 bool do_clinit) 198 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { 199 DCHECK(at->IsLoadClass() || at->IsClinitCheck()); 200 } 201 202 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 203 LocationSummary* locations = at_->GetLocations(); 204 205 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 206 __ Bind(GetEntryLabel()); 207 codegen->SaveLiveRegisters(locations); 208 209 InvokeRuntimeCallingConvention calling_convention; 210 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); 211 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); 212 int32_t entry_point_offset = do_clinit_ 213 ? QUICK_ENTRY_POINT(pInitializeStaticStorage) 214 : QUICK_ENTRY_POINT(pInitializeType); 215 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_); 216 217 // Move the class to the desired location. 218 Location out = locations->Out(); 219 if (out.IsValid()) { 220 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); 221 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); 222 } 223 codegen->RestoreLiveRegisters(locations); 224 __ b(GetExitLabel()); 225 } 226 227 private: 228 // The class this slow path will load. 229 HLoadClass* const cls_; 230 231 // The instruction where this slow path is happening. 232 // (Might be the load class or an initialization check). 233 HInstruction* const at_; 234 235 // The dex PC of `at_`. 236 const uint32_t dex_pc_; 237 238 // Whether to initialize the class. 239 const bool do_clinit_; 240 241 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); 242}; 243 244class LoadStringSlowPathARM : public SlowPathCodeARM { 245 public: 246 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} 247 248 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 249 LocationSummary* locations = instruction_->GetLocations(); 250 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); 251 252 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 253 __ Bind(GetEntryLabel()); 254 codegen->SaveLiveRegisters(locations); 255 256 InvokeRuntimeCallingConvention calling_convention; 257 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0)); 258 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex()); 259 arm_codegen->InvokeRuntime( 260 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc()); 261 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); 262 263 codegen->RestoreLiveRegisters(locations); 264 __ b(GetExitLabel()); 265 } 266 267 private: 268 HLoadString* const instruction_; 269 270 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); 271}; 272 273class TypeCheckSlowPathARM : public SlowPathCodeARM { 274 public: 275 TypeCheckSlowPathARM(HInstruction* instruction, 276 Location class_to_check, 277 Location object_class, 278 uint32_t dex_pc) 279 : instruction_(instruction), 280 class_to_check_(class_to_check), 281 object_class_(object_class), 282 dex_pc_(dex_pc) {} 283 284 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { 285 LocationSummary* locations = instruction_->GetLocations(); 286 DCHECK(instruction_->IsCheckCast() 287 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); 288 289 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); 290 __ Bind(GetEntryLabel()); 291 codegen->SaveLiveRegisters(locations); 292 293 // We're moving two locations to locations that could overlap, so we need a parallel 294 // move resolver. 295 InvokeRuntimeCallingConvention calling_convention; 296 codegen->EmitParallelMoves( 297 class_to_check_, 298 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), 299 object_class_, 300 Location::RegisterLocation(calling_convention.GetRegisterAt(1))); 301 302 if (instruction_->IsInstanceOf()) { 303 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_); 304 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); 305 } else { 306 DCHECK(instruction_->IsCheckCast()); 307 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_); 308 } 309 310 codegen->RestoreLiveRegisters(locations); 311 __ b(GetExitLabel()); 312 } 313 314 private: 315 HInstruction* const instruction_; 316 const Location class_to_check_; 317 const Location object_class_; 318 uint32_t dex_pc_; 319 320 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); 321}; 322 323#undef __ 324 325#undef __ 326#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())-> 327 328inline Condition ARMCondition(IfCondition cond) { 329 switch (cond) { 330 case kCondEQ: return EQ; 331 case kCondNE: return NE; 332 case kCondLT: return LT; 333 case kCondLE: return LE; 334 case kCondGT: return GT; 335 case kCondGE: return GE; 336 default: 337 LOG(FATAL) << "Unknown if condition"; 338 } 339 return EQ; // Unreachable. 340} 341 342inline Condition ARMOppositeCondition(IfCondition cond) { 343 switch (cond) { 344 case kCondEQ: return NE; 345 case kCondNE: return EQ; 346 case kCondLT: return GE; 347 case kCondLE: return GT; 348 case kCondGT: return LE; 349 case kCondGE: return LT; 350 default: 351 LOG(FATAL) << "Unknown if condition"; 352 } 353 return EQ; // Unreachable. 354} 355 356void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { 357 stream << ArmManagedRegister::FromCoreRegister(Register(reg)); 358} 359 360void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { 361 stream << ArmManagedRegister::FromSRegister(SRegister(reg)); 362} 363 364size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { 365 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); 366 return kArmWordSize; 367} 368 369size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { 370 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); 371 return kArmWordSize; 372} 373 374CodeGeneratorARM::CodeGeneratorARM(HGraph* graph) 375 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs), 376 block_labels_(graph->GetArena(), 0), 377 location_builder_(graph, this), 378 instruction_visitor_(graph, this), 379 move_resolver_(graph->GetArena(), this), 380 assembler_(true) {} 381 382size_t CodeGeneratorARM::FrameEntrySpillSize() const { 383 return kNumberOfPushedRegistersAtEntry * kArmWordSize; 384} 385 386Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { 387 switch (type) { 388 case Primitive::kPrimLong: { 389 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); 390 ArmManagedRegister pair = 391 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); 392 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); 393 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); 394 395 blocked_core_registers_[pair.AsRegisterPairLow()] = true; 396 blocked_core_registers_[pair.AsRegisterPairHigh()] = true; 397 UpdateBlockedPairRegisters(); 398 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); 399 } 400 401 case Primitive::kPrimByte: 402 case Primitive::kPrimBoolean: 403 case Primitive::kPrimChar: 404 case Primitive::kPrimShort: 405 case Primitive::kPrimInt: 406 case Primitive::kPrimNot: { 407 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); 408 // Block all register pairs that contain `reg`. 409 for (int i = 0; i < kNumberOfRegisterPairs; i++) { 410 ArmManagedRegister current = 411 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); 412 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { 413 blocked_register_pairs_[i] = true; 414 } 415 } 416 return Location::RegisterLocation(reg); 417 } 418 419 case Primitive::kPrimFloat: { 420 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); 421 return Location::FpuRegisterLocation(reg); 422 } 423 424 case Primitive::kPrimDouble: { 425 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); 426 DCHECK_EQ(reg % 2, 0); 427 return Location::FpuRegisterPairLocation(reg, reg + 1); 428 } 429 430 case Primitive::kPrimVoid: 431 LOG(FATAL) << "Unreachable type " << type; 432 } 433 434 return Location(); 435} 436 437void CodeGeneratorARM::SetupBlockedRegisters() const { 438 // Don't allocate the dalvik style register pair passing. 439 blocked_register_pairs_[R1_R2] = true; 440 441 // Stack register, LR and PC are always reserved. 442 blocked_core_registers_[SP] = true; 443 blocked_core_registers_[LR] = true; 444 blocked_core_registers_[PC] = true; 445 446 // Reserve thread register. 447 blocked_core_registers_[TR] = true; 448 449 // Reserve temp register. 450 blocked_core_registers_[IP] = true; 451 452 // TODO: We currently don't use Quick's callee saved registers. 453 // We always save and restore R6 and R7 to make sure we can use three 454 // register pairs for long operations. 455 blocked_core_registers_[R4] = true; 456 blocked_core_registers_[R5] = true; 457 blocked_core_registers_[R8] = true; 458 blocked_core_registers_[R10] = true; 459 blocked_core_registers_[R11] = true; 460 461 blocked_fpu_registers_[S16] = true; 462 blocked_fpu_registers_[S17] = true; 463 blocked_fpu_registers_[S18] = true; 464 blocked_fpu_registers_[S19] = true; 465 blocked_fpu_registers_[S20] = true; 466 blocked_fpu_registers_[S21] = true; 467 blocked_fpu_registers_[S22] = true; 468 blocked_fpu_registers_[S23] = true; 469 blocked_fpu_registers_[S24] = true; 470 blocked_fpu_registers_[S25] = true; 471 blocked_fpu_registers_[S26] = true; 472 blocked_fpu_registers_[S27] = true; 473 blocked_fpu_registers_[S28] = true; 474 blocked_fpu_registers_[S29] = true; 475 blocked_fpu_registers_[S30] = true; 476 blocked_fpu_registers_[S31] = true; 477 478 UpdateBlockedPairRegisters(); 479} 480 481void CodeGeneratorARM::UpdateBlockedPairRegisters() const { 482 for (int i = 0; i < kNumberOfRegisterPairs; i++) { 483 ArmManagedRegister current = 484 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); 485 if (blocked_core_registers_[current.AsRegisterPairLow()] 486 || blocked_core_registers_[current.AsRegisterPairHigh()]) { 487 blocked_register_pairs_[i] = true; 488 } 489 } 490} 491 492InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) 493 : HGraphVisitor(graph), 494 assembler_(codegen->GetAssembler()), 495 codegen_(codegen) {} 496 497void CodeGeneratorARM::GenerateFrameEntry() { 498 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); 499 if (!skip_overflow_check) { 500 if (kExplicitStackOverflowCheck) { 501 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM(); 502 AddSlowPath(slow_path); 503 504 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value()); 505 __ cmp(SP, ShifterOperand(IP)); 506 __ b(slow_path->GetEntryLabel(), CC); 507 } else { 508 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); 509 __ LoadFromOffset(kLoadWord, IP, IP, 0); 510 RecordPcInfo(nullptr, 0); 511 } 512 } 513 514 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7); 515 __ PushList(1 << LR | 1 << R6 | 1 << R7); 516 517 // The return PC has already been pushed on the stack. 518 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize)); 519 __ StoreToOffset(kStoreWord, R0, SP, 0); 520} 521 522void CodeGeneratorARM::GenerateFrameExit() { 523 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize); 524 __ PopList(1 << PC | 1 << R6 | 1 << R7); 525} 526 527void CodeGeneratorARM::Bind(HBasicBlock* block) { 528 __ Bind(GetLabelOf(block)); 529} 530 531Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { 532 switch (load->GetType()) { 533 case Primitive::kPrimLong: 534 case Primitive::kPrimDouble: 535 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); 536 break; 537 538 case Primitive::kPrimInt: 539 case Primitive::kPrimNot: 540 case Primitive::kPrimFloat: 541 return Location::StackSlot(GetStackSlot(load->GetLocal())); 542 543 case Primitive::kPrimBoolean: 544 case Primitive::kPrimByte: 545 case Primitive::kPrimChar: 546 case Primitive::kPrimShort: 547 case Primitive::kPrimVoid: 548 LOG(FATAL) << "Unexpected type " << load->GetType(); 549 } 550 551 LOG(FATAL) << "Unreachable"; 552 return Location(); 553} 554 555Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { 556 switch (type) { 557 case Primitive::kPrimBoolean: 558 case Primitive::kPrimByte: 559 case Primitive::kPrimChar: 560 case Primitive::kPrimShort: 561 case Primitive::kPrimInt: 562 case Primitive::kPrimNot: { 563 uint32_t index = gp_index_++; 564 uint32_t stack_index = stack_index_++; 565 if (index < calling_convention.GetNumberOfRegisters()) { 566 return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); 567 } else { 568 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); 569 } 570 } 571 572 case Primitive::kPrimLong: { 573 uint32_t index = gp_index_; 574 uint32_t stack_index = stack_index_; 575 gp_index_ += 2; 576 stack_index_ += 2; 577 if (index + 1 < calling_convention.GetNumberOfRegisters()) { 578 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair( 579 calling_convention.GetRegisterPairAt(index)); 580 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); 581 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { 582 return Location::QuickParameter(index, stack_index); 583 } else { 584 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); 585 } 586 } 587 588 case Primitive::kPrimFloat: { 589 uint32_t stack_index = stack_index_++; 590 if (float_index_ % 2 == 0) { 591 float_index_ = std::max(double_index_, float_index_); 592 } 593 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { 594 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); 595 } else { 596 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); 597 } 598 } 599 600 case Primitive::kPrimDouble: { 601 double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); 602 uint32_t stack_index = stack_index_; 603 stack_index_ += 2; 604 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { 605 uint32_t index = double_index_; 606 double_index_ += 2; 607 return Location::FpuRegisterPairLocation( 608 calling_convention.GetFpuRegisterAt(index), 609 calling_convention.GetFpuRegisterAt(index + 1)); 610 } else { 611 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); 612 } 613 } 614 615 case Primitive::kPrimVoid: 616 LOG(FATAL) << "Unexpected parameter type " << type; 617 break; 618 } 619 return Location(); 620} 621 622Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) { 623 switch (type) { 624 case Primitive::kPrimBoolean: 625 case Primitive::kPrimByte: 626 case Primitive::kPrimChar: 627 case Primitive::kPrimShort: 628 case Primitive::kPrimInt: 629 case Primitive::kPrimNot: { 630 return Location::RegisterLocation(R0); 631 } 632 633 case Primitive::kPrimFloat: { 634 return Location::FpuRegisterLocation(S0); 635 } 636 637 case Primitive::kPrimLong: { 638 return Location::RegisterPairLocation(R0, R1); 639 } 640 641 case Primitive::kPrimDouble: { 642 return Location::FpuRegisterPairLocation(S0, S1); 643 } 644 645 case Primitive::kPrimVoid: 646 return Location(); 647 } 648 UNREACHABLE(); 649 return Location(); 650} 651 652void CodeGeneratorARM::Move32(Location destination, Location source) { 653 if (source.Equals(destination)) { 654 return; 655 } 656 if (destination.IsRegister()) { 657 if (source.IsRegister()) { 658 __ Mov(destination.As<Register>(), source.As<Register>()); 659 } else if (source.IsFpuRegister()) { 660 __ vmovrs(destination.As<Register>(), source.As<SRegister>()); 661 } else { 662 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex()); 663 } 664 } else if (destination.IsFpuRegister()) { 665 if (source.IsRegister()) { 666 __ vmovsr(destination.As<SRegister>(), source.As<Register>()); 667 } else if (source.IsFpuRegister()) { 668 __ vmovs(destination.As<SRegister>(), source.As<SRegister>()); 669 } else { 670 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex()); 671 } 672 } else { 673 DCHECK(destination.IsStackSlot()) << destination; 674 if (source.IsRegister()) { 675 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex()); 676 } else if (source.IsFpuRegister()) { 677 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex()); 678 } else { 679 DCHECK(source.IsStackSlot()) << source; 680 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); 681 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); 682 } 683 } 684} 685 686void CodeGeneratorARM::Move64(Location destination, Location source) { 687 if (source.Equals(destination)) { 688 return; 689 } 690 if (destination.IsRegisterPair()) { 691 if (source.IsRegisterPair()) { 692 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); 693 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); 694 } else if (source.IsFpuRegister()) { 695 UNIMPLEMENTED(FATAL); 696 } else if (source.IsQuickParameter()) { 697 uint16_t register_index = source.GetQuickParameterRegisterIndex(); 698 uint16_t stack_index = source.GetQuickParameterStackIndex(); 699 InvokeDexCallingConvention calling_convention; 700 __ Mov(destination.AsRegisterPairLow<Register>(), 701 calling_convention.GetRegisterAt(register_index)); 702 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(), 703 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()); 704 } else { 705 DCHECK(source.IsDoubleStackSlot()); 706 if (destination.AsRegisterPairLow<Register>() == R1) { 707 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2); 708 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex()); 709 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize)); 710 } else { 711 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), 712 SP, source.GetStackIndex()); 713 } 714 } 715 } else if (destination.IsFpuRegisterPair()) { 716 if (source.IsDoubleStackSlot()) { 717 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), 718 SP, 719 source.GetStackIndex()); 720 } else { 721 UNIMPLEMENTED(FATAL); 722 } 723 } else if (destination.IsQuickParameter()) { 724 InvokeDexCallingConvention calling_convention; 725 uint16_t register_index = destination.GetQuickParameterRegisterIndex(); 726 uint16_t stack_index = destination.GetQuickParameterStackIndex(); 727 if (source.IsRegisterPair()) { 728 __ Mov(calling_convention.GetRegisterAt(register_index), 729 source.AsRegisterPairLow<Register>()); 730 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(), 731 SP, calling_convention.GetStackOffsetOf(stack_index + 1)); 732 } else if (source.IsFpuRegister()) { 733 UNIMPLEMENTED(FATAL); 734 } else { 735 DCHECK(source.IsDoubleStackSlot()); 736 __ LoadFromOffset( 737 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex()); 738 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize)); 739 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1)); 740 } 741 } else { 742 DCHECK(destination.IsDoubleStackSlot()); 743 if (source.IsRegisterPair()) { 744 if (source.AsRegisterPairLow<Register>() == R1) { 745 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); 746 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); 747 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); 748 } else { 749 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), 750 SP, destination.GetStackIndex()); 751 } 752 } else if (source.IsQuickParameter()) { 753 InvokeDexCallingConvention calling_convention; 754 uint16_t register_index = source.GetQuickParameterRegisterIndex(); 755 uint16_t stack_index = source.GetQuickParameterStackIndex(); 756 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index), 757 SP, destination.GetStackIndex()); 758 __ LoadFromOffset(kLoadWord, R0, 759 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()); 760 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize)); 761 } else if (source.IsFpuRegisterPair()) { 762 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), 763 SP, 764 destination.GetStackIndex()); 765 } else { 766 DCHECK(source.IsDoubleStackSlot()); 767 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); 768 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); 769 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize)); 770 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); 771 } 772 } 773} 774 775void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { 776 LocationSummary* locations = instruction->GetLocations(); 777 if (locations != nullptr && locations->Out().Equals(location)) { 778 return; 779 } 780 781 if (locations != nullptr && locations->Out().IsConstant()) { 782 HConstant* const_to_move = locations->Out().GetConstant(); 783 if (const_to_move->IsIntConstant()) { 784 int32_t value = const_to_move->AsIntConstant()->GetValue(); 785 if (location.IsRegister()) { 786 __ LoadImmediate(location.As<Register>(), value); 787 } else { 788 DCHECK(location.IsStackSlot()); 789 __ LoadImmediate(IP, value); 790 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); 791 } 792 } else if (const_to_move->IsLongConstant()) { 793 int64_t value = const_to_move->AsLongConstant()->GetValue(); 794 if (location.IsRegisterPair()) { 795 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); 796 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); 797 } else { 798 DCHECK(location.IsDoubleStackSlot()); 799 __ LoadImmediate(IP, Low32Bits(value)); 800 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); 801 __ LoadImmediate(IP, High32Bits(value)); 802 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); 803 } 804 } 805 } else if (instruction->IsLoadLocal()) { 806 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); 807 switch (instruction->GetType()) { 808 case Primitive::kPrimBoolean: 809 case Primitive::kPrimByte: 810 case Primitive::kPrimChar: 811 case Primitive::kPrimShort: 812 case Primitive::kPrimInt: 813 case Primitive::kPrimNot: 814 case Primitive::kPrimFloat: 815 Move32(location, Location::StackSlot(stack_slot)); 816 break; 817 818 case Primitive::kPrimLong: 819 case Primitive::kPrimDouble: 820 Move64(location, Location::DoubleStackSlot(stack_slot)); 821 break; 822 823 default: 824 LOG(FATAL) << "Unexpected type " << instruction->GetType(); 825 } 826 } else if (instruction->IsTemporary()) { 827 Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); 828 if (temp_location.IsStackSlot()) { 829 Move32(location, temp_location); 830 } else { 831 DCHECK(temp_location.IsDoubleStackSlot()); 832 Move64(location, temp_location); 833 } 834 } else { 835 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); 836 switch (instruction->GetType()) { 837 case Primitive::kPrimBoolean: 838 case Primitive::kPrimByte: 839 case Primitive::kPrimChar: 840 case Primitive::kPrimShort: 841 case Primitive::kPrimNot: 842 case Primitive::kPrimInt: 843 case Primitive::kPrimFloat: 844 Move32(location, locations->Out()); 845 break; 846 847 case Primitive::kPrimLong: 848 case Primitive::kPrimDouble: 849 Move64(location, locations->Out()); 850 break; 851 852 default: 853 LOG(FATAL) << "Unexpected type " << instruction->GetType(); 854 } 855 } 856} 857 858void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, 859 HInstruction* instruction, 860 uint32_t dex_pc) { 861 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); 862 __ blx(LR); 863 RecordPcInfo(instruction, dex_pc); 864 DCHECK(instruction->IsSuspendCheck() 865 || instruction->IsBoundsCheck() 866 || instruction->IsNullCheck() 867 || instruction->IsDivZeroCheck() 868 || !IsLeafMethod()); 869} 870 871void LocationsBuilderARM::VisitGoto(HGoto* got) { 872 got->SetLocations(nullptr); 873} 874 875void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { 876 HBasicBlock* successor = got->GetSuccessor(); 877 DCHECK(!successor->IsExitBlock()); 878 879 HBasicBlock* block = got->GetBlock(); 880 HInstruction* previous = got->GetPrevious(); 881 882 HLoopInformation* info = block->GetLoopInformation(); 883 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { 884 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); 885 GenerateSuspendCheck(info->GetSuspendCheck(), successor); 886 return; 887 } 888 889 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { 890 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); 891 } 892 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { 893 __ b(codegen_->GetLabelOf(successor)); 894 } 895} 896 897void LocationsBuilderARM::VisitExit(HExit* exit) { 898 exit->SetLocations(nullptr); 899} 900 901void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { 902 UNUSED(exit); 903 if (kIsDebugBuild) { 904 __ Comment("Unreachable"); 905 __ bkpt(0); 906 } 907} 908 909void LocationsBuilderARM::VisitIf(HIf* if_instr) { 910 LocationSummary* locations = 911 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); 912 HInstruction* cond = if_instr->InputAt(0); 913 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { 914 locations->SetInAt(0, Location::RequiresRegister()); 915 } 916} 917 918void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { 919 HInstruction* cond = if_instr->InputAt(0); 920 if (cond->IsIntConstant()) { 921 // Constant condition, statically compared against 1. 922 int32_t cond_value = cond->AsIntConstant()->GetValue(); 923 if (cond_value == 1) { 924 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), 925 if_instr->IfTrueSuccessor())) { 926 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); 927 } 928 return; 929 } else { 930 DCHECK_EQ(cond_value, 0); 931 } 932 } else { 933 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { 934 // Condition has been materialized, compare the output to 0 935 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister()); 936 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(), 937 ShifterOperand(0)); 938 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE); 939 } else { 940 // Condition has not been materialized, use its inputs as the 941 // comparison and its condition as the branch condition. 942 LocationSummary* locations = cond->GetLocations(); 943 if (locations->InAt(1).IsRegister()) { 944 __ cmp(locations->InAt(0).As<Register>(), 945 ShifterOperand(locations->InAt(1).As<Register>())); 946 } else { 947 DCHECK(locations->InAt(1).IsConstant()); 948 int32_t value = 949 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); 950 ShifterOperand operand; 951 if (ShifterOperand::CanHoldArm(value, &operand)) { 952 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value)); 953 } else { 954 Register temp = IP; 955 __ LoadImmediate(temp, value); 956 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp)); 957 } 958 } 959 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), 960 ARMCondition(cond->AsCondition()->GetCondition())); 961 } 962 } 963 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), 964 if_instr->IfFalseSuccessor())) { 965 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); 966 } 967} 968 969 970void LocationsBuilderARM::VisitCondition(HCondition* comp) { 971 LocationSummary* locations = 972 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); 973 locations->SetInAt(0, Location::RequiresRegister()); 974 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1))); 975 if (comp->NeedsMaterialization()) { 976 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 977 } 978} 979 980void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) { 981 if (!comp->NeedsMaterialization()) return; 982 983 LocationSummary* locations = comp->GetLocations(); 984 if (locations->InAt(1).IsRegister()) { 985 __ cmp(locations->InAt(0).As<Register>(), 986 ShifterOperand(locations->InAt(1).As<Register>())); 987 } else { 988 DCHECK(locations->InAt(1).IsConstant()); 989 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); 990 ShifterOperand operand; 991 if (ShifterOperand::CanHoldArm(value, &operand)) { 992 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value)); 993 } else { 994 Register temp = IP; 995 __ LoadImmediate(temp, value); 996 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp)); 997 } 998 } 999 __ it(ARMCondition(comp->GetCondition()), kItElse); 1000 __ mov(locations->Out().As<Register>(), ShifterOperand(1), 1001 ARMCondition(comp->GetCondition())); 1002 __ mov(locations->Out().As<Register>(), ShifterOperand(0), 1003 ARMOppositeCondition(comp->GetCondition())); 1004} 1005 1006void LocationsBuilderARM::VisitEqual(HEqual* comp) { 1007 VisitCondition(comp); 1008} 1009 1010void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { 1011 VisitCondition(comp); 1012} 1013 1014void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { 1015 VisitCondition(comp); 1016} 1017 1018void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { 1019 VisitCondition(comp); 1020} 1021 1022void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { 1023 VisitCondition(comp); 1024} 1025 1026void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { 1027 VisitCondition(comp); 1028} 1029 1030void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { 1031 VisitCondition(comp); 1032} 1033 1034void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { 1035 VisitCondition(comp); 1036} 1037 1038void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { 1039 VisitCondition(comp); 1040} 1041 1042void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { 1043 VisitCondition(comp); 1044} 1045 1046void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { 1047 VisitCondition(comp); 1048} 1049 1050void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { 1051 VisitCondition(comp); 1052} 1053 1054void LocationsBuilderARM::VisitLocal(HLocal* local) { 1055 local->SetLocations(nullptr); 1056} 1057 1058void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { 1059 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); 1060} 1061 1062void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { 1063 load->SetLocations(nullptr); 1064} 1065 1066void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { 1067 // Nothing to do, this is driven by the code generator. 1068 UNUSED(load); 1069} 1070 1071void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { 1072 LocationSummary* locations = 1073 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); 1074 switch (store->InputAt(1)->GetType()) { 1075 case Primitive::kPrimBoolean: 1076 case Primitive::kPrimByte: 1077 case Primitive::kPrimChar: 1078 case Primitive::kPrimShort: 1079 case Primitive::kPrimInt: 1080 case Primitive::kPrimNot: 1081 case Primitive::kPrimFloat: 1082 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); 1083 break; 1084 1085 case Primitive::kPrimLong: 1086 case Primitive::kPrimDouble: 1087 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); 1088 break; 1089 1090 default: 1091 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); 1092 } 1093} 1094 1095void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { 1096 UNUSED(store); 1097} 1098 1099void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { 1100 LocationSummary* locations = 1101 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); 1102 locations->SetOut(Location::ConstantLocation(constant)); 1103} 1104 1105void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { 1106 // Will be generated at use site. 1107 UNUSED(constant); 1108} 1109 1110void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { 1111 LocationSummary* locations = 1112 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); 1113 locations->SetOut(Location::ConstantLocation(constant)); 1114} 1115 1116void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { 1117 // Will be generated at use site. 1118 UNUSED(constant); 1119} 1120 1121void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { 1122 LocationSummary* locations = 1123 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); 1124 locations->SetOut(Location::ConstantLocation(constant)); 1125} 1126 1127void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { 1128 // Will be generated at use site. 1129 UNUSED(constant); 1130} 1131 1132void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { 1133 LocationSummary* locations = 1134 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); 1135 locations->SetOut(Location::ConstantLocation(constant)); 1136} 1137 1138void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { 1139 // Will be generated at use site. 1140 UNUSED(constant); 1141} 1142 1143void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { 1144 ret->SetLocations(nullptr); 1145} 1146 1147void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { 1148 UNUSED(ret); 1149 codegen_->GenerateFrameExit(); 1150} 1151 1152void LocationsBuilderARM::VisitReturn(HReturn* ret) { 1153 LocationSummary* locations = 1154 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); 1155 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); 1156} 1157 1158void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { 1159 UNUSED(ret); 1160 codegen_->GenerateFrameExit(); 1161} 1162 1163void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) { 1164 HandleInvoke(invoke); 1165} 1166 1167void CodeGeneratorARM::LoadCurrentMethod(Register reg) { 1168 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); 1169} 1170 1171void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) { 1172 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); 1173 1174 // TODO: Implement all kinds of calls: 1175 // 1) boot -> boot 1176 // 2) app -> boot 1177 // 3) app -> app 1178 // 1179 // Currently we implement the app -> app logic, which looks up in the resolve cache. 1180 1181 // temp = method; 1182 codegen_->LoadCurrentMethod(temp); 1183 // temp = temp->dex_cache_resolved_methods_; 1184 __ LoadFromOffset( 1185 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); 1186 // temp = temp[index_in_cache] 1187 __ LoadFromOffset( 1188 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache())); 1189 // LR = temp[offset_of_quick_compiled_code] 1190 __ LoadFromOffset(kLoadWord, LR, temp, 1191 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( 1192 kArmWordSize).Int32Value()); 1193 // LR() 1194 __ blx(LR); 1195 1196 codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); 1197 DCHECK(!codegen_->IsLeafMethod()); 1198} 1199 1200void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { 1201 LocationSummary* locations = 1202 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); 1203 locations->AddTemp(Location::RegisterLocation(R0)); 1204 1205 InvokeDexCallingConventionVisitor calling_convention_visitor; 1206 for (size_t i = 0; i < invoke->InputCount(); i++) { 1207 HInstruction* input = invoke->InputAt(i); 1208 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); 1209 } 1210 1211 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType())); 1212} 1213 1214void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { 1215 HandleInvoke(invoke); 1216} 1217 1218void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { 1219 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); 1220 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + 1221 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); 1222 LocationSummary* locations = invoke->GetLocations(); 1223 Location receiver = locations->InAt(0); 1224 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); 1225 // temp = object->GetClass(); 1226 if (receiver.IsStackSlot()) { 1227 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); 1228 __ LoadFromOffset(kLoadWord, temp, temp, class_offset); 1229 } else { 1230 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); 1231 } 1232 // temp = temp->GetMethodAt(method_offset); 1233 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( 1234 kArmWordSize).Int32Value(); 1235 __ LoadFromOffset(kLoadWord, temp, temp, method_offset); 1236 // LR = temp->GetEntryPoint(); 1237 __ LoadFromOffset(kLoadWord, LR, temp, entry_point); 1238 // LR(); 1239 __ blx(LR); 1240 DCHECK(!codegen_->IsLeafMethod()); 1241 codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); 1242} 1243 1244void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { 1245 HandleInvoke(invoke); 1246 // Add the hidden argument. 1247 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); 1248} 1249 1250void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { 1251 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. 1252 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); 1253 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + 1254 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); 1255 LocationSummary* locations = invoke->GetLocations(); 1256 Location receiver = locations->InAt(0); 1257 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); 1258 1259 // Set the hidden argument. 1260 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex()); 1261 1262 // temp = object->GetClass(); 1263 if (receiver.IsStackSlot()) { 1264 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); 1265 __ LoadFromOffset(kLoadWord, temp, temp, class_offset); 1266 } else { 1267 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); 1268 } 1269 // temp = temp->GetImtEntryAt(method_offset); 1270 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( 1271 kArmWordSize).Int32Value(); 1272 __ LoadFromOffset(kLoadWord, temp, temp, method_offset); 1273 // LR = temp->GetEntryPoint(); 1274 __ LoadFromOffset(kLoadWord, LR, temp, entry_point); 1275 // LR(); 1276 __ blx(LR); 1277 DCHECK(!codegen_->IsLeafMethod()); 1278 codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); 1279} 1280 1281void LocationsBuilderARM::VisitNeg(HNeg* neg) { 1282 LocationSummary* locations = 1283 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); 1284 switch (neg->GetResultType()) { 1285 case Primitive::kPrimInt: 1286 case Primitive::kPrimLong: { 1287 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong); 1288 locations->SetInAt(0, Location::RequiresRegister()); 1289 locations->SetOut(Location::RequiresRegister(), output_overlaps); 1290 break; 1291 } 1292 1293 case Primitive::kPrimFloat: 1294 case Primitive::kPrimDouble: 1295 locations->SetInAt(0, Location::RequiresFpuRegister()); 1296 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); 1297 break; 1298 1299 default: 1300 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); 1301 } 1302} 1303 1304void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { 1305 LocationSummary* locations = neg->GetLocations(); 1306 Location out = locations->Out(); 1307 Location in = locations->InAt(0); 1308 switch (neg->GetResultType()) { 1309 case Primitive::kPrimInt: 1310 DCHECK(in.IsRegister()); 1311 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0)); 1312 break; 1313 1314 case Primitive::kPrimLong: 1315 DCHECK(in.IsRegisterPair()); 1316 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) 1317 __ rsbs(out.AsRegisterPairLow<Register>(), 1318 in.AsRegisterPairLow<Register>(), 1319 ShifterOperand(0)); 1320 // We cannot emit an RSC (Reverse Subtract with Carry) 1321 // instruction here, as it does not exist in the Thumb-2 1322 // instruction set. We use the following approach 1323 // using SBC and SUB instead. 1324 // 1325 // out.hi = -C 1326 __ sbc(out.AsRegisterPairHigh<Register>(), 1327 out.AsRegisterPairHigh<Register>(), 1328 ShifterOperand(out.AsRegisterPairHigh<Register>())); 1329 // out.hi = out.hi - in.hi 1330 __ sub(out.AsRegisterPairHigh<Register>(), 1331 out.AsRegisterPairHigh<Register>(), 1332 ShifterOperand(in.AsRegisterPairHigh<Register>())); 1333 break; 1334 1335 case Primitive::kPrimFloat: 1336 DCHECK(in.IsFpuRegister()); 1337 __ vnegs(out.As<SRegister>(), in.As<SRegister>()); 1338 break; 1339 1340 case Primitive::kPrimDouble: 1341 DCHECK(in.IsFpuRegisterPair()); 1342 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), 1343 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); 1344 break; 1345 1346 default: 1347 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); 1348 } 1349} 1350 1351void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { 1352 LocationSummary* locations = 1353 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); 1354 Primitive::Type result_type = conversion->GetResultType(); 1355 Primitive::Type input_type = conversion->GetInputType(); 1356 switch (result_type) { 1357 case Primitive::kPrimByte: 1358 switch (input_type) { 1359 case Primitive::kPrimShort: 1360 case Primitive::kPrimInt: 1361 case Primitive::kPrimChar: 1362 // Processing a Dex `int-to-byte' instruction. 1363 locations->SetInAt(0, Location::RequiresRegister()); 1364 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1365 break; 1366 1367 default: 1368 LOG(FATAL) << "Unexpected type conversion from " << input_type 1369 << " to " << result_type; 1370 } 1371 break; 1372 1373 case Primitive::kPrimShort: 1374 switch (input_type) { 1375 case Primitive::kPrimByte: 1376 case Primitive::kPrimInt: 1377 case Primitive::kPrimChar: 1378 // Processing a Dex `int-to-short' instruction. 1379 locations->SetInAt(0, Location::RequiresRegister()); 1380 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1381 break; 1382 1383 default: 1384 LOG(FATAL) << "Unexpected type conversion from " << input_type 1385 << " to " << result_type; 1386 } 1387 break; 1388 1389 case Primitive::kPrimInt: 1390 switch (input_type) { 1391 case Primitive::kPrimLong: 1392 // Processing a Dex `long-to-int' instruction. 1393 locations->SetInAt(0, Location::Any()); 1394 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1395 break; 1396 1397 case Primitive::kPrimFloat: 1398 case Primitive::kPrimDouble: 1399 LOG(FATAL) << "Type conversion from " << input_type 1400 << " to " << result_type << " not yet implemented"; 1401 break; 1402 1403 default: 1404 LOG(FATAL) << "Unexpected type conversion from " << input_type 1405 << " to " << result_type; 1406 } 1407 break; 1408 1409 case Primitive::kPrimLong: 1410 switch (input_type) { 1411 case Primitive::kPrimByte: 1412 case Primitive::kPrimShort: 1413 case Primitive::kPrimInt: 1414 case Primitive::kPrimChar: 1415 // Processing a Dex `int-to-long' instruction. 1416 locations->SetInAt(0, Location::RequiresRegister()); 1417 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1418 break; 1419 1420 case Primitive::kPrimFloat: 1421 case Primitive::kPrimDouble: 1422 LOG(FATAL) << "Type conversion from " << input_type << " to " 1423 << result_type << " not yet implemented"; 1424 break; 1425 1426 default: 1427 LOG(FATAL) << "Unexpected type conversion from " << input_type 1428 << " to " << result_type; 1429 } 1430 break; 1431 1432 case Primitive::kPrimChar: 1433 switch (input_type) { 1434 case Primitive::kPrimByte: 1435 case Primitive::kPrimShort: 1436 case Primitive::kPrimInt: 1437 case Primitive::kPrimChar: 1438 // Processing a Dex `int-to-char' instruction. 1439 locations->SetInAt(0, Location::RequiresRegister()); 1440 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1441 break; 1442 1443 default: 1444 LOG(FATAL) << "Unexpected type conversion from " << input_type 1445 << " to " << result_type; 1446 } 1447 break; 1448 1449 case Primitive::kPrimFloat: 1450 switch (input_type) { 1451 case Primitive::kPrimByte: 1452 case Primitive::kPrimShort: 1453 case Primitive::kPrimInt: 1454 case Primitive::kPrimChar: 1455 // Processing a Dex `int-to-float' instruction. 1456 locations->SetInAt(0, Location::RequiresRegister()); 1457 locations->SetOut(Location::RequiresFpuRegister()); 1458 break; 1459 1460 case Primitive::kPrimLong: 1461 case Primitive::kPrimDouble: 1462 LOG(FATAL) << "Type conversion from " << input_type 1463 << " to " << result_type << " not yet implemented"; 1464 break; 1465 1466 default: 1467 LOG(FATAL) << "Unexpected type conversion from " << input_type 1468 << " to " << result_type; 1469 }; 1470 break; 1471 1472 case Primitive::kPrimDouble: 1473 switch (input_type) { 1474 case Primitive::kPrimByte: 1475 case Primitive::kPrimShort: 1476 case Primitive::kPrimInt: 1477 case Primitive::kPrimChar: 1478 // Processing a Dex `int-to-double' instruction. 1479 locations->SetInAt(0, Location::RequiresRegister()); 1480 locations->SetOut(Location::RequiresFpuRegister()); 1481 break; 1482 1483 case Primitive::kPrimLong: 1484 case Primitive::kPrimFloat: 1485 LOG(FATAL) << "Type conversion from " << input_type 1486 << " to " << result_type << " not yet implemented"; 1487 break; 1488 1489 default: 1490 LOG(FATAL) << "Unexpected type conversion from " << input_type 1491 << " to " << result_type; 1492 }; 1493 break; 1494 1495 default: 1496 LOG(FATAL) << "Unexpected type conversion from " << input_type 1497 << " to " << result_type; 1498 } 1499} 1500 1501void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { 1502 LocationSummary* locations = conversion->GetLocations(); 1503 Location out = locations->Out(); 1504 Location in = locations->InAt(0); 1505 Primitive::Type result_type = conversion->GetResultType(); 1506 Primitive::Type input_type = conversion->GetInputType(); 1507 switch (result_type) { 1508 case Primitive::kPrimByte: 1509 switch (input_type) { 1510 case Primitive::kPrimShort: 1511 case Primitive::kPrimInt: 1512 case Primitive::kPrimChar: 1513 // Processing a Dex `int-to-byte' instruction. 1514 __ sbfx(out.As<Register>(), in.As<Register>(), 0, 8); 1515 break; 1516 1517 default: 1518 LOG(FATAL) << "Unexpected type conversion from " << input_type 1519 << " to " << result_type; 1520 } 1521 break; 1522 1523 case Primitive::kPrimShort: 1524 switch (input_type) { 1525 case Primitive::kPrimByte: 1526 case Primitive::kPrimInt: 1527 case Primitive::kPrimChar: 1528 // Processing a Dex `int-to-short' instruction. 1529 __ sbfx(out.As<Register>(), in.As<Register>(), 0, 16); 1530 break; 1531 1532 default: 1533 LOG(FATAL) << "Unexpected type conversion from " << input_type 1534 << " to " << result_type; 1535 } 1536 break; 1537 1538 case Primitive::kPrimInt: 1539 switch (input_type) { 1540 case Primitive::kPrimLong: 1541 // Processing a Dex `long-to-int' instruction. 1542 DCHECK(out.IsRegister()); 1543 if (in.IsRegisterPair()) { 1544 __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>()); 1545 } else if (in.IsDoubleStackSlot()) { 1546 __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex()); 1547 } else { 1548 DCHECK(in.IsConstant()); 1549 DCHECK(in.GetConstant()->IsLongConstant()); 1550 int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); 1551 __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value)); 1552 } 1553 break; 1554 1555 case Primitive::kPrimFloat: 1556 case Primitive::kPrimDouble: 1557 LOG(FATAL) << "Type conversion from " << input_type 1558 << " to " << result_type << " not yet implemented"; 1559 break; 1560 1561 default: 1562 LOG(FATAL) << "Unexpected type conversion from " << input_type 1563 << " to " << result_type; 1564 } 1565 break; 1566 1567 case Primitive::kPrimLong: 1568 switch (input_type) { 1569 case Primitive::kPrimByte: 1570 case Primitive::kPrimShort: 1571 case Primitive::kPrimInt: 1572 case Primitive::kPrimChar: 1573 // Processing a Dex `int-to-long' instruction. 1574 DCHECK(out.IsRegisterPair()); 1575 DCHECK(in.IsRegister()); 1576 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>()); 1577 // Sign extension. 1578 __ Asr(out.AsRegisterPairHigh<Register>(), 1579 out.AsRegisterPairLow<Register>(), 1580 31); 1581 break; 1582 1583 case Primitive::kPrimFloat: 1584 case Primitive::kPrimDouble: 1585 LOG(FATAL) << "Type conversion from " << input_type << " to " 1586 << result_type << " not yet implemented"; 1587 break; 1588 1589 default: 1590 LOG(FATAL) << "Unexpected type conversion from " << input_type 1591 << " to " << result_type; 1592 } 1593 break; 1594 1595 case Primitive::kPrimChar: 1596 switch (input_type) { 1597 case Primitive::kPrimByte: 1598 case Primitive::kPrimShort: 1599 case Primitive::kPrimInt: 1600 case Primitive::kPrimChar: 1601 // Processing a Dex `int-to-char' instruction. 1602 __ ubfx(out.As<Register>(), in.As<Register>(), 0, 16); 1603 break; 1604 1605 default: 1606 LOG(FATAL) << "Unexpected type conversion from " << input_type 1607 << " to " << result_type; 1608 } 1609 break; 1610 1611 case Primitive::kPrimFloat: 1612 switch (input_type) { 1613 case Primitive::kPrimByte: 1614 case Primitive::kPrimShort: 1615 case Primitive::kPrimInt: 1616 case Primitive::kPrimChar: { 1617 // Processing a Dex `int-to-float' instruction. 1618 __ vmovsr(out.As<SRegister>(), in.As<Register>()); 1619 __ vcvtsi(out.As<SRegister>(), out.As<SRegister>()); 1620 break; 1621 } 1622 1623 case Primitive::kPrimLong: 1624 case Primitive::kPrimDouble: 1625 LOG(FATAL) << "Type conversion from " << input_type 1626 << " to " << result_type << " not yet implemented"; 1627 break; 1628 1629 default: 1630 LOG(FATAL) << "Unexpected type conversion from " << input_type 1631 << " to " << result_type; 1632 }; 1633 break; 1634 1635 case Primitive::kPrimDouble: 1636 switch (input_type) { 1637 case Primitive::kPrimByte: 1638 case Primitive::kPrimShort: 1639 case Primitive::kPrimInt: 1640 case Primitive::kPrimChar: { 1641 // Processing a Dex `int-to-double' instruction. 1642 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.As<Register>()); 1643 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), 1644 out.AsFpuRegisterPairLow<SRegister>()); 1645 break; 1646 } 1647 1648 case Primitive::kPrimLong: 1649 case Primitive::kPrimFloat: 1650 LOG(FATAL) << "Type conversion from " << input_type 1651 << " to " << result_type << " not yet implemented"; 1652 break; 1653 1654 default: 1655 LOG(FATAL) << "Unexpected type conversion from " << input_type 1656 << " to " << result_type; 1657 }; 1658 break; 1659 1660 default: 1661 LOG(FATAL) << "Unexpected type conversion from " << input_type 1662 << " to " << result_type; 1663 } 1664} 1665 1666void LocationsBuilderARM::VisitAdd(HAdd* add) { 1667 LocationSummary* locations = 1668 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); 1669 switch (add->GetResultType()) { 1670 case Primitive::kPrimInt: 1671 case Primitive::kPrimLong: { 1672 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong); 1673 locations->SetInAt(0, Location::RequiresRegister()); 1674 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); 1675 locations->SetOut(Location::RequiresRegister(), output_overlaps); 1676 break; 1677 } 1678 1679 case Primitive::kPrimFloat: 1680 case Primitive::kPrimDouble: { 1681 locations->SetInAt(0, Location::RequiresFpuRegister()); 1682 locations->SetInAt(1, Location::RequiresFpuRegister()); 1683 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); 1684 break; 1685 } 1686 1687 default: 1688 LOG(FATAL) << "Unexpected add type " << add->GetResultType(); 1689 } 1690} 1691 1692void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { 1693 LocationSummary* locations = add->GetLocations(); 1694 Location out = locations->Out(); 1695 Location first = locations->InAt(0); 1696 Location second = locations->InAt(1); 1697 switch (add->GetResultType()) { 1698 case Primitive::kPrimInt: 1699 if (second.IsRegister()) { 1700 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); 1701 } else { 1702 __ AddConstant(out.As<Register>(), 1703 first.As<Register>(), 1704 second.GetConstant()->AsIntConstant()->GetValue()); 1705 } 1706 break; 1707 1708 case Primitive::kPrimLong: 1709 __ adds(out.AsRegisterPairLow<Register>(), 1710 first.AsRegisterPairLow<Register>(), 1711 ShifterOperand(second.AsRegisterPairLow<Register>())); 1712 __ adc(out.AsRegisterPairHigh<Register>(), 1713 first.AsRegisterPairHigh<Register>(), 1714 ShifterOperand(second.AsRegisterPairHigh<Register>())); 1715 break; 1716 1717 case Primitive::kPrimFloat: 1718 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); 1719 break; 1720 1721 case Primitive::kPrimDouble: 1722 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), 1723 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), 1724 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); 1725 break; 1726 1727 default: 1728 LOG(FATAL) << "Unexpected add type " << add->GetResultType(); 1729 } 1730} 1731 1732void LocationsBuilderARM::VisitSub(HSub* sub) { 1733 LocationSummary* locations = 1734 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); 1735 switch (sub->GetResultType()) { 1736 case Primitive::kPrimInt: 1737 case Primitive::kPrimLong: { 1738 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong); 1739 locations->SetInAt(0, Location::RequiresRegister()); 1740 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); 1741 locations->SetOut(Location::RequiresRegister(), output_overlaps); 1742 break; 1743 } 1744 case Primitive::kPrimFloat: 1745 case Primitive::kPrimDouble: { 1746 locations->SetInAt(0, Location::RequiresFpuRegister()); 1747 locations->SetInAt(1, Location::RequiresFpuRegister()); 1748 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); 1749 break; 1750 } 1751 default: 1752 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); 1753 } 1754} 1755 1756void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { 1757 LocationSummary* locations = sub->GetLocations(); 1758 Location out = locations->Out(); 1759 Location first = locations->InAt(0); 1760 Location second = locations->InAt(1); 1761 switch (sub->GetResultType()) { 1762 case Primitive::kPrimInt: { 1763 if (second.IsRegister()) { 1764 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); 1765 } else { 1766 __ AddConstant(out.As<Register>(), 1767 first.As<Register>(), 1768 -second.GetConstant()->AsIntConstant()->GetValue()); 1769 } 1770 break; 1771 } 1772 1773 case Primitive::kPrimLong: { 1774 __ subs(out.AsRegisterPairLow<Register>(), 1775 first.AsRegisterPairLow<Register>(), 1776 ShifterOperand(second.AsRegisterPairLow<Register>())); 1777 __ sbc(out.AsRegisterPairHigh<Register>(), 1778 first.AsRegisterPairHigh<Register>(), 1779 ShifterOperand(second.AsRegisterPairHigh<Register>())); 1780 break; 1781 } 1782 1783 case Primitive::kPrimFloat: { 1784 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); 1785 break; 1786 } 1787 1788 case Primitive::kPrimDouble: { 1789 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), 1790 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), 1791 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); 1792 break; 1793 } 1794 1795 1796 default: 1797 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); 1798 } 1799} 1800 1801void LocationsBuilderARM::VisitMul(HMul* mul) { 1802 LocationSummary* locations = 1803 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); 1804 switch (mul->GetResultType()) { 1805 case Primitive::kPrimInt: 1806 case Primitive::kPrimLong: { 1807 locations->SetInAt(0, Location::RequiresRegister()); 1808 locations->SetInAt(1, Location::RequiresRegister()); 1809 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1810 break; 1811 } 1812 1813 case Primitive::kPrimFloat: 1814 case Primitive::kPrimDouble: { 1815 locations->SetInAt(0, Location::RequiresFpuRegister()); 1816 locations->SetInAt(1, Location::RequiresFpuRegister()); 1817 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); 1818 break; 1819 } 1820 1821 default: 1822 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); 1823 } 1824} 1825 1826void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { 1827 LocationSummary* locations = mul->GetLocations(); 1828 Location out = locations->Out(); 1829 Location first = locations->InAt(0); 1830 Location second = locations->InAt(1); 1831 switch (mul->GetResultType()) { 1832 case Primitive::kPrimInt: { 1833 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>()); 1834 break; 1835 } 1836 case Primitive::kPrimLong: { 1837 Register out_hi = out.AsRegisterPairHigh<Register>(); 1838 Register out_lo = out.AsRegisterPairLow<Register>(); 1839 Register in1_hi = first.AsRegisterPairHigh<Register>(); 1840 Register in1_lo = first.AsRegisterPairLow<Register>(); 1841 Register in2_hi = second.AsRegisterPairHigh<Register>(); 1842 Register in2_lo = second.AsRegisterPairLow<Register>(); 1843 1844 // Extra checks to protect caused by the existence of R1_R2. 1845 // The algorithm is wrong if out.hi is either in1.lo or in2.lo: 1846 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); 1847 DCHECK_NE(out_hi, in1_lo); 1848 DCHECK_NE(out_hi, in2_lo); 1849 1850 // input: in1 - 64 bits, in2 - 64 bits 1851 // output: out 1852 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo 1853 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] 1854 // parts: out.lo = (in1.lo * in2.lo)[31:0] 1855 1856 // IP <- in1.lo * in2.hi 1857 __ mul(IP, in1_lo, in2_hi); 1858 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo 1859 __ mla(out_hi, in1_hi, in2_lo, IP); 1860 // out.lo <- (in1.lo * in2.lo)[31:0]; 1861 __ umull(out_lo, IP, in1_lo, in2_lo); 1862 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] 1863 __ add(out_hi, out_hi, ShifterOperand(IP)); 1864 break; 1865 } 1866 1867 case Primitive::kPrimFloat: { 1868 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); 1869 break; 1870 } 1871 1872 case Primitive::kPrimDouble: { 1873 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), 1874 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), 1875 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); 1876 break; 1877 } 1878 1879 default: 1880 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); 1881 } 1882} 1883 1884void LocationsBuilderARM::VisitDiv(HDiv* div) { 1885 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong 1886 ? LocationSummary::kCall 1887 : LocationSummary::kNoCall; 1888 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); 1889 1890 switch (div->GetResultType()) { 1891 case Primitive::kPrimInt: { 1892 locations->SetInAt(0, Location::RequiresRegister()); 1893 locations->SetInAt(1, Location::RequiresRegister()); 1894 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1895 break; 1896 } 1897 case Primitive::kPrimLong: { 1898 InvokeRuntimeCallingConvention calling_convention; 1899 locations->SetInAt(0, Location::RegisterPairLocation( 1900 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); 1901 locations->SetInAt(1, Location::RegisterPairLocation( 1902 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); 1903 // The runtime helper puts the output in R0,R2. 1904 locations->SetOut(Location::RegisterPairLocation(R0, R2)); 1905 break; 1906 } 1907 case Primitive::kPrimFloat: 1908 case Primitive::kPrimDouble: { 1909 locations->SetInAt(0, Location::RequiresFpuRegister()); 1910 locations->SetInAt(1, Location::RequiresFpuRegister()); 1911 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); 1912 break; 1913 } 1914 1915 default: 1916 LOG(FATAL) << "Unexpected div type " << div->GetResultType(); 1917 } 1918} 1919 1920void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { 1921 LocationSummary* locations = div->GetLocations(); 1922 Location out = locations->Out(); 1923 Location first = locations->InAt(0); 1924 Location second = locations->InAt(1); 1925 1926 switch (div->GetResultType()) { 1927 case Primitive::kPrimInt: { 1928 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>()); 1929 break; 1930 } 1931 1932 case Primitive::kPrimLong: { 1933 InvokeRuntimeCallingConvention calling_convention; 1934 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); 1935 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); 1936 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); 1937 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); 1938 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); 1939 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>()); 1940 1941 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc()); 1942 break; 1943 } 1944 1945 case Primitive::kPrimFloat: { 1946 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); 1947 break; 1948 } 1949 1950 case Primitive::kPrimDouble: { 1951 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), 1952 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), 1953 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); 1954 break; 1955 } 1956 1957 default: 1958 LOG(FATAL) << "Unexpected div type " << div->GetResultType(); 1959 } 1960} 1961 1962void LocationsBuilderARM::VisitRem(HRem* rem) { 1963 LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong 1964 ? LocationSummary::kCall 1965 : LocationSummary::kNoCall; 1966 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); 1967 1968 switch (rem->GetResultType()) { 1969 case Primitive::kPrimInt: { 1970 locations->SetInAt(0, Location::RequiresRegister()); 1971 locations->SetInAt(1, Location::RequiresRegister()); 1972 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 1973 locations->AddTemp(Location::RequiresRegister()); 1974 break; 1975 } 1976 case Primitive::kPrimLong: { 1977 InvokeRuntimeCallingConvention calling_convention; 1978 locations->SetInAt(0, Location::RegisterPairLocation( 1979 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); 1980 locations->SetInAt(1, Location::RegisterPairLocation( 1981 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); 1982 // The runtime helper puts the output in R2,R3. 1983 locations->SetOut(Location::RegisterPairLocation(R2, R3)); 1984 break; 1985 } 1986 case Primitive::kPrimFloat: 1987 case Primitive::kPrimDouble: { 1988 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); 1989 break; 1990 } 1991 1992 default: 1993 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); 1994 } 1995} 1996 1997void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { 1998 LocationSummary* locations = rem->GetLocations(); 1999 Location out = locations->Out(); 2000 Location first = locations->InAt(0); 2001 Location second = locations->InAt(1); 2002 2003 switch (rem->GetResultType()) { 2004 case Primitive::kPrimInt: { 2005 Register reg1 = first.As<Register>(); 2006 Register reg2 = second.As<Register>(); 2007 Register temp = locations->GetTemp(0).As<Register>(); 2008 2009 // temp = reg1 / reg2 (integer division) 2010 // temp = temp * reg2 2011 // dest = reg1 - temp 2012 __ sdiv(temp, reg1, reg2); 2013 __ mul(temp, temp, reg2); 2014 __ sub(out.As<Register>(), reg1, ShifterOperand(temp)); 2015 break; 2016 } 2017 2018 case Primitive::kPrimLong: { 2019 InvokeRuntimeCallingConvention calling_convention; 2020 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); 2021 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); 2022 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); 2023 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); 2024 DCHECK_EQ(R2, out.AsRegisterPairLow<Register>()); 2025 DCHECK_EQ(R3, out.AsRegisterPairHigh<Register>()); 2026 2027 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc()); 2028 break; 2029 } 2030 2031 case Primitive::kPrimFloat: 2032 case Primitive::kPrimDouble: { 2033 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); 2034 break; 2035 } 2036 2037 default: 2038 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); 2039 } 2040} 2041 2042void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { 2043 LocationSummary* locations = 2044 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2045 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); 2046 if (instruction->HasUses()) { 2047 locations->SetOut(Location::SameAsFirstInput()); 2048 } 2049} 2050 2051void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { 2052 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); 2053 codegen_->AddSlowPath(slow_path); 2054 2055 LocationSummary* locations = instruction->GetLocations(); 2056 Location value = locations->InAt(0); 2057 2058 switch (instruction->GetType()) { 2059 case Primitive::kPrimInt: { 2060 if (value.IsRegister()) { 2061 __ cmp(value.As<Register>(), ShifterOperand(0)); 2062 __ b(slow_path->GetEntryLabel(), EQ); 2063 } else { 2064 DCHECK(value.IsConstant()) << value; 2065 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { 2066 __ b(slow_path->GetEntryLabel()); 2067 } 2068 } 2069 break; 2070 } 2071 case Primitive::kPrimLong: { 2072 if (value.IsRegisterPair()) { 2073 __ orrs(IP, 2074 value.AsRegisterPairLow<Register>(), 2075 ShifterOperand(value.AsRegisterPairHigh<Register>())); 2076 __ b(slow_path->GetEntryLabel(), EQ); 2077 } else { 2078 DCHECK(value.IsConstant()) << value; 2079 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { 2080 __ b(slow_path->GetEntryLabel()); 2081 } 2082 } 2083 break; 2084 default: 2085 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); 2086 } 2087 } 2088} 2089 2090void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { 2091 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); 2092 2093 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong 2094 ? LocationSummary::kCall 2095 : LocationSummary::kNoCall; 2096 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind); 2097 2098 switch (op->GetResultType()) { 2099 case Primitive::kPrimInt: { 2100 locations->SetInAt(0, Location::RequiresRegister()); 2101 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); 2102 locations->SetOut(Location::RequiresRegister()); 2103 break; 2104 } 2105 case Primitive::kPrimLong: { 2106 InvokeRuntimeCallingConvention calling_convention; 2107 locations->SetInAt(0, Location::RegisterPairLocation( 2108 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); 2109 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); 2110 // The runtime helper puts the output in R0,R2. 2111 locations->SetOut(Location::RegisterPairLocation(R0, R2)); 2112 break; 2113 } 2114 default: 2115 LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); 2116 } 2117} 2118 2119void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { 2120 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); 2121 2122 LocationSummary* locations = op->GetLocations(); 2123 Location out = locations->Out(); 2124 Location first = locations->InAt(0); 2125 Location second = locations->InAt(1); 2126 2127 Primitive::Type type = op->GetResultType(); 2128 switch (type) { 2129 case Primitive::kPrimInt: { 2130 Register out_reg = out.As<Register>(); 2131 Register first_reg = first.As<Register>(); 2132 // Arm doesn't mask the shift count so we need to do it ourselves. 2133 if (second.IsRegister()) { 2134 Register second_reg = second.As<Register>(); 2135 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); 2136 if (op->IsShl()) { 2137 __ Lsl(out_reg, first_reg, second_reg); 2138 } else if (op->IsShr()) { 2139 __ Asr(out_reg, first_reg, second_reg); 2140 } else { 2141 __ Lsr(out_reg, first_reg, second_reg); 2142 } 2143 } else { 2144 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); 2145 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); 2146 if (shift_value == 0) { // arm does not support shifting with 0 immediate. 2147 __ Mov(out_reg, first_reg); 2148 } else if (op->IsShl()) { 2149 __ Lsl(out_reg, first_reg, shift_value); 2150 } else if (op->IsShr()) { 2151 __ Asr(out_reg, first_reg, shift_value); 2152 } else { 2153 __ Lsr(out_reg, first_reg, shift_value); 2154 } 2155 } 2156 break; 2157 } 2158 case Primitive::kPrimLong: { 2159 // TODO: Inline the assembly instead of calling the runtime. 2160 InvokeRuntimeCallingConvention calling_convention; 2161 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); 2162 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); 2163 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.As<Register>()); 2164 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); 2165 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>()); 2166 2167 int32_t entry_point_offset; 2168 if (op->IsShl()) { 2169 entry_point_offset = QUICK_ENTRY_POINT(pShlLong); 2170 } else if (op->IsShr()) { 2171 entry_point_offset = QUICK_ENTRY_POINT(pShrLong); 2172 } else { 2173 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong); 2174 } 2175 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); 2176 __ blx(LR); 2177 break; 2178 } 2179 default: 2180 LOG(FATAL) << "Unexpected operation type " << type; 2181 } 2182} 2183 2184void LocationsBuilderARM::VisitShl(HShl* shl) { 2185 HandleShift(shl); 2186} 2187 2188void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { 2189 HandleShift(shl); 2190} 2191 2192void LocationsBuilderARM::VisitShr(HShr* shr) { 2193 HandleShift(shr); 2194} 2195 2196void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { 2197 HandleShift(shr); 2198} 2199 2200void LocationsBuilderARM::VisitUShr(HUShr* ushr) { 2201 HandleShift(ushr); 2202} 2203 2204void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { 2205 HandleShift(ushr); 2206} 2207 2208void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { 2209 LocationSummary* locations = 2210 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); 2211 InvokeRuntimeCallingConvention calling_convention; 2212 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); 2213 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); 2214 locations->SetOut(Location::RegisterLocation(R0)); 2215} 2216 2217void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { 2218 InvokeRuntimeCallingConvention calling_convention; 2219 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); 2220 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); 2221 codegen_->InvokeRuntime( 2222 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); 2223} 2224 2225void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { 2226 LocationSummary* locations = 2227 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); 2228 InvokeRuntimeCallingConvention calling_convention; 2229 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); 2230 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); 2231 locations->SetOut(Location::RegisterLocation(R0)); 2232 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); 2233} 2234 2235void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { 2236 InvokeRuntimeCallingConvention calling_convention; 2237 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); 2238 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); 2239 codegen_->InvokeRuntime( 2240 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); 2241} 2242 2243void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { 2244 LocationSummary* locations = 2245 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2246 Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); 2247 if (location.IsStackSlot()) { 2248 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); 2249 } else if (location.IsDoubleStackSlot()) { 2250 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); 2251 } 2252 locations->SetOut(location); 2253} 2254 2255void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { 2256 // Nothing to do, the parameter is already at its location. 2257 UNUSED(instruction); 2258} 2259 2260void LocationsBuilderARM::VisitNot(HNot* not_) { 2261 LocationSummary* locations = 2262 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); 2263 locations->SetInAt(0, Location::RequiresRegister()); 2264 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 2265} 2266 2267void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { 2268 LocationSummary* locations = not_->GetLocations(); 2269 Location out = locations->Out(); 2270 Location in = locations->InAt(0); 2271 switch (not_->InputAt(0)->GetType()) { 2272 case Primitive::kPrimBoolean: 2273 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1)); 2274 break; 2275 2276 case Primitive::kPrimInt: 2277 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>())); 2278 break; 2279 2280 case Primitive::kPrimLong: 2281 __ mvn(out.AsRegisterPairLow<Register>(), 2282 ShifterOperand(in.AsRegisterPairLow<Register>())); 2283 __ mvn(out.AsRegisterPairHigh<Register>(), 2284 ShifterOperand(in.AsRegisterPairHigh<Register>())); 2285 break; 2286 2287 default: 2288 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); 2289 } 2290} 2291 2292void LocationsBuilderARM::VisitCompare(HCompare* compare) { 2293 LocationSummary* locations = 2294 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); 2295 switch (compare->InputAt(0)->GetType()) { 2296 case Primitive::kPrimLong: { 2297 locations->SetInAt(0, Location::RequiresRegister()); 2298 locations->SetInAt(1, Location::RequiresRegister()); 2299 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 2300 break; 2301 } 2302 case Primitive::kPrimFloat: 2303 case Primitive::kPrimDouble: { 2304 locations->SetInAt(0, Location::RequiresFpuRegister()); 2305 locations->SetInAt(1, Location::RequiresFpuRegister()); 2306 locations->SetOut(Location::RequiresRegister()); 2307 break; 2308 } 2309 default: 2310 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); 2311 } 2312} 2313 2314void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { 2315 LocationSummary* locations = compare->GetLocations(); 2316 Register out = locations->Out().As<Register>(); 2317 Location left = locations->InAt(0); 2318 Location right = locations->InAt(1); 2319 2320 Label less, greater, done; 2321 Primitive::Type type = compare->InputAt(0)->GetType(); 2322 switch (type) { 2323 case Primitive::kPrimLong: { 2324 __ cmp(left.AsRegisterPairHigh<Register>(), 2325 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. 2326 __ b(&less, LT); 2327 __ b(&greater, GT); 2328 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags. 2329 __ LoadImmediate(out, 0); 2330 __ cmp(left.AsRegisterPairLow<Register>(), 2331 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. 2332 break; 2333 } 2334 case Primitive::kPrimFloat: 2335 case Primitive::kPrimDouble: { 2336 __ LoadImmediate(out, 0); 2337 if (type == Primitive::kPrimFloat) { 2338 __ vcmps(left.As<SRegister>(), right.As<SRegister>()); 2339 } else { 2340 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), 2341 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); 2342 } 2343 __ vmstat(); // transfer FP status register to ARM APSR. 2344 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. 2345 break; 2346 } 2347 default: 2348 LOG(FATAL) << "Unexpected compare type " << type; 2349 } 2350 __ b(&done, EQ); 2351 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats. 2352 2353 __ Bind(&greater); 2354 __ LoadImmediate(out, 1); 2355 __ b(&done); 2356 2357 __ Bind(&less); 2358 __ LoadImmediate(out, -1); 2359 2360 __ Bind(&done); 2361} 2362 2363void LocationsBuilderARM::VisitPhi(HPhi* instruction) { 2364 LocationSummary* locations = 2365 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2366 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { 2367 locations->SetInAt(i, Location::Any()); 2368 } 2369 locations->SetOut(Location::Any()); 2370} 2371 2372void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { 2373 UNUSED(instruction); 2374 LOG(FATAL) << "Unreachable"; 2375} 2376 2377void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { 2378 LocationSummary* locations = 2379 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2380 bool needs_write_barrier = 2381 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue()); 2382 locations->SetInAt(0, Location::RequiresRegister()); 2383 locations->SetInAt(1, Location::RequiresRegister()); 2384 // Temporary registers for the write barrier. 2385 if (needs_write_barrier) { 2386 locations->AddTemp(Location::RequiresRegister()); 2387 locations->AddTemp(Location::RequiresRegister()); 2388 } 2389} 2390 2391void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { 2392 LocationSummary* locations = instruction->GetLocations(); 2393 Register obj = locations->InAt(0).As<Register>(); 2394 uint32_t offset = instruction->GetFieldOffset().Uint32Value(); 2395 Primitive::Type field_type = instruction->GetFieldType(); 2396 2397 switch (field_type) { 2398 case Primitive::kPrimBoolean: 2399 case Primitive::kPrimByte: { 2400 Register value = locations->InAt(1).As<Register>(); 2401 __ StoreToOffset(kStoreByte, value, obj, offset); 2402 break; 2403 } 2404 2405 case Primitive::kPrimShort: 2406 case Primitive::kPrimChar: { 2407 Register value = locations->InAt(1).As<Register>(); 2408 __ StoreToOffset(kStoreHalfword, value, obj, offset); 2409 break; 2410 } 2411 2412 case Primitive::kPrimInt: 2413 case Primitive::kPrimNot: { 2414 Register value = locations->InAt(1).As<Register>(); 2415 __ StoreToOffset(kStoreWord, value, obj, offset); 2416 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) { 2417 Register temp = locations->GetTemp(0).As<Register>(); 2418 Register card = locations->GetTemp(1).As<Register>(); 2419 codegen_->MarkGCCard(temp, card, obj, value); 2420 } 2421 break; 2422 } 2423 2424 case Primitive::kPrimLong: { 2425 Location value = locations->InAt(1); 2426 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); 2427 break; 2428 } 2429 2430 case Primitive::kPrimFloat: { 2431 SRegister value = locations->InAt(1).As<SRegister>(); 2432 __ StoreSToOffset(value, obj, offset); 2433 break; 2434 } 2435 2436 case Primitive::kPrimDouble: { 2437 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()); 2438 __ StoreDToOffset(value, obj, offset); 2439 break; 2440 } 2441 2442 case Primitive::kPrimVoid: 2443 LOG(FATAL) << "Unreachable type " << field_type; 2444 UNREACHABLE(); 2445 } 2446} 2447 2448void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { 2449 LocationSummary* locations = 2450 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2451 locations->SetInAt(0, Location::RequiresRegister()); 2452 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 2453} 2454 2455void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { 2456 LocationSummary* locations = instruction->GetLocations(); 2457 Register obj = locations->InAt(0).As<Register>(); 2458 uint32_t offset = instruction->GetFieldOffset().Uint32Value(); 2459 2460 switch (instruction->GetType()) { 2461 case Primitive::kPrimBoolean: { 2462 Register out = locations->Out().As<Register>(); 2463 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); 2464 break; 2465 } 2466 2467 case Primitive::kPrimByte: { 2468 Register out = locations->Out().As<Register>(); 2469 __ LoadFromOffset(kLoadSignedByte, out, obj, offset); 2470 break; 2471 } 2472 2473 case Primitive::kPrimShort: { 2474 Register out = locations->Out().As<Register>(); 2475 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); 2476 break; 2477 } 2478 2479 case Primitive::kPrimChar: { 2480 Register out = locations->Out().As<Register>(); 2481 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); 2482 break; 2483 } 2484 2485 case Primitive::kPrimInt: 2486 case Primitive::kPrimNot: { 2487 Register out = locations->Out().As<Register>(); 2488 __ LoadFromOffset(kLoadWord, out, obj, offset); 2489 break; 2490 } 2491 2492 case Primitive::kPrimLong: { 2493 // TODO: support volatile. 2494 Location out = locations->Out(); 2495 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); 2496 break; 2497 } 2498 2499 case Primitive::kPrimFloat: { 2500 SRegister out = locations->Out().As<SRegister>(); 2501 __ LoadSFromOffset(out, obj, offset); 2502 break; 2503 } 2504 2505 case Primitive::kPrimDouble: { 2506 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()); 2507 __ LoadDFromOffset(out, obj, offset); 2508 break; 2509 } 2510 2511 case Primitive::kPrimVoid: 2512 LOG(FATAL) << "Unreachable type " << instruction->GetType(); 2513 UNREACHABLE(); 2514 } 2515} 2516 2517void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { 2518 LocationSummary* locations = 2519 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2520 locations->SetInAt(0, Location::RequiresRegister()); 2521 if (instruction->HasUses()) { 2522 locations->SetOut(Location::SameAsFirstInput()); 2523 } 2524} 2525 2526void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { 2527 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); 2528 codegen_->AddSlowPath(slow_path); 2529 2530 LocationSummary* locations = instruction->GetLocations(); 2531 Location obj = locations->InAt(0); 2532 2533 if (obj.IsRegister()) { 2534 __ cmp(obj.As<Register>(), ShifterOperand(0)); 2535 __ b(slow_path->GetEntryLabel(), EQ); 2536 } else { 2537 DCHECK(obj.IsConstant()) << obj; 2538 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); 2539 __ b(slow_path->GetEntryLabel()); 2540 } 2541} 2542 2543void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { 2544 LocationSummary* locations = 2545 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2546 locations->SetInAt(0, Location::RequiresRegister()); 2547 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); 2548 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 2549} 2550 2551void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { 2552 LocationSummary* locations = instruction->GetLocations(); 2553 Register obj = locations->InAt(0).As<Register>(); 2554 Location index = locations->InAt(1); 2555 2556 switch (instruction->GetType()) { 2557 case Primitive::kPrimBoolean: { 2558 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); 2559 Register out = locations->Out().As<Register>(); 2560 if (index.IsConstant()) { 2561 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; 2562 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); 2563 } else { 2564 __ add(IP, obj, ShifterOperand(index.As<Register>())); 2565 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); 2566 } 2567 break; 2568 } 2569 2570 case Primitive::kPrimByte: { 2571 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); 2572 Register out = locations->Out().As<Register>(); 2573 if (index.IsConstant()) { 2574 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; 2575 __ LoadFromOffset(kLoadSignedByte, out, obj, offset); 2576 } else { 2577 __ add(IP, obj, ShifterOperand(index.As<Register>())); 2578 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); 2579 } 2580 break; 2581 } 2582 2583 case Primitive::kPrimShort: { 2584 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); 2585 Register out = locations->Out().As<Register>(); 2586 if (index.IsConstant()) { 2587 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; 2588 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); 2589 } else { 2590 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); 2591 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); 2592 } 2593 break; 2594 } 2595 2596 case Primitive::kPrimChar: { 2597 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); 2598 Register out = locations->Out().As<Register>(); 2599 if (index.IsConstant()) { 2600 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; 2601 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); 2602 } else { 2603 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); 2604 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); 2605 } 2606 break; 2607 } 2608 2609 case Primitive::kPrimInt: 2610 case Primitive::kPrimNot: { 2611 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); 2612 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); 2613 Register out = locations->Out().As<Register>(); 2614 if (index.IsConstant()) { 2615 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; 2616 __ LoadFromOffset(kLoadWord, out, obj, offset); 2617 } else { 2618 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); 2619 __ LoadFromOffset(kLoadWord, out, IP, data_offset); 2620 } 2621 break; 2622 } 2623 2624 case Primitive::kPrimLong: { 2625 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); 2626 Location out = locations->Out(); 2627 if (index.IsConstant()) { 2628 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; 2629 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); 2630 } else { 2631 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); 2632 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); 2633 } 2634 break; 2635 } 2636 2637 case Primitive::kPrimFloat: 2638 case Primitive::kPrimDouble: 2639 LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); 2640 UNREACHABLE(); 2641 case Primitive::kPrimVoid: 2642 LOG(FATAL) << "Unreachable type " << instruction->GetType(); 2643 UNREACHABLE(); 2644 } 2645} 2646 2647void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { 2648 Primitive::Type value_type = instruction->GetComponentType(); 2649 2650 bool needs_write_barrier = 2651 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); 2652 bool needs_runtime_call = instruction->NeedsTypeCheck(); 2653 2654 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( 2655 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); 2656 if (needs_runtime_call) { 2657 InvokeRuntimeCallingConvention calling_convention; 2658 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); 2659 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); 2660 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); 2661 } else { 2662 locations->SetInAt(0, Location::RequiresRegister()); 2663 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); 2664 locations->SetInAt(2, Location::RequiresRegister()); 2665 2666 if (needs_write_barrier) { 2667 // Temporary registers for the write barrier. 2668 locations->AddTemp(Location::RequiresRegister()); 2669 locations->AddTemp(Location::RequiresRegister()); 2670 } 2671 } 2672} 2673 2674void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { 2675 LocationSummary* locations = instruction->GetLocations(); 2676 Register obj = locations->InAt(0).As<Register>(); 2677 Location index = locations->InAt(1); 2678 Primitive::Type value_type = instruction->GetComponentType(); 2679 bool needs_runtime_call = locations->WillCall(); 2680 bool needs_write_barrier = 2681 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); 2682 2683 switch (value_type) { 2684 case Primitive::kPrimBoolean: 2685 case Primitive::kPrimByte: { 2686 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); 2687 Register value = locations->InAt(2).As<Register>(); 2688 if (index.IsConstant()) { 2689 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; 2690 __ StoreToOffset(kStoreByte, value, obj, offset); 2691 } else { 2692 __ add(IP, obj, ShifterOperand(index.As<Register>())); 2693 __ StoreToOffset(kStoreByte, value, IP, data_offset); 2694 } 2695 break; 2696 } 2697 2698 case Primitive::kPrimShort: 2699 case Primitive::kPrimChar: { 2700 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); 2701 Register value = locations->InAt(2).As<Register>(); 2702 if (index.IsConstant()) { 2703 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; 2704 __ StoreToOffset(kStoreHalfword, value, obj, offset); 2705 } else { 2706 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); 2707 __ StoreToOffset(kStoreHalfword, value, IP, data_offset); 2708 } 2709 break; 2710 } 2711 2712 case Primitive::kPrimInt: 2713 case Primitive::kPrimNot: { 2714 if (!needs_runtime_call) { 2715 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); 2716 Register value = locations->InAt(2).As<Register>(); 2717 if (index.IsConstant()) { 2718 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; 2719 __ StoreToOffset(kStoreWord, value, obj, offset); 2720 } else { 2721 DCHECK(index.IsRegister()) << index; 2722 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); 2723 __ StoreToOffset(kStoreWord, value, IP, data_offset); 2724 } 2725 if (needs_write_barrier) { 2726 DCHECK_EQ(value_type, Primitive::kPrimNot); 2727 Register temp = locations->GetTemp(0).As<Register>(); 2728 Register card = locations->GetTemp(1).As<Register>(); 2729 codegen_->MarkGCCard(temp, card, obj, value); 2730 } 2731 } else { 2732 DCHECK_EQ(value_type, Primitive::kPrimNot); 2733 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc()); 2734 } 2735 break; 2736 } 2737 2738 case Primitive::kPrimLong: { 2739 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); 2740 Location value = locations->InAt(2); 2741 if (index.IsConstant()) { 2742 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; 2743 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); 2744 } else { 2745 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); 2746 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); 2747 } 2748 break; 2749 } 2750 2751 case Primitive::kPrimFloat: 2752 case Primitive::kPrimDouble: 2753 LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); 2754 UNREACHABLE(); 2755 case Primitive::kPrimVoid: 2756 LOG(FATAL) << "Unreachable type " << instruction->GetType(); 2757 UNREACHABLE(); 2758 } 2759} 2760 2761void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { 2762 LocationSummary* locations = 2763 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2764 locations->SetInAt(0, Location::RequiresRegister()); 2765 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 2766} 2767 2768void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { 2769 LocationSummary* locations = instruction->GetLocations(); 2770 uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); 2771 Register obj = locations->InAt(0).As<Register>(); 2772 Register out = locations->Out().As<Register>(); 2773 __ LoadFromOffset(kLoadWord, out, obj, offset); 2774} 2775 2776void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { 2777 LocationSummary* locations = 2778 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 2779 locations->SetInAt(0, Location::RequiresRegister()); 2780 locations->SetInAt(1, Location::RequiresRegister()); 2781 if (instruction->HasUses()) { 2782 locations->SetOut(Location::SameAsFirstInput()); 2783 } 2784} 2785 2786void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { 2787 LocationSummary* locations = instruction->GetLocations(); 2788 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( 2789 instruction, locations->InAt(0), locations->InAt(1)); 2790 codegen_->AddSlowPath(slow_path); 2791 2792 Register index = locations->InAt(0).As<Register>(); 2793 Register length = locations->InAt(1).As<Register>(); 2794 2795 __ cmp(index, ShifterOperand(length)); 2796 __ b(slow_path->GetEntryLabel(), CS); 2797} 2798 2799void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) { 2800 Label is_null; 2801 __ CompareAndBranchIfZero(value, &is_null); 2802 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); 2803 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); 2804 __ strb(card, Address(card, temp)); 2805 __ Bind(&is_null); 2806} 2807 2808void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { 2809 temp->SetLocations(nullptr); 2810} 2811 2812void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { 2813 // Nothing to do, this is driven by the code generator. 2814 UNUSED(temp); 2815} 2816 2817void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { 2818 UNUSED(instruction); 2819 LOG(FATAL) << "Unreachable"; 2820} 2821 2822void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { 2823 codegen_->GetMoveResolver()->EmitNativeCode(instruction); 2824} 2825 2826void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { 2827 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); 2828} 2829 2830void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { 2831 HBasicBlock* block = instruction->GetBlock(); 2832 if (block->GetLoopInformation() != nullptr) { 2833 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); 2834 // The back edge will generate the suspend check. 2835 return; 2836 } 2837 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { 2838 // The goto will generate the suspend check. 2839 return; 2840 } 2841 GenerateSuspendCheck(instruction, nullptr); 2842} 2843 2844void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, 2845 HBasicBlock* successor) { 2846 SuspendCheckSlowPathARM* slow_path = 2847 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); 2848 codegen_->AddSlowPath(slow_path); 2849 2850 __ LoadFromOffset( 2851 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); 2852 __ cmp(IP, ShifterOperand(0)); 2853 // TODO: Figure out the branch offsets and use cbz/cbnz. 2854 if (successor == nullptr) { 2855 __ b(slow_path->GetEntryLabel(), NE); 2856 __ Bind(slow_path->GetReturnLabel()); 2857 } else { 2858 __ b(codegen_->GetLabelOf(successor), EQ); 2859 __ b(slow_path->GetEntryLabel()); 2860 } 2861} 2862 2863ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { 2864 return codegen_->GetAssembler(); 2865} 2866 2867void ParallelMoveResolverARM::EmitMove(size_t index) { 2868 MoveOperands* move = moves_.Get(index); 2869 Location source = move->GetSource(); 2870 Location destination = move->GetDestination(); 2871 2872 if (source.IsRegister()) { 2873 if (destination.IsRegister()) { 2874 __ Mov(destination.As<Register>(), source.As<Register>()); 2875 } else { 2876 DCHECK(destination.IsStackSlot()); 2877 __ StoreToOffset(kStoreWord, source.As<Register>(), 2878 SP, destination.GetStackIndex()); 2879 } 2880 } else if (source.IsStackSlot()) { 2881 if (destination.IsRegister()) { 2882 __ LoadFromOffset(kLoadWord, destination.As<Register>(), 2883 SP, source.GetStackIndex()); 2884 } else { 2885 DCHECK(destination.IsStackSlot()); 2886 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); 2887 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); 2888 } 2889 } else { 2890 DCHECK(source.IsConstant()); 2891 DCHECK(source.GetConstant()->IsIntConstant()); 2892 int32_t value = source.GetConstant()->AsIntConstant()->GetValue(); 2893 if (destination.IsRegister()) { 2894 __ LoadImmediate(destination.As<Register>(), value); 2895 } else { 2896 DCHECK(destination.IsStackSlot()); 2897 __ LoadImmediate(IP, value); 2898 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); 2899 } 2900 } 2901} 2902 2903void ParallelMoveResolverARM::Exchange(Register reg, int mem) { 2904 __ Mov(IP, reg); 2905 __ LoadFromOffset(kLoadWord, reg, SP, mem); 2906 __ StoreToOffset(kStoreWord, IP, SP, mem); 2907} 2908 2909void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { 2910 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); 2911 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; 2912 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), 2913 SP, mem1 + stack_offset); 2914 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); 2915 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), 2916 SP, mem2 + stack_offset); 2917 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); 2918} 2919 2920void ParallelMoveResolverARM::EmitSwap(size_t index) { 2921 MoveOperands* move = moves_.Get(index); 2922 Location source = move->GetSource(); 2923 Location destination = move->GetDestination(); 2924 2925 if (source.IsRegister() && destination.IsRegister()) { 2926 DCHECK_NE(source.As<Register>(), IP); 2927 DCHECK_NE(destination.As<Register>(), IP); 2928 __ Mov(IP, source.As<Register>()); 2929 __ Mov(source.As<Register>(), destination.As<Register>()); 2930 __ Mov(destination.As<Register>(), IP); 2931 } else if (source.IsRegister() && destination.IsStackSlot()) { 2932 Exchange(source.As<Register>(), destination.GetStackIndex()); 2933 } else if (source.IsStackSlot() && destination.IsRegister()) { 2934 Exchange(destination.As<Register>(), source.GetStackIndex()); 2935 } else if (source.IsStackSlot() && destination.IsStackSlot()) { 2936 Exchange(source.GetStackIndex(), destination.GetStackIndex()); 2937 } else { 2938 LOG(FATAL) << "Unimplemented"; 2939 } 2940} 2941 2942void ParallelMoveResolverARM::SpillScratch(int reg) { 2943 __ Push(static_cast<Register>(reg)); 2944} 2945 2946void ParallelMoveResolverARM::RestoreScratch(int reg) { 2947 __ Pop(static_cast<Register>(reg)); 2948} 2949 2950void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { 2951 LocationSummary::CallKind call_kind = cls->CanCallRuntime() 2952 ? LocationSummary::kCallOnSlowPath 2953 : LocationSummary::kNoCall; 2954 LocationSummary* locations = 2955 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); 2956 locations->SetOut(Location::RequiresRegister()); 2957} 2958 2959void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { 2960 Register out = cls->GetLocations()->Out().As<Register>(); 2961 if (cls->IsReferrersClass()) { 2962 DCHECK(!cls->CanCallRuntime()); 2963 DCHECK(!cls->MustGenerateClinitCheck()); 2964 codegen_->LoadCurrentMethod(out); 2965 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); 2966 } else { 2967 DCHECK(cls->CanCallRuntime()); 2968 codegen_->LoadCurrentMethod(out); 2969 __ LoadFromOffset( 2970 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); 2971 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); 2972 2973 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( 2974 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); 2975 codegen_->AddSlowPath(slow_path); 2976 __ cmp(out, ShifterOperand(0)); 2977 __ b(slow_path->GetEntryLabel(), EQ); 2978 if (cls->MustGenerateClinitCheck()) { 2979 GenerateClassInitializationCheck(slow_path, out); 2980 } else { 2981 __ Bind(slow_path->GetExitLabel()); 2982 } 2983 } 2984} 2985 2986void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { 2987 LocationSummary* locations = 2988 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); 2989 locations->SetInAt(0, Location::RequiresRegister()); 2990 if (check->HasUses()) { 2991 locations->SetOut(Location::SameAsFirstInput()); 2992 } 2993} 2994 2995void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { 2996 // We assume the class is not null. 2997 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( 2998 check->GetLoadClass(), check, check->GetDexPc(), true); 2999 codegen_->AddSlowPath(slow_path); 3000 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); 3001} 3002 3003void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( 3004 SlowPathCodeARM* slow_path, Register class_reg) { 3005 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); 3006 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); 3007 __ b(slow_path->GetEntryLabel(), LT); 3008 // Even if the initialized flag is set, we may be in a situation where caches are not synced 3009 // properly. Therefore, we do a memory fence. 3010 __ dmb(ISH); 3011 __ Bind(slow_path->GetExitLabel()); 3012} 3013 3014void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { 3015 LocationSummary* locations = 3016 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 3017 locations->SetInAt(0, Location::RequiresRegister()); 3018 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); 3019} 3020 3021void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { 3022 LocationSummary* locations = instruction->GetLocations(); 3023 Register cls = locations->InAt(0).As<Register>(); 3024 uint32_t offset = instruction->GetFieldOffset().Uint32Value(); 3025 3026 switch (instruction->GetType()) { 3027 case Primitive::kPrimBoolean: { 3028 Register out = locations->Out().As<Register>(); 3029 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset); 3030 break; 3031 } 3032 3033 case Primitive::kPrimByte: { 3034 Register out = locations->Out().As<Register>(); 3035 __ LoadFromOffset(kLoadSignedByte, out, cls, offset); 3036 break; 3037 } 3038 3039 case Primitive::kPrimShort: { 3040 Register out = locations->Out().As<Register>(); 3041 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset); 3042 break; 3043 } 3044 3045 case Primitive::kPrimChar: { 3046 Register out = locations->Out().As<Register>(); 3047 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset); 3048 break; 3049 } 3050 3051 case Primitive::kPrimInt: 3052 case Primitive::kPrimNot: { 3053 Register out = locations->Out().As<Register>(); 3054 __ LoadFromOffset(kLoadWord, out, cls, offset); 3055 break; 3056 } 3057 3058 case Primitive::kPrimLong: { 3059 // TODO: support volatile. 3060 Location out = locations->Out(); 3061 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset); 3062 break; 3063 } 3064 3065 case Primitive::kPrimFloat: { 3066 SRegister out = locations->Out().As<SRegister>(); 3067 __ LoadSFromOffset(out, cls, offset); 3068 break; 3069 } 3070 3071 case Primitive::kPrimDouble: { 3072 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()); 3073 __ LoadDFromOffset(out, cls, offset); 3074 break; 3075 } 3076 3077 case Primitive::kPrimVoid: 3078 LOG(FATAL) << "Unreachable type " << instruction->GetType(); 3079 UNREACHABLE(); 3080 } 3081} 3082 3083void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { 3084 LocationSummary* locations = 3085 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 3086 bool needs_write_barrier = 3087 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue()); 3088 locations->SetInAt(0, Location::RequiresRegister()); 3089 locations->SetInAt(1, Location::RequiresRegister()); 3090 // Temporary registers for the write barrier. 3091 if (needs_write_barrier) { 3092 locations->AddTemp(Location::RequiresRegister()); 3093 locations->AddTemp(Location::RequiresRegister()); 3094 } 3095} 3096 3097void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { 3098 LocationSummary* locations = instruction->GetLocations(); 3099 Register cls = locations->InAt(0).As<Register>(); 3100 uint32_t offset = instruction->GetFieldOffset().Uint32Value(); 3101 Primitive::Type field_type = instruction->GetFieldType(); 3102 3103 switch (field_type) { 3104 case Primitive::kPrimBoolean: 3105 case Primitive::kPrimByte: { 3106 Register value = locations->InAt(1).As<Register>(); 3107 __ StoreToOffset(kStoreByte, value, cls, offset); 3108 break; 3109 } 3110 3111 case Primitive::kPrimShort: 3112 case Primitive::kPrimChar: { 3113 Register value = locations->InAt(1).As<Register>(); 3114 __ StoreToOffset(kStoreHalfword, value, cls, offset); 3115 break; 3116 } 3117 3118 case Primitive::kPrimInt: 3119 case Primitive::kPrimNot: { 3120 Register value = locations->InAt(1).As<Register>(); 3121 __ StoreToOffset(kStoreWord, value, cls, offset); 3122 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) { 3123 Register temp = locations->GetTemp(0).As<Register>(); 3124 Register card = locations->GetTemp(1).As<Register>(); 3125 codegen_->MarkGCCard(temp, card, cls, value); 3126 } 3127 break; 3128 } 3129 3130 case Primitive::kPrimLong: { 3131 Location value = locations->InAt(1); 3132 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset); 3133 break; 3134 } 3135 3136 case Primitive::kPrimFloat: { 3137 SRegister value = locations->InAt(1).As<SRegister>(); 3138 __ StoreSToOffset(value, cls, offset); 3139 break; 3140 } 3141 3142 case Primitive::kPrimDouble: { 3143 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()); 3144 __ StoreDToOffset(value, cls, offset); 3145 break; 3146 } 3147 3148 case Primitive::kPrimVoid: 3149 LOG(FATAL) << "Unreachable type " << field_type; 3150 UNREACHABLE(); 3151 } 3152} 3153 3154void LocationsBuilderARM::VisitLoadString(HLoadString* load) { 3155 LocationSummary* locations = 3156 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); 3157 locations->SetOut(Location::RequiresRegister()); 3158} 3159 3160void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { 3161 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); 3162 codegen_->AddSlowPath(slow_path); 3163 3164 Register out = load->GetLocations()->Out().As<Register>(); 3165 codegen_->LoadCurrentMethod(out); 3166 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); 3167 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); 3168 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); 3169 __ cmp(out, ShifterOperand(0)); 3170 __ b(slow_path->GetEntryLabel(), EQ); 3171 __ Bind(slow_path->GetExitLabel()); 3172} 3173 3174void LocationsBuilderARM::VisitLoadException(HLoadException* load) { 3175 LocationSummary* locations = 3176 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); 3177 locations->SetOut(Location::RequiresRegister()); 3178} 3179 3180void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { 3181 Register out = load->GetLocations()->Out().As<Register>(); 3182 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value(); 3183 __ LoadFromOffset(kLoadWord, out, TR, offset); 3184 __ LoadImmediate(IP, 0); 3185 __ StoreToOffset(kStoreWord, IP, TR, offset); 3186} 3187 3188void LocationsBuilderARM::VisitThrow(HThrow* instruction) { 3189 LocationSummary* locations = 3190 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); 3191 InvokeRuntimeCallingConvention calling_convention; 3192 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); 3193} 3194 3195void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { 3196 codegen_->InvokeRuntime( 3197 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc()); 3198} 3199 3200void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { 3201 LocationSummary::CallKind call_kind = instruction->IsClassFinal() 3202 ? LocationSummary::kNoCall 3203 : LocationSummary::kCallOnSlowPath; 3204 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); 3205 locations->SetInAt(0, Location::RequiresRegister()); 3206 locations->SetInAt(1, Location::RequiresRegister()); 3207 locations->SetOut(Location::RequiresRegister()); 3208} 3209 3210void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { 3211 LocationSummary* locations = instruction->GetLocations(); 3212 Register obj = locations->InAt(0).As<Register>(); 3213 Register cls = locations->InAt(1).As<Register>(); 3214 Register out = locations->Out().As<Register>(); 3215 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); 3216 Label done, zero; 3217 SlowPathCodeARM* slow_path = nullptr; 3218 3219 // Return 0 if `obj` is null. 3220 // TODO: avoid this check if we know obj is not null. 3221 __ cmp(obj, ShifterOperand(0)); 3222 __ b(&zero, EQ); 3223 // Compare the class of `obj` with `cls`. 3224 __ LoadFromOffset(kLoadWord, out, obj, class_offset); 3225 __ cmp(out, ShifterOperand(cls)); 3226 if (instruction->IsClassFinal()) { 3227 // Classes must be equal for the instanceof to succeed. 3228 __ b(&zero, NE); 3229 __ LoadImmediate(out, 1); 3230 __ b(&done); 3231 } else { 3232 // If the classes are not equal, we go into a slow path. 3233 DCHECK(locations->OnlyCallsOnSlowPath()); 3234 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( 3235 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); 3236 codegen_->AddSlowPath(slow_path); 3237 __ b(slow_path->GetEntryLabel(), NE); 3238 __ LoadImmediate(out, 1); 3239 __ b(&done); 3240 } 3241 __ Bind(&zero); 3242 __ LoadImmediate(out, 0); 3243 if (slow_path != nullptr) { 3244 __ Bind(slow_path->GetExitLabel()); 3245 } 3246 __ Bind(&done); 3247} 3248 3249void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { 3250 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( 3251 instruction, LocationSummary::kCallOnSlowPath); 3252 locations->SetInAt(0, Location::RequiresRegister()); 3253 locations->SetInAt(1, Location::RequiresRegister()); 3254 locations->AddTemp(Location::RequiresRegister()); 3255} 3256 3257void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { 3258 LocationSummary* locations = instruction->GetLocations(); 3259 Register obj = locations->InAt(0).As<Register>(); 3260 Register cls = locations->InAt(1).As<Register>(); 3261 Register temp = locations->GetTemp(0).As<Register>(); 3262 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); 3263 3264 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( 3265 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); 3266 codegen_->AddSlowPath(slow_path); 3267 3268 // TODO: avoid this check if we know obj is not null. 3269 __ cmp(obj, ShifterOperand(0)); 3270 __ b(slow_path->GetExitLabel(), EQ); 3271 // Compare the class of `obj` with `cls`. 3272 __ LoadFromOffset(kLoadWord, temp, obj, class_offset); 3273 __ cmp(temp, ShifterOperand(cls)); 3274 __ b(slow_path->GetEntryLabel(), NE); 3275 __ Bind(slow_path->GetExitLabel()); 3276} 3277 3278void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { 3279 LocationSummary* locations = 3280 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); 3281 InvokeRuntimeCallingConvention calling_convention; 3282 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); 3283} 3284 3285void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { 3286 codegen_->InvokeRuntime(instruction->IsEnter() 3287 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), 3288 instruction, 3289 instruction->GetDexPc()); 3290} 3291 3292void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } 3293void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } 3294void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } 3295 3296void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { 3297 LocationSummary* locations = 3298 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); 3299 DCHECK(instruction->GetResultType() == Primitive::kPrimInt 3300 || instruction->GetResultType() == Primitive::kPrimLong); 3301 locations->SetInAt(0, Location::RequiresRegister()); 3302 locations->SetInAt(1, Location::RequiresRegister()); 3303 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong); 3304 locations->SetOut(Location::RequiresRegister(), output_overlaps); 3305} 3306 3307void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { 3308 HandleBitwiseOperation(instruction); 3309} 3310 3311void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { 3312 HandleBitwiseOperation(instruction); 3313} 3314 3315void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { 3316 HandleBitwiseOperation(instruction); 3317} 3318 3319void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { 3320 LocationSummary* locations = instruction->GetLocations(); 3321 3322 if (instruction->GetResultType() == Primitive::kPrimInt) { 3323 Register first = locations->InAt(0).As<Register>(); 3324 Register second = locations->InAt(1).As<Register>(); 3325 Register out = locations->Out().As<Register>(); 3326 if (instruction->IsAnd()) { 3327 __ and_(out, first, ShifterOperand(second)); 3328 } else if (instruction->IsOr()) { 3329 __ orr(out, first, ShifterOperand(second)); 3330 } else { 3331 DCHECK(instruction->IsXor()); 3332 __ eor(out, first, ShifterOperand(second)); 3333 } 3334 } else { 3335 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); 3336 Location first = locations->InAt(0); 3337 Location second = locations->InAt(1); 3338 Location out = locations->Out(); 3339 if (instruction->IsAnd()) { 3340 __ and_(out.AsRegisterPairLow<Register>(), 3341 first.AsRegisterPairLow<Register>(), 3342 ShifterOperand(second.AsRegisterPairLow<Register>())); 3343 __ and_(out.AsRegisterPairHigh<Register>(), 3344 first.AsRegisterPairHigh<Register>(), 3345 ShifterOperand(second.AsRegisterPairHigh<Register>())); 3346 } else if (instruction->IsOr()) { 3347 __ orr(out.AsRegisterPairLow<Register>(), 3348 first.AsRegisterPairLow<Register>(), 3349 ShifterOperand(second.AsRegisterPairLow<Register>())); 3350 __ orr(out.AsRegisterPairHigh<Register>(), 3351 first.AsRegisterPairHigh<Register>(), 3352 ShifterOperand(second.AsRegisterPairHigh<Register>())); 3353 } else { 3354 DCHECK(instruction->IsXor()); 3355 __ eor(out.AsRegisterPairLow<Register>(), 3356 first.AsRegisterPairLow<Register>(), 3357 ShifterOperand(second.AsRegisterPairLow<Register>())); 3358 __ eor(out.AsRegisterPairHigh<Register>(), 3359 first.AsRegisterPairHigh<Register>(), 3360 ShifterOperand(second.AsRegisterPairHigh<Register>())); 3361 } 3362 } 3363} 3364 3365} // namespace arm 3366} // namespace art 3367