Part _arg;
};
+/**
+ * @brief Op with two arguments
+ */
+class BinaryOp : public Op
+{
+public:
+ explicit BinaryOp();
+
+public:
+ BinaryOp(const BinaryOp &) = delete;
+ BinaryOp(BinaryOp &&) = delete;
+
+public:
+ virtual ~BinaryOp() = default;
+
+public:
+ std::set<Object *> uses(void) const final;
+
+public:
+ Op *left(void) const { return _left.child(); }
+ void left(Op *op) { _left.child(op); }
+
+public:
+ Op *right(void) const { return _right.child(); }
+ void right(Op *op) { _right.child(op); }
+
+private:
+ // @brief Left-hand side (LHS) argument
+ Part _left;
+ // @brief Right-hand side (RHS) argument
+ Part _right;
+};
+
} // namespace coco
#endif // __COCO_IR_OP_H__
*
* Add(L, R) is valid only when L and R have identical kind/shape/dtype
*/
-class Add final : public Op
+class Add final : public BinaryOp
{
public:
- explicit Add();
+ explicit Add() = default;
public:
Add(const Add &) = delete;
Add(Add &&) = delete;
public:
- std::set<Object *> uses(void) const override;
-
-public:
Add *asAdd(void) override { return this; }
const Add *asAdd(void) const override { return this; }
-
-public:
- Op *left(void) const { return _left.child(); }
- void left(Op *op) { _left.child(op); }
-
-public:
- Op *right(void) const { return _right.child(); }
- void right(Op *op) { _right.child(op); }
-
-private:
- // @brief Left-hand side (LHS) argument
- Part _left;
- // @brief Right-hand side (RHS) argument
- Part _right;
};
} // namesapce coco
return res;
}
+//
+// BinaryOp trait
+//
+BinaryOp::BinaryOp() : _left{this}, _right{this}
+{
+ // DO NOTHING
+}
+
+std::set<Object *> BinaryOp::uses(void) const
+{
+ std::set<Object *> res;
+
+ if (auto l = left())
+ {
+ for (auto obj : l->uses())
+ {
+ res.insert(obj);
+ }
+ }
+
+ if (auto r = right())
+ {
+ for (auto obj : r->uses())
+ {
+ res.insert(obj);
+ }
+ }
+
+ return res;
+}
+
} // namespace coco
namespace coco
{
-/**
- * Operator: Add
- */
-Add::Add() : _left{this}, _right{this}
-{
- // DO NOTHING
-}
-
-std::set<Object *> Add::uses(void) const
-{
- std::set<Object *> res;
-
- if (auto l = left())
- {
- for (auto obj : l->uses())
- {
- res.insert(obj);
- }
- }
-
- if (auto r = right())
- {
- for (auto obj : r->uses())
- {
- res.insert(obj);
- }
- }
-
- return res;
-}
-
} // namespace coco