Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceInstX86Base.h - Generic x86 instructions -*- C++ -*--===// | 1 //===- subzero/src/IceInstX86Base.h - Generic x86 instructions -*- C++ -*--===// |
| 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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 : InstX86Base(Func, K, 1, llvm::dyn_cast<Variable>(SrcDest)) { | 580 : InstX86Base(Func, K, 1, llvm::dyn_cast<Variable>(SrcDest)) { |
| 581 this->addSource(SrcDest); | 581 this->addSource(SrcDest); |
| 582 } | 582 } |
| 583 | 583 |
| 584 private: | 584 private: |
| 585 static const char *Opcode; | 585 static const char *Opcode; |
| 586 static const GPREmitterOneOp Emitter; | 586 static const GPREmitterOneOp Emitter; |
| 587 }; | 587 }; |
| 588 | 588 |
| 589 /// Instructions of the form x := op(y). | 589 /// Instructions of the form x := op(y). |
| 590 class InstX86Add; | |
| 590 template <typename InstX86Base::InstKindX86 K> | 591 template <typename InstX86Base::InstKindX86 K> |
| 591 class InstX86BaseUnaryopGPR : public InstX86Base { | 592 class InstX86BaseUnaryopGPR : public InstX86Base { |
| 592 InstX86BaseUnaryopGPR() = delete; | 593 InstX86BaseUnaryopGPR() = delete; |
| 593 InstX86BaseUnaryopGPR(const InstX86BaseUnaryopGPR &) = delete; | 594 InstX86BaseUnaryopGPR(const InstX86BaseUnaryopGPR &) = delete; |
| 594 InstX86BaseUnaryopGPR &operator=(const InstX86BaseUnaryopGPR &) = delete; | 595 InstX86BaseUnaryopGPR &operator=(const InstX86BaseUnaryopGPR &) = delete; |
| 595 | 596 |
| 596 public: | 597 public: |
| 597 using Base = InstX86BaseUnaryopGPR<K>; | 598 using Base = InstX86BaseUnaryopGPR<K>; |
| 598 | 599 |
| 599 void emit(const Cfg *Func) const override { | 600 void emit(const Cfg *Func) const override { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 613 this->getSrc(0)->emit(Func); | 614 this->getSrc(0)->emit(Func); |
| 614 Str << ", "; | 615 Str << ", "; |
| 615 this->getDest()->emit(Func); | 616 this->getDest()->emit(Func); |
| 616 } | 617 } |
| 617 void emitIAS(const Cfg *Func) const override { | 618 void emitIAS(const Cfg *Func) const override { |
| 618 assert(this->getSrcSize() == 1); | 619 assert(this->getSrcSize() == 1); |
| 619 const Variable *Var = this->getDest(); | 620 const Variable *Var = this->getDest(); |
| 620 Type Ty = Var->getType(); | 621 Type Ty = Var->getType(); |
| 621 const Operand *Src = this->getSrc(0); | 622 const Operand *Src = this->getSrc(0); |
| 622 constexpr bool IsLea = K == InstX86Base::Lea; | 623 constexpr bool IsLea = K == InstX86Base::Lea; |
| 624 | |
| 625 if (IsLea) { | |
| 626 if (auto *Add = deoptLeaToAddOrNull(Func)) { | |
| 627 Add->emitIAS(Func); | |
| 628 return; | |
| 629 } | |
| 630 } | |
| 623 emitIASRegOpTyGPR(Func, IsLea, Ty, Var, Src, Emitter); | 631 emitIASRegOpTyGPR(Func, IsLea, Ty, Var, Src, Emitter); |
| 624 } | 632 } |
| 625 void dump(const Cfg *Func) const override { | 633 void dump(const Cfg *Func) const override { |
| 626 if (!BuildDefs::dump()) | 634 if (!BuildDefs::dump()) |
| 627 return; | 635 return; |
| 628 Ostream &Str = Func->getContext()->getStrDump(); | 636 Ostream &Str = Func->getContext()->getStrDump(); |
| 629 this->dumpDest(Func); | 637 this->dumpDest(Func); |
| 630 Str << " = " << Opcode << "." << this->getSrc(0)->getType() << " "; | 638 Str << " = " << Opcode << "." << this->getSrc(0)->getType() << " "; |
| 631 this->dumpSources(Func); | 639 this->dumpSources(Func); |
| 632 } | 640 } |
| 641 | |
| 633 static bool classof(const Inst *Instr) { | 642 static bool classof(const Inst *Instr) { |
| 634 return InstX86Base::isClassof(Instr, InstX86Base::K); | 643 return InstX86Base::isClassof(Instr, InstX86Base::K); |
| 635 } | 644 } |
| 636 | 645 |
| 637 protected: | 646 protected: |
| 638 InstX86BaseUnaryopGPR(Cfg *Func, Variable *Dest, Operand *Src) | 647 InstX86BaseUnaryopGPR(Cfg *Func, Variable *Dest, Operand *Src) |
| 639 : InstX86Base(Func, K, 1, Dest) { | 648 : InstX86Base(Func, K, 1, Dest) { |
| 640 this->addSource(Src); | 649 this->addSource(Src); |
| 641 } | 650 } |
| 642 | 651 |
| 652 InstX86Add *deoptLeaToAddOrNull(const Cfg *Func) const { | |
|
Jim Stichnoth
2016/08/02 03:43:52
I think you could just declare this to return Inst
manasijm
2016/08/02 16:08:36
Done.
| |
| 653 // Revert back to Add when the Lea is a 2-address instruction. | |
| 654 // Caller has to emit, this just produces the add instruction. | |
| 655 auto *MemOp = llvm::dyn_cast<X86OperandMem>(this->getSrc(0)); | |
|
Jim Stichnoth
2016/08/02 03:43:52
if (auto *MemOp = llvm::dyn_cast<X86OperandMem>(th
manasijm
2016/08/02 16:08:36
Done.
| |
| 656 if (MemOp != nullptr && getFlags().getAggressiveLea() && | |
| 657 MemOp->getBase()->getRegNum() == this->getDest()->getRegNum() && | |
| 658 MemOp->getIndex() == nullptr && MemOp->getShift() == 0) { | |
| 659 auto *Add = InstImpl<TraitsType>::InstX86Add::create( | |
| 660 const_cast<Cfg *>(Func), this->getDest(), MemOp->getOffset()); | |
| 661 // TODO(manasijm): Remove const_cast by emitting code for add directly. | |
| 662 return Add; | |
| 663 } | |
| 664 return nullptr; | |
| 665 } | |
| 666 | |
| 643 static const char *Opcode; | 667 static const char *Opcode; |
| 644 static const GPREmitterRegOp Emitter; | 668 static const GPREmitterRegOp Emitter; |
| 645 }; | 669 }; |
| 646 | 670 |
| 647 template <typename InstX86Base::InstKindX86 K> | 671 template <typename InstX86Base::InstKindX86 K> |
| 648 class InstX86BaseUnaryopXmm : public InstX86Base { | 672 class InstX86BaseUnaryopXmm : public InstX86Base { |
| 649 InstX86BaseUnaryopXmm() = delete; | 673 InstX86BaseUnaryopXmm() = delete; |
| 650 InstX86BaseUnaryopXmm(const InstX86BaseUnaryopXmm &) = delete; | 674 InstX86BaseUnaryopXmm(const InstX86BaseUnaryopXmm &) = delete; |
| 651 InstX86BaseUnaryopXmm &operator=(const InstX86BaseUnaryopXmm &) = delete; | 675 InstX86BaseUnaryopXmm &operator=(const InstX86BaseUnaryopXmm &) = delete; |
| 652 | 676 |
| (...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3611 &InstImpl<TraitsType>::Assembler::punpckldq}; \ | 3635 &InstImpl<TraitsType>::Assembler::punpckldq}; \ |
| 3612 } \ | 3636 } \ |
| 3613 } | 3637 } |
| 3614 | 3638 |
| 3615 } // end of namespace X86NAMESPACE | 3639 } // end of namespace X86NAMESPACE |
| 3616 } // end of namespace Ice | 3640 } // end of namespace Ice |
| 3617 | 3641 |
| 3618 #include "IceInstX86BaseImpl.h" | 3642 #include "IceInstX86BaseImpl.h" |
| 3619 | 3643 |
| 3620 #endif // SUBZERO_SRC_ICEINSTX86BASE_H | 3644 #endif // SUBZERO_SRC_ICEINSTX86BASE_H |
| OLD | NEW |