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 (void)RA; |
| 520 Asm->ret(); |
491 } | 521 } |
492 | 522 |
493 void InstMIPS32Ret::dump(const Cfg *Func) const { | 523 void InstMIPS32Ret::dump(const Cfg *Func) const { |
494 if (!BuildDefs::dump()) | 524 if (!BuildDefs::dump()) |
495 return; | 525 return; |
496 Ostream &Str = Func->getContext()->getStrDump(); | 526 Ostream &Str = Func->getContext()->getStrDump(); |
497 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); | 527 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); |
498 Str << "ret." << Ty << " "; | 528 Str << "ret." << Ty << " "; |
499 dumpSources(Func); | 529 dumpSources(Func); |
500 } | 530 } |
501 | 531 |
502 void InstMIPS32Mov::emit(const Cfg *Func) const { | 532 void InstMIPS32Mov::emit(const Cfg *Func) const { |
503 if (!BuildDefs::dump()) | 533 if (!BuildDefs::dump()) |
504 return; | 534 return; |
505 assert(!(isMultiDest() && isMultiSource()) && "Invalid vmov type."); | 535 assert(!(isMultiDest() && isMultiSource()) && "Invalid mov type."); |
506 if (isMultiDest()) { | 536 if (isMultiDest()) { |
507 emitMultiDestSingleSource(Func); | 537 emitMultiDestSingleSource(Func); |
508 return; | 538 return; |
509 } | 539 } |
510 | 540 |
511 if (isMultiSource()) { | 541 if (isMultiSource()) { |
512 emitSingleDestMultiSource(Func); | 542 emitSingleDestMultiSource(Func); |
513 return; | 543 return; |
514 } | 544 } |
515 | 545 |
516 emitSingleDestSingleSource(Func); | 546 emitSingleDestSingleSource(Func); |
517 } | 547 } |
518 | 548 |
| 549 // TODO(jaydeep.patil) Handle all types of operands in mov |
519 void InstMIPS32Mov::emitIAS(const Cfg *Func) const { | 550 void InstMIPS32Mov::emitIAS(const Cfg *Func) const { |
520 assert(getSrcSize() == 1); | 551 assert(!(isMultiDest() && isMultiSource()) && "Invalid mov type."); |
521 (void)Func; | 552 |
| 553 if (isMultiDest()) { |
| 554 llvm_unreachable("Not yet implemented"); |
| 555 } |
| 556 if (isMultiSource()) { |
| 557 llvm_unreachable("Not yet implemented"); |
| 558 } |
| 559 |
| 560 Variable *Dest = getDest(); |
| 561 Operand *Src = getSrc(0); |
| 562 auto *SrcV = llvm::dyn_cast<Variable>(Src); |
| 563 assert(!llvm::isa<Constant>(Src)); |
| 564 const bool DestIsReg = Dest->hasReg(); |
| 565 const bool SrcIsReg = (SrcV && SrcV->hasReg()); |
| 566 |
| 567 // reg to reg |
| 568 if (DestIsReg && SrcIsReg) { |
| 569 switch (Dest->getType()) { |
| 570 default: |
| 571 break; |
| 572 case IceType_i1: |
| 573 case IceType_i8: |
| 574 case IceType_i16: |
| 575 case IceType_i32: |
| 576 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 577 Asm->move(getDest(), getSrc(0)); |
| 578 return; |
| 579 } |
| 580 } |
522 llvm_unreachable("Not yet implemented"); | 581 llvm_unreachable("Not yet implemented"); |
523 } | 582 } |
524 | 583 |
525 void InstMIPS32Mov::dump(const Cfg *Func) const { | 584 void InstMIPS32Mov::dump(const Cfg *Func) const { |
526 if (!BuildDefs::dump()) | 585 if (!BuildDefs::dump()) |
527 return; | 586 return; |
528 assert(getSrcSize() == 1 || getSrcSize() == 2); | 587 assert(getSrcSize() == 1 || getSrcSize() == 2); |
529 Ostream &Str = Func->getContext()->getStrDump(); | 588 Ostream &Str = Func->getContext()->getStrDump(); |
530 Variable *Dest = getDest(); | 589 Variable *Dest = getDest(); |
531 Variable *DestHi = getDestHi(); | 590 Variable *DestHi = getDestHi(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 ActualOpcode = "mov.s"; | 666 ActualOpcode = "mov.s"; |
608 break; | 667 break; |
609 case IceType_f64: | 668 case IceType_f64: |
610 ActualOpcode = "mov.d"; | 669 ActualOpcode = "mov.d"; |
611 break; | 670 break; |
612 case IceType_i1: | 671 case IceType_i1: |
613 case IceType_i8: | 672 case IceType_i8: |
614 case IceType_i16: | 673 case IceType_i16: |
615 case IceType_i32: | 674 case IceType_i32: |
616 Str << "\t" | 675 Str << "\t" |
617 "add" | 676 "move" |
618 "\t"; | 677 "\t"; |
619 getDest()->emit(Func); | 678 getDest()->emit(Func); |
620 Str << ", $zero, "; | 679 Str << ", "; |
621 getSrc(0)->emit(Func); | 680 getSrc(0)->emit(Func); |
622 return; | 681 return; |
623 default: | 682 default: |
624 UnimplementedError(getFlags()); | 683 UnimplementedError(getFlags()); |
625 return; | 684 return; |
626 } | 685 } |
627 | 686 |
628 assert(ActualOpcode); | 687 assert(ActualOpcode); |
629 Str << "\t" << ActualOpcode << "\t"; | 688 Str << "\t" << ActualOpcode << "\t"; |
630 getDest()->emit(Func); | 689 getDest()->emit(Func); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 getDest()->emit(Func); | 745 getDest()->emit(Func); |
687 Str << ", "; | 746 Str << ", "; |
688 getSrc(0)->emit(Func); | 747 getSrc(0)->emit(Func); |
689 return; | 748 return; |
690 } | 749 } |
691 | 750 |
692 // stack to stack | 751 // stack to stack |
693 llvm::report_fatal_error("mov cant copy stack to stack."); | 752 llvm::report_fatal_error("mov cant copy stack to stack."); |
694 } | 753 } |
695 | 754 |
| 755 template <> void InstMIPS32Addiu::emitIAS(const Cfg *Func) const { |
| 756 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 757 Asm->addiu(getDest(), getSrc(0), Imm); |
| 758 } |
| 759 |
| 760 template <> void InstMIPS32Slti::emitIAS(const Cfg *Func) const { |
| 761 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 762 Asm->slti(getDest(), getSrc(0), Imm); |
| 763 } |
| 764 |
| 765 template <> void InstMIPS32Sltiu::emitIAS(const Cfg *Func) const { |
| 766 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 767 Asm->sltiu(getDest(), getSrc(0), Imm); |
| 768 } |
| 769 |
| 770 template <> void InstMIPS32And::emitIAS(const Cfg *Func) const { |
| 771 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 772 Asm->and_(getDest(), getSrc(0), getSrc(1)); |
| 773 } |
| 774 |
| 775 template <> void InstMIPS32Andi::emitIAS(const Cfg *Func) const { |
| 776 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 777 Asm->andi(getDest(), getSrc(0), Imm); |
| 778 } |
| 779 |
| 780 template <> void InstMIPS32Or::emitIAS(const Cfg *Func) const { |
| 781 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 782 Asm->or_(getDest(), getSrc(0), getSrc(1)); |
| 783 } |
| 784 |
| 785 template <> void InstMIPS32Ori::emitIAS(const Cfg *Func) const { |
| 786 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 787 Asm->ori(getDest(), getSrc(0), Imm); |
| 788 } |
| 789 |
| 790 template <> void InstMIPS32Xor::emitIAS(const Cfg *Func) const { |
| 791 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 792 Asm->xor_(getDest(), getSrc(0), getSrc(1)); |
| 793 } |
| 794 |
| 795 template <> void InstMIPS32Xori::emitIAS(const Cfg *Func) const { |
| 796 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 797 Asm->xori(getDest(), getSrc(0), Imm); |
| 798 } |
| 799 |
| 800 template <> void InstMIPS32Sll::emitIAS(const Cfg *Func) const { |
| 801 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 802 Asm->sll(getDest(), getSrc(0), Imm); |
| 803 } |
| 804 |
| 805 template <> void InstMIPS32Srl::emitIAS(const Cfg *Func) const { |
| 806 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 807 Asm->srl(getDest(), getSrc(0), Imm); |
| 808 } |
| 809 |
| 810 template <> void InstMIPS32Sra::emitIAS(const Cfg *Func) const { |
| 811 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 812 Asm->sra(getDest(), getSrc(0), Imm); |
| 813 } |
| 814 |
| 815 template <> void InstMIPS32Addu::emitIAS(const Cfg *Func) const { |
| 816 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 817 Asm->addu(getDest(), getSrc(0), getSrc(1)); |
| 818 } |
| 819 |
| 820 template <> void InstMIPS32Slt::emitIAS(const Cfg *Func) const { |
| 821 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 822 Asm->slt(getDest(), getSrc(0), getSrc(1)); |
| 823 } |
| 824 |
| 825 template <> void InstMIPS32Sltu::emitIAS(const Cfg *Func) const { |
| 826 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 827 Asm->sltu(getDest(), getSrc(0), getSrc(1)); |
| 828 } |
| 829 |
| 830 template <> void InstMIPS32Sw::emitIAS(const Cfg *Func) const { |
| 831 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 832 auto *Mem = llvm::dyn_cast<OperandMIPS32Mem>(getSrc(1)); |
| 833 ConstantInteger32 *Offset = llvm::cast<ConstantInteger32>(Mem->getOffset()); |
| 834 uint32_t Imm = static_cast<uint32_t>(Offset->getValue()); |
| 835 Asm->sw(getSrc(0), Mem->getBase(), Imm); |
| 836 } |
| 837 |
| 838 template <> void InstMIPS32Lw::emitIAS(const Cfg *Func) const { |
| 839 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 840 auto *Mem = llvm::dyn_cast<OperandMIPS32Mem>(getSrc(0)); |
| 841 ConstantInteger32 *Offset = llvm::cast<ConstantInteger32>(Mem->getOffset()); |
| 842 uint32_t Imm = static_cast<uint32_t>(Offset->getValue()); |
| 843 Asm->lw(getDest(), Mem->getBase(), Imm); |
| 844 } |
| 845 |
696 } // end of namespace MIPS32 | 846 } // end of namespace MIPS32 |
697 } // end of namespace Ice | 847 } // end of namespace Ice |
OLD | NEW |