Subzero: Make InstX8632Cbwdq a UnaryOp.
After the changes in CL 443203003, InstX8632Cbwdq fits the template for
a UnaryOp, so change it to be in instance of this class.
BUG=none
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/452143003
diff --git a/src/IceInstX8632.cpp b/src/IceInstX8632.cpp
index 457f56e..03cdb95 100644
--- a/src/IceInstX8632.cpp
+++ b/src/IceInstX8632.cpp
@@ -136,11 +136,6 @@
addSource(CallTarget);
}
-InstX8632Cbwdq::InstX8632Cbwdq(Cfg *Func, Variable *Dest, Operand *Source)
- : InstX8632(Func, InstX8632::Cbwdq, 1, Dest) {
- addSource(Source);
-}
-
InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source,
InstX8632::BrCond Condition)
: InstX8632(Func, InstX8632::Cmov, 2, Dest), Condition(Condition) {
@@ -452,6 +447,7 @@
template <> const char *InstX8632Lea::Opcode = "lea";
template <> const char *InstX8632Movd::Opcode = "movd";
template <> const char *InstX8632Sqrtss::Opcode = "sqrtss";
+template <> const char *InstX8632Cbwdq::Opcode = "cbw/cwd/cdq";
// Binary ops
template <> const char *InstX8632Add::Opcode = "add";
template <> const char *InstX8632Addps::Opcode = "addps";
@@ -647,6 +643,31 @@
}
}
+template <> void InstX8632Cbwdq::emit(const Cfg *Func) const {
+ Ostream &Str = Func->getContext()->getStrEmit();
+ assert(getSrcSize() == 1);
+ Operand *Src0 = getSrc(0);
+ assert(llvm::isa<Variable>(Src0));
+ assert(llvm::cast<Variable>(Src0)->getRegNum() == TargetX8632::Reg_eax);
+ switch (Src0->getType()) {
+ default:
+ llvm_unreachable("unexpected source type!");
+ break;
+ case IceType_i8:
+ assert(getDest()->getRegNum() == TargetX8632::Reg_eax);
+ Str << "\tcbw\n";
+ break;
+ case IceType_i16:
+ assert(getDest()->getRegNum() == TargetX8632::Reg_edx);
+ Str << "\tcwd\n";
+ break;
+ case IceType_i32:
+ assert(getDest()->getRegNum() == TargetX8632::Reg_edx);
+ Str << "\tcdq\n";
+ break;
+ }
+}
+
void InstX8632Mul::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit();
assert(getSrcSize() == 2);
@@ -718,38 +739,6 @@
dumpSources(Func);
}
-void InstX8632Cbwdq::emit(const Cfg *Func) const {
- Ostream &Str = Func->getContext()->getStrEmit();
- assert(getSrcSize() == 1);
- Operand *Src0 = getSrc(0);
- assert(llvm::isa<Variable>(Src0));
- assert(llvm::cast<Variable>(Src0)->getRegNum() == TargetX8632::Reg_eax);
- switch (Src0->getType()) {
- default:
- llvm_unreachable("unexpected source type!");
- break;
- case IceType_i8:
- assert(getDest()->getRegNum() == TargetX8632::Reg_eax);
- Str << "\tcbw\n";
- break;
- case IceType_i16:
- assert(getDest()->getRegNum() == TargetX8632::Reg_edx);
- Str << "\tcwd\n";
- break;
- case IceType_i32:
- assert(getDest()->getRegNum() == TargetX8632::Reg_edx);
- Str << "\tcdq\n";
- break;
- }
-}
-
-void InstX8632Cbwdq::dump(const Cfg *Func) const {
- Ostream &Str = Func->getContext()->getStrDump();
- dumpDest(Func);
- Str << " = cbw/cwd/cdq." << getSrc(0)->getType() << " ";
- dumpSources(Func);
-}
-
void InstX8632Cmov::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit();
Str << "\t";
diff --git a/src/IceInstX8632.h b/src/IceInstX8632.h
index 1aa7909..bc9ac53 100644
--- a/src/IceInstX8632.h
+++ b/src/IceInstX8632.h
@@ -556,6 +556,8 @@
typedef InstX8632Unaryop<InstX8632::Lea> InstX8632Lea;
typedef InstX8632Unaryop<InstX8632::Movd> InstX8632Movd;
typedef InstX8632Unaryop<InstX8632::Sqrtss> InstX8632Sqrtss;
+// Cbwdq instruction - wrapper for cbw, cwd, and cdq
+typedef InstX8632Unaryop<InstX8632::Cbwdq> InstX8632Cbwdq;
typedef InstX8632Binop<InstX8632::Add> InstX8632Add;
typedef InstX8632Binop<InstX8632::Addps> InstX8632Addps;
typedef InstX8632Binop<InstX8632::Adc> InstX8632Adc;
@@ -689,24 +691,6 @@
virtual ~InstX8632Shrd() {}
};
-// Cbdwq instruction - wrapper for cbw, cwd, or cdq
-class InstX8632Cbwdq : public InstX8632 {
-public:
- static InstX8632Cbwdq *create(Cfg *Func, Variable *Dest, Operand *Source) {
- return new (Func->allocate<InstX8632Cbwdq>())
- InstX8632Cbwdq(Func, Dest, Source);
- }
- virtual void emit(const Cfg *Func) const;
- virtual void dump(const Cfg *Func) const;
- static bool classof(const Inst *Inst) { return isClassof(Inst, Cbwdq); }
-
-private:
- InstX8632Cbwdq(Cfg *Func, Variable *Dest, Operand *Source);
- InstX8632Cbwdq(const InstX8632Cbwdq &) LLVM_DELETED_FUNCTION;
- InstX8632Cbwdq &operator=(const InstX8632Cbwdq &) LLVM_DELETED_FUNCTION;
- virtual ~InstX8632Cbwdq() {}
-};
-
// Conditional move instruction.
class InstX8632Cmov : public InstX8632 {
public:
@@ -1195,6 +1179,7 @@
// possibility of ODR violations and link errors.
template <> void InstX8632Addss::emit(const Cfg *Func) const;
template <> void InstX8632Blendvps::emit(const Cfg *Func) const;
+template <> void InstX8632Cbwdq::emit(const Cfg *Func) const;
template <> void InstX8632Div::emit(const Cfg *Func) const;
template <> void InstX8632Divss::emit(const Cfg *Func) const;
template <> void InstX8632Idiv::emit(const Cfg *Func) const;