Chromium Code Reviews| Index: src/IceInstX86Base.h |
| diff --git a/src/IceInstX86Base.h b/src/IceInstX86Base.h |
| index 655b38d36831fe47acf75e14ca419eedc11f6e9b..0beb0ad3fb73e43598361d503cbabe945aad369f 100644 |
| --- a/src/IceInstX86Base.h |
| +++ b/src/IceInstX86Base.h |
| @@ -587,6 +587,7 @@ template <typename TraitsType> struct InstImpl { |
| }; |
| /// Instructions of the form x := op(y). |
| + class InstX86Add; |
| template <typename InstX86Base::InstKindX86 K> |
| class InstX86BaseUnaryopGPR : public InstX86Base { |
| InstX86BaseUnaryopGPR() = delete; |
| @@ -620,6 +621,13 @@ template <typename TraitsType> struct InstImpl { |
| Type Ty = Var->getType(); |
| const Operand *Src = this->getSrc(0); |
| constexpr bool IsLea = K == InstX86Base::Lea; |
| + |
| + if (IsLea) { |
| + if (auto *Add = deoptLeaToAddOrNull(Func)) { |
| + Add->emitIAS(Func); |
| + return; |
| + } |
| + } |
| emitIASRegOpTyGPR(Func, IsLea, Ty, Var, Src, Emitter); |
| } |
| void dump(const Cfg *Func) const override { |
| @@ -630,6 +638,7 @@ template <typename TraitsType> struct InstImpl { |
| Str << " = " << Opcode << "." << this->getSrc(0)->getType() << " "; |
| this->dumpSources(Func); |
| } |
| + |
| static bool classof(const Inst *Instr) { |
| return InstX86Base::isClassof(Instr, InstX86Base::K); |
| } |
| @@ -640,6 +649,21 @@ template <typename TraitsType> struct InstImpl { |
| this->addSource(Src); |
| } |
| + 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.
|
| + // Revert back to Add when the Lea is a 2-address instruction. |
| + // Caller has to emit, this just produces the add instruction. |
| + 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.
|
| + if (MemOp != nullptr && getFlags().getAggressiveLea() && |
| + MemOp->getBase()->getRegNum() == this->getDest()->getRegNum() && |
| + MemOp->getIndex() == nullptr && MemOp->getShift() == 0) { |
| + auto *Add = InstImpl<TraitsType>::InstX86Add::create( |
| + const_cast<Cfg *>(Func), this->getDest(), MemOp->getOffset()); |
| + // TODO(manasijm): Remove const_cast by emitting code for add directly. |
| + return Add; |
| + } |
| + return nullptr; |
| + } |
| + |
| static const char *Opcode; |
| static const GPREmitterRegOp Emitter; |
| }; |