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 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 getDest()->emit(Func); | 715 getDest()->emit(Func); |
687 Str << ", "; | 716 Str << ", "; |
688 getSrc(0)->emit(Func); | 717 getSrc(0)->emit(Func); |
689 return; | 718 return; |
690 } | 719 } |
691 | 720 |
692 // stack to stack | 721 // stack to stack |
693 llvm::report_fatal_error("mov cant copy stack to stack."); | 722 llvm::report_fatal_error("mov cant copy stack to stack."); |
694 } | 723 } |
695 | 724 |
| 725 template <> void InstMIPS32Addiu::emitIAS(const Cfg *Func) const { |
| 726 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 727 Asm->addiu(getDest(), getSrc(0), (const uint32_t) Imm); |
| 728 } |
| 729 |
| 730 template <> void InstMIPS32Slti::emitIAS(const Cfg *Func) const { |
| 731 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 732 Asm->slti(getDest(), getSrc(0), (const uint32_t) Imm); |
| 733 } |
| 734 |
| 735 template <> void InstMIPS32Sltiu::emitIAS(const Cfg *Func) const { |
| 736 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 737 Asm->sltiu(getDest(), getSrc(0), (const uint32_t) Imm); |
| 738 } |
| 739 |
| 740 template <> void InstMIPS32Andi::emitIAS(const Cfg *Func) const { |
| 741 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 742 Asm->andi(getDest(), getSrc(0), (const uint32_t) Imm); |
| 743 } |
| 744 |
| 745 template <> void InstMIPS32Ori::emitIAS(const Cfg *Func) const { |
| 746 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 747 Asm->ori(getDest(), getSrc(0), (const uint32_t) Imm); |
| 748 } |
| 749 |
| 750 template <> void InstMIPS32Xori::emitIAS(const Cfg *Func) const { |
| 751 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 752 Asm->xori(getDest(), getSrc(0), (const uint32_t) Imm); |
| 753 } |
| 754 |
| 755 template <> void InstMIPS32Sll::emitIAS(const Cfg *Func) const { |
| 756 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 757 Asm->sll(getDest(), getSrc(0), (const uint32_t) Imm); |
| 758 } |
| 759 |
| 760 template <> void InstMIPS32Srl::emitIAS(const Cfg *Func) const { |
| 761 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 762 Asm->srl(getDest(), getSrc(0), (const uint32_t) Imm); |
| 763 } |
| 764 |
| 765 template <> void InstMIPS32Sra::emitIAS(const Cfg *Func) const { |
| 766 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 767 Asm->sra(getDest(), getSrc(0), (const uint32_t) Imm); |
| 768 } |
| 769 |
| 770 template <> void InstMIPS32Addu::emitIAS(const Cfg *Func) const { |
| 771 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 772 Asm->addu(getDest(), getSrc(0), getSrc(1)); |
| 773 } |
| 774 |
| 775 template <> void InstMIPS32Slt::emitIAS(const Cfg *Func) const { |
| 776 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 777 Asm->slt(getDest(), getSrc(0), getSrc(1)); |
| 778 } |
| 779 |
| 780 template <> void InstMIPS32Sw::emitIAS(const Cfg *Func) const { |
| 781 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 782 auto *Mem = llvm::dyn_cast<OperandMIPS32Mem>(getSrc(1)); |
| 783 ConstantInteger32 *Offset = llvm::cast<ConstantInteger32>(Mem->getOffset()); |
| 784 uint32_t Imm = static_cast<uint32_t>(Offset->getValue()); |
| 785 Asm->sw(getSrc(0), Mem->getBase(), Imm); |
| 786 } |
| 787 |
| 788 template <> void InstMIPS32Lw::emitIAS(const Cfg *Func) const { |
| 789 auto *Asm = Func->getAssembler<MIPS32::AssemblerMIPS32>(); |
| 790 auto *Mem = llvm::dyn_cast<OperandMIPS32Mem>(getSrc(0)); |
| 791 ConstantInteger32 *Offset = llvm::cast<ConstantInteger32>(Mem->getOffset()); |
| 792 uint32_t Imm = static_cast<uint32_t>(Offset->getValue()); |
| 793 Asm->lw(getDest(), Mem->getBase(), Imm); |
| 794 } |
| 795 |
696 } // end of namespace MIPS32 | 796 } // end of namespace MIPS32 |
697 } // end of namespace Ice | 797 } // end of namespace Ice |
OLD | NEW |