OLD | NEW |
1 //===- subzero/src/IceInstMips32.cpp - Mips32 instruction implementation --===// | 1 //===- subzero/src/IceInstMips32.cpp - Mips32 instruction implementation --===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 /// \file | 10 /// \file |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 auto *RA = llvm::cast<Variable>(getSrc(0)); | 377 auto *RA = llvm::cast<Variable>(getSrc(0)); |
378 assert(RA->hasReg()); | 378 assert(RA->hasReg()); |
379 assert(RA->getRegNum() == RegMIPS32::Reg_RA); | 379 assert(RA->getRegNum() == RegMIPS32::Reg_RA); |
380 Ostream &Str = Func->getContext()->getStrEmit(); | 380 Ostream &Str = Func->getContext()->getStrEmit(); |
381 Str << "\t" | 381 Str << "\t" |
382 "jr" | 382 "jr" |
383 "\t"; | 383 "\t"; |
384 RA->emit(Func); | 384 RA->emit(Func); |
385 } | 385 } |
386 | 386 |
| 387 void InstMIPS32Br::emitIAS(const Cfg *Func) const { |
| 388 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 389 if (isUnconditionalBranch()) { |
| 390 Asm->b(Asm->getOrCreateCfgNodeLabel(getTargetFalse()->getIndex())); |
| 391 } else { |
| 392 switch (Predicate) { |
| 393 default: |
| 394 break; |
| 395 case CondMIPS32::EQ: |
| 396 case CondMIPS32::NE: |
| 397 Asm->bcc(Predicate, getSrc(0), getSrc(1), |
| 398 Asm->getOrCreateCfgNodeLabel(getTargetFalse()->getIndex())); |
| 399 break; |
| 400 case CondMIPS32::EQZ: |
| 401 case CondMIPS32::NEZ: |
| 402 case CondMIPS32::LEZ: |
| 403 case CondMIPS32::LTZ: |
| 404 case CondMIPS32::GEZ: |
| 405 case CondMIPS32::GTZ: |
| 406 Asm->bzc(Predicate, getSrc(0), |
| 407 Asm->getOrCreateCfgNodeLabel(getTargetFalse()->getIndex())); |
| 408 break; |
| 409 } |
| 410 } |
| 411 } |
| 412 |
387 void InstMIPS32Br::emit(const Cfg *Func) const { | 413 void InstMIPS32Br::emit(const Cfg *Func) const { |
388 if (!BuildDefs::dump()) | 414 if (!BuildDefs::dump()) |
389 return; | 415 return; |
390 Ostream &Str = Func->getContext()->getStrEmit(); | 416 Ostream &Str = Func->getContext()->getStrEmit(); |
391 Str << "\t" | 417 Str << "\t" |
392 "b" << InstMIPS32CondAttributes[Predicate].EmitString << "\t"; | 418 "b" << InstMIPS32CondAttributes[Predicate].EmitString << "\t"; |
393 if (Label) { | 419 if (Label) { |
394 Str << Label->getLabelName(); | 420 Str << Label->getLabelName(); |
395 } else { | 421 } else { |
396 if (isUnconditionalBranch()) { | 422 if (isUnconditionalBranch()) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 Ostream &Str = Func->getContext()->getStrDump(); | 505 Ostream &Str = Func->getContext()->getStrDump(); |
480 if (getDest()) { | 506 if (getDest()) { |
481 dumpDest(Func); | 507 dumpDest(Func); |
482 Str << " = "; | 508 Str << " = "; |
483 } | 509 } |
484 Str << "call "; | 510 Str << "call "; |
485 getCallTarget()->dump(Func); | 511 getCallTarget()->dump(Func); |
486 } | 512 } |
487 | 513 |
488 void InstMIPS32Ret::emitIAS(const Cfg *Func) const { | 514 void InstMIPS32Ret::emitIAS(const Cfg *Func) const { |
489 (void)Func; | 515 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
490 llvm_unreachable("Not yet implemented"); | 516 auto *RA = llvm::cast<Variable>(getSrc(0)); |
| 517 assert(RA->hasReg()); |
| 518 assert(RA->getRegNum() == RegMIPS32::Reg_RA); |
| 519 Asm->ret(); |
491 } | 520 } |
492 | 521 |
493 void InstMIPS32Ret::dump(const Cfg *Func) const { | 522 void InstMIPS32Ret::dump(const Cfg *Func) const { |
494 if (!BuildDefs::dump()) | 523 if (!BuildDefs::dump()) |
495 return; | 524 return; |
496 Ostream &Str = Func->getContext()->getStrDump(); | 525 Ostream &Str = Func->getContext()->getStrDump(); |
497 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); | 526 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); |
498 Str << "ret." << Ty << " "; | 527 Str << "ret." << Ty << " "; |
499 dumpSources(Func); | 528 dumpSources(Func); |
500 } | 529 } |
501 | 530 |
502 void InstMIPS32Mov::emit(const Cfg *Func) const { | 531 void InstMIPS32Mov::emit(const Cfg *Func) const { |
503 if (!BuildDefs::dump()) | 532 if (!BuildDefs::dump()) |
504 return; | 533 return; |
505 assert(!(isMultiDest() && isMultiSource()) && "Invalid vmov type."); | 534 assert(!(isMultiDest() && isMultiSource()) && "Invalid mov type."); |
506 if (isMultiDest()) { | 535 if (isMultiDest()) { |
507 emitMultiDestSingleSource(Func); | 536 emitMultiDestSingleSource(Func); |
508 return; | 537 return; |
509 } | 538 } |
510 | 539 |
511 if (isMultiSource()) { | 540 if (isMultiSource()) { |
512 emitSingleDestMultiSource(Func); | 541 emitSingleDestMultiSource(Func); |
513 return; | 542 return; |
514 } | 543 } |
515 | 544 |
516 emitSingleDestSingleSource(Func); | 545 emitSingleDestSingleSource(Func); |
517 } | 546 } |
518 | 547 |
| 548 // TODO(jaydeep.patil) Handle all types of operands in mov |
519 void InstMIPS32Mov::emitIAS(const Cfg *Func) const { | 549 void InstMIPS32Mov::emitIAS(const Cfg *Func) const { |
520 assert(getSrcSize() == 1); | 550 assert(!(isMultiDest() && isMultiSource()) && "Invalid mov type."); |
521 (void)Func; | 551 |
| 552 if (isMultiDest()) { |
| 553 llvm_unreachable("Not yet implemented"); |
| 554 } |
| 555 if (isMultiSource()) { |
| 556 llvm_unreachable("Not yet implemented"); |
| 557 } |
| 558 |
| 559 Variable *Dest = getDest(); |
| 560 Operand *Src = getSrc(0); |
| 561 auto *SrcV = llvm::dyn_cast<Variable>(Src); |
| 562 assert(!llvm::isa<Constant>(Src)); |
| 563 const bool DestIsReg = Dest->hasReg(); |
| 564 const bool SrcIsReg = (SrcV && SrcV->hasReg()); |
| 565 |
| 566 // reg to reg |
| 567 if (DestIsReg && SrcIsReg) { |
| 568 switch (Dest->getType()) { |
| 569 default: |
| 570 break; |
| 571 case IceType_i1: |
| 572 case IceType_i8: |
| 573 case IceType_i16: |
| 574 case IceType_i32: |
| 575 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 576 Asm->move(getDest(), getSrc(0)); |
| 577 return; |
| 578 } |
| 579 } |
522 llvm_unreachable("Not yet implemented"); | 580 llvm_unreachable("Not yet implemented"); |
523 } | 581 } |
524 | 582 |
525 void InstMIPS32Mov::dump(const Cfg *Func) const { | 583 void InstMIPS32Mov::dump(const Cfg *Func) const { |
526 if (!BuildDefs::dump()) | 584 if (!BuildDefs::dump()) |
527 return; | 585 return; |
528 assert(getSrcSize() == 1 || getSrcSize() == 2); | 586 assert(getSrcSize() == 1 || getSrcSize() == 2); |
529 Ostream &Str = Func->getContext()->getStrDump(); | 587 Ostream &Str = Func->getContext()->getStrDump(); |
530 Variable *Dest = getDest(); | 588 Variable *Dest = getDest(); |
531 Variable *DestHi = getDestHi(); | 589 Variable *DestHi = getDestHi(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 ActualOpcode = "mov.s"; | 665 ActualOpcode = "mov.s"; |
608 break; | 666 break; |
609 case IceType_f64: | 667 case IceType_f64: |
610 ActualOpcode = "mov.d"; | 668 ActualOpcode = "mov.d"; |
611 break; | 669 break; |
612 case IceType_i1: | 670 case IceType_i1: |
613 case IceType_i8: | 671 case IceType_i8: |
614 case IceType_i16: | 672 case IceType_i16: |
615 case IceType_i32: | 673 case IceType_i32: |
616 Str << "\t" | 674 Str << "\t" |
617 "add" | 675 "move" |
618 "\t"; | 676 "\t"; |
619 getDest()->emit(Func); | 677 getDest()->emit(Func); |
620 Str << ", $zero, "; | 678 Str << ", "; |
621 getSrc(0)->emit(Func); | 679 getSrc(0)->emit(Func); |
622 return; | 680 return; |
623 default: | 681 default: |
624 UnimplementedError(getFlags()); | 682 UnimplementedError(getFlags()); |
625 return; | 683 return; |
626 } | 684 } |
627 | 685 |
628 assert(ActualOpcode); | 686 assert(ActualOpcode); |
629 Str << "\t" << ActualOpcode << "\t"; | 687 Str << "\t" << ActualOpcode << "\t"; |
630 getDest()->emit(Func); | 688 getDest()->emit(Func); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 getDest()->emit(Func); | 744 getDest()->emit(Func); |
687 Str << ", "; | 745 Str << ", "; |
688 getSrc(0)->emit(Func); | 746 getSrc(0)->emit(Func); |
689 return; | 747 return; |
690 } | 748 } |
691 | 749 |
692 // stack to stack | 750 // stack to stack |
693 llvm::report_fatal_error("mov cant copy stack to stack."); | 751 llvm::report_fatal_error("mov cant copy stack to stack."); |
694 } | 752 } |
695 | 753 |
| 754 template <> void InstMIPS32Addiu::emitIAS(const Cfg *Func) const { |
| 755 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 756 Asm->addiu(getDest(), getSrc(0), Imm); |
| 757 } |
| 758 |
| 759 template <> void InstMIPS32Slti::emitIAS(const Cfg *Func) const { |
| 760 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 761 Asm->slti(getDest(), getSrc(0), Imm); |
| 762 } |
| 763 |
| 764 template <> void InstMIPS32Sltiu::emitIAS(const Cfg *Func) const { |
| 765 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 766 Asm->sltiu(getDest(), getSrc(0), Imm); |
| 767 } |
| 768 |
| 769 template <> void InstMIPS32And::emitIAS(const Cfg *Func) const { |
| 770 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 771 Asm->and_(getDest(), getSrc(0), getSrc(1)); |
| 772 } |
| 773 |
| 774 template <> void InstMIPS32Andi::emitIAS(const Cfg *Func) const { |
| 775 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 776 Asm->andi(getDest(), getSrc(0), Imm); |
| 777 } |
| 778 |
| 779 template <> void InstMIPS32Or::emitIAS(const Cfg *Func) const { |
| 780 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 781 Asm->or_(getDest(), getSrc(0), getSrc(1)); |
| 782 } |
| 783 |
| 784 template <> void InstMIPS32Ori::emitIAS(const Cfg *Func) const { |
| 785 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 786 Asm->ori(getDest(), getSrc(0), Imm); |
| 787 } |
| 788 |
| 789 template <> void InstMIPS32Xor::emitIAS(const Cfg *Func) const { |
| 790 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 791 Asm->xor_(getDest(), getSrc(0), getSrc(1)); |
| 792 } |
| 793 |
| 794 template <> void InstMIPS32Xori::emitIAS(const Cfg *Func) const { |
| 795 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 796 Asm->xori(getDest(), getSrc(0), Imm); |
| 797 } |
| 798 |
| 799 template <> void InstMIPS32Sll::emitIAS(const Cfg *Func) const { |
| 800 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 801 Asm->sll(getDest(), getSrc(0), Imm); |
| 802 } |
| 803 |
| 804 template <> void InstMIPS32Srl::emitIAS(const Cfg *Func) const { |
| 805 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 806 Asm->srl(getDest(), getSrc(0), Imm); |
| 807 } |
| 808 |
| 809 template <> void InstMIPS32Sra::emitIAS(const Cfg *Func) const { |
| 810 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 811 Asm->sra(getDest(), getSrc(0), Imm); |
| 812 } |
| 813 |
| 814 template <> void InstMIPS32Addu::emitIAS(const Cfg *Func) const { |
| 815 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 816 Asm->addu(getDest(), getSrc(0), getSrc(1)); |
| 817 } |
| 818 |
| 819 template <> void InstMIPS32Slt::emitIAS(const Cfg *Func) const { |
| 820 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 821 Asm->slt(getDest(), getSrc(0), getSrc(1)); |
| 822 } |
| 823 |
| 824 template <> void InstMIPS32Sltu::emitIAS(const Cfg *Func) const { |
| 825 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 826 Asm->sltu(getDest(), getSrc(0), getSrc(1)); |
| 827 } |
| 828 |
| 829 template <> void InstMIPS32Sw::emitIAS(const Cfg *Func) const { |
| 830 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 831 auto *Mem = llvm::dyn_cast<OperandMIPS32Mem>(getSrc(1)); |
| 832 ConstantInteger32 *Offset = llvm::cast<ConstantInteger32>(Mem->getOffset()); |
| 833 uint32_t Imm = static_cast<uint32_t>(Offset->getValue()); |
| 834 Asm->sw(getSrc(0), Mem->getBase(), Imm); |
| 835 } |
| 836 |
| 837 template <> void InstMIPS32Lw::emitIAS(const Cfg *Func) const { |
| 838 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 839 auto *Mem = llvm::dyn_cast<OperandMIPS32Mem>(getSrc(0)); |
| 840 ConstantInteger32 *Offset = llvm::cast<ConstantInteger32>(Mem->getOffset()); |
| 841 uint32_t Imm = static_cast<uint32_t>(Offset->getValue()); |
| 842 Asm->lw(getDest(), Mem->getBase(), Imm); |
| 843 } |
| 844 |
696 } // end of namespace MIPS32 | 845 } // end of namespace MIPS32 |
697 } // end of namespace Ice | 846 } // end of namespace Ice |
OLD | NEW |