OLD | NEW |
1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8632.cpp - X86-32 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 // This file implements the InstX8632 and OperandX8632 classes, | 10 // This file implements the InstX8632 and OperandX8632 classes, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 InstX8632Label *Label, InstX8632::BrCond Condition) | 129 InstX8632Label *Label, InstX8632::BrCond Condition) |
130 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), | 130 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), |
131 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} | 131 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} |
132 | 132 |
133 InstX8632Call::InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget) | 133 InstX8632Call::InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget) |
134 : InstX8632(Func, InstX8632::Call, 1, Dest) { | 134 : InstX8632(Func, InstX8632::Call, 1, Dest) { |
135 HasSideEffects = true; | 135 HasSideEffects = true; |
136 addSource(CallTarget); | 136 addSource(CallTarget); |
137 } | 137 } |
138 | 138 |
139 InstX8632Cbwdq::InstX8632Cbwdq(Cfg *Func, Variable *Dest, Operand *Source) | |
140 : InstX8632(Func, InstX8632::Cbwdq, 1, Dest) { | |
141 addSource(Source); | |
142 } | |
143 | |
144 InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, | 139 InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, |
145 InstX8632::BrCond Condition) | 140 InstX8632::BrCond Condition) |
146 : InstX8632(Func, InstX8632::Cmov, 2, Dest), Condition(Condition) { | 141 : InstX8632(Func, InstX8632::Cmov, 2, Dest), Condition(Condition) { |
147 // The final result is either the original Dest, or Source, so mark | 142 // The final result is either the original Dest, or Source, so mark |
148 // both as sources. | 143 // both as sources. |
149 addSource(Dest); | 144 addSource(Dest); |
150 addSource(Source); | 145 addSource(Source); |
151 } | 146 } |
152 | 147 |
153 InstX8632Cmpps::InstX8632Cmpps(Cfg *Func, Variable *Dest, Operand *Source, | 148 InstX8632Cmpps::InstX8632Cmpps(Cfg *Func, Variable *Dest, Operand *Source, |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 440 |
446 // In-place ops | 441 // In-place ops |
447 template <> const char *InstX8632Bswap::Opcode = "bswap"; | 442 template <> const char *InstX8632Bswap::Opcode = "bswap"; |
448 template <> const char *InstX8632Neg::Opcode = "neg"; | 443 template <> const char *InstX8632Neg::Opcode = "neg"; |
449 // Unary ops | 444 // Unary ops |
450 template <> const char *InstX8632Bsf::Opcode = "bsf"; | 445 template <> const char *InstX8632Bsf::Opcode = "bsf"; |
451 template <> const char *InstX8632Bsr::Opcode = "bsr"; | 446 template <> const char *InstX8632Bsr::Opcode = "bsr"; |
452 template <> const char *InstX8632Lea::Opcode = "lea"; | 447 template <> const char *InstX8632Lea::Opcode = "lea"; |
453 template <> const char *InstX8632Movd::Opcode = "movd"; | 448 template <> const char *InstX8632Movd::Opcode = "movd"; |
454 template <> const char *InstX8632Sqrtss::Opcode = "sqrtss"; | 449 template <> const char *InstX8632Sqrtss::Opcode = "sqrtss"; |
| 450 template <> const char *InstX8632Cbwdq::Opcode = "cbw/cwd/cdq"; |
455 // Binary ops | 451 // Binary ops |
456 template <> const char *InstX8632Add::Opcode = "add"; | 452 template <> const char *InstX8632Add::Opcode = "add"; |
457 template <> const char *InstX8632Addps::Opcode = "addps"; | 453 template <> const char *InstX8632Addps::Opcode = "addps"; |
458 template <> const char *InstX8632Adc::Opcode = "adc"; | 454 template <> const char *InstX8632Adc::Opcode = "adc"; |
459 template <> const char *InstX8632Addss::Opcode = "addss"; | 455 template <> const char *InstX8632Addss::Opcode = "addss"; |
460 template <> const char *InstX8632Padd::Opcode = "padd"; | 456 template <> const char *InstX8632Padd::Opcode = "padd"; |
461 template <> const char *InstX8632Sub::Opcode = "sub"; | 457 template <> const char *InstX8632Sub::Opcode = "sub"; |
462 template <> const char *InstX8632Subps::Opcode = "subps"; | 458 template <> const char *InstX8632Subps::Opcode = "subps"; |
463 template <> const char *InstX8632Subss::Opcode = "subss"; | 459 template <> const char *InstX8632Subss::Opcode = "subss"; |
464 template <> const char *InstX8632Sbb::Opcode = "sbb"; | 460 template <> const char *InstX8632Sbb::Opcode = "sbb"; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 Str << ", "; | 636 Str << ", "; |
641 getSrc(0)->emit(Func); | 637 getSrc(0)->emit(Func); |
642 Str << ", "; | 638 Str << ", "; |
643 getSrc(1)->emit(Func); | 639 getSrc(1)->emit(Func); |
644 Str << "\n"; | 640 Str << "\n"; |
645 } else { | 641 } else { |
646 emitTwoAddress("imul", this, Func); | 642 emitTwoAddress("imul", this, Func); |
647 } | 643 } |
648 } | 644 } |
649 | 645 |
| 646 template <> void InstX8632Cbwdq::emit(const Cfg *Func) const { |
| 647 Ostream &Str = Func->getContext()->getStrEmit(); |
| 648 assert(getSrcSize() == 1); |
| 649 Operand *Src0 = getSrc(0); |
| 650 assert(llvm::isa<Variable>(Src0)); |
| 651 assert(llvm::cast<Variable>(Src0)->getRegNum() == TargetX8632::Reg_eax); |
| 652 switch (Src0->getType()) { |
| 653 default: |
| 654 llvm_unreachable("unexpected source type!"); |
| 655 break; |
| 656 case IceType_i8: |
| 657 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); |
| 658 Str << "\tcbw\n"; |
| 659 break; |
| 660 case IceType_i16: |
| 661 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); |
| 662 Str << "\tcwd\n"; |
| 663 break; |
| 664 case IceType_i32: |
| 665 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); |
| 666 Str << "\tcdq\n"; |
| 667 break; |
| 668 } |
| 669 } |
| 670 |
650 void InstX8632Mul::emit(const Cfg *Func) const { | 671 void InstX8632Mul::emit(const Cfg *Func) const { |
651 Ostream &Str = Func->getContext()->getStrEmit(); | 672 Ostream &Str = Func->getContext()->getStrEmit(); |
652 assert(getSrcSize() == 2); | 673 assert(getSrcSize() == 2); |
653 assert(llvm::isa<Variable>(getSrc(0))); | 674 assert(llvm::isa<Variable>(getSrc(0))); |
654 assert(llvm::dyn_cast<Variable>(getSrc(0))->getRegNum() == | 675 assert(llvm::dyn_cast<Variable>(getSrc(0))->getRegNum() == |
655 TargetX8632::Reg_eax); | 676 TargetX8632::Reg_eax); |
656 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); // TODO: allow edx? | 677 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); // TODO: allow edx? |
657 Str << "\tmul\t"; | 678 Str << "\tmul\t"; |
658 getSrc(1)->emit(Func); | 679 getSrc(1)->emit(Func); |
659 Str << "\n"; | 680 Str << "\n"; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 Str << "\n"; | 732 Str << "\n"; |
712 } | 733 } |
713 | 734 |
714 void InstX8632Shrd::dump(const Cfg *Func) const { | 735 void InstX8632Shrd::dump(const Cfg *Func) const { |
715 Ostream &Str = Func->getContext()->getStrDump(); | 736 Ostream &Str = Func->getContext()->getStrDump(); |
716 dumpDest(Func); | 737 dumpDest(Func); |
717 Str << " = shrd." << getDest()->getType() << " "; | 738 Str << " = shrd." << getDest()->getType() << " "; |
718 dumpSources(Func); | 739 dumpSources(Func); |
719 } | 740 } |
720 | 741 |
721 void InstX8632Cbwdq::emit(const Cfg *Func) const { | |
722 Ostream &Str = Func->getContext()->getStrEmit(); | |
723 assert(getSrcSize() == 1); | |
724 Operand *Src0 = getSrc(0); | |
725 assert(llvm::isa<Variable>(Src0)); | |
726 assert(llvm::cast<Variable>(Src0)->getRegNum() == TargetX8632::Reg_eax); | |
727 switch (Src0->getType()) { | |
728 default: | |
729 llvm_unreachable("unexpected source type!"); | |
730 break; | |
731 case IceType_i8: | |
732 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); | |
733 Str << "\tcbw\n"; | |
734 break; | |
735 case IceType_i16: | |
736 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); | |
737 Str << "\tcwd\n"; | |
738 break; | |
739 case IceType_i32: | |
740 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); | |
741 Str << "\tcdq\n"; | |
742 break; | |
743 } | |
744 } | |
745 | |
746 void InstX8632Cbwdq::dump(const Cfg *Func) const { | |
747 Ostream &Str = Func->getContext()->getStrDump(); | |
748 dumpDest(Func); | |
749 Str << " = cbw/cwd/cdq." << getSrc(0)->getType() << " "; | |
750 dumpSources(Func); | |
751 } | |
752 | |
753 void InstX8632Cmov::emit(const Cfg *Func) const { | 742 void InstX8632Cmov::emit(const Cfg *Func) const { |
754 Ostream &Str = Func->getContext()->getStrEmit(); | 743 Ostream &Str = Func->getContext()->getStrEmit(); |
755 Str << "\t"; | 744 Str << "\t"; |
756 assert(Condition != Br_None); | 745 assert(Condition != Br_None); |
757 assert(getDest()->hasReg()); | 746 assert(getDest()->hasReg()); |
758 Str << "cmov" << InstX8632BrAttributes[Condition].DisplayString << "\t"; | 747 Str << "cmov" << InstX8632BrAttributes[Condition].DisplayString << "\t"; |
759 getDest()->emit(Func); | 748 getDest()->emit(Func); |
760 Str << ", "; | 749 Str << ", "; |
761 getSrc(1)->emit(Func); | 750 getSrc(1)->emit(Func); |
762 Str << "\n"; | 751 Str << "\n"; |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 default: | 1472 default: |
1484 Str << "???"; | 1473 Str << "???"; |
1485 break; | 1474 break; |
1486 } | 1475 } |
1487 Str << "("; | 1476 Str << "("; |
1488 Var->dump(Func); | 1477 Var->dump(Func); |
1489 Str << ")"; | 1478 Str << ")"; |
1490 } | 1479 } |
1491 | 1480 |
1492 } // end of namespace Ice | 1481 } // end of namespace Ice |
OLD | NEW |