#define __COCO_IR_OP_H__
#include "coco/IR/Object.forward.h"
+#include "coco/IR/Instr.forward.h"
+
+#include "coco/ADT/PtrLink.h"
#include <set>
template <typename T> T accept(Visitor<T> &v) const { return accept(&v); }
template <typename T> T accept(Visitor<T> &&v) const { return accept(&v); }
+
+protected:
+ virtual void get(const PtrLink<Op, Instr> **) const = 0;
+
+public:
+ Instr *parent(void) const;
};
} // namespace coco
};
public:
- explicit Conv2D(const Param &);
+ explicit Conv2D(const PtrLink<Op, Instr> *, const Param &);
public:
std::set<Object *> uses(void) const override;
public:
KernelObject *ker(void) const { return _ker; }
void ker(KernelObject *ker);
+
+private:
+ const PtrLink<Op, Instr> *const _op_link;
+
+private:
+ void get(const PtrLink<Op, Instr> **out) const override { *out = _op_link; }
};
} // namespace coco
#include "coco/IR/Op.h"
//
+// Op
+//
+#include <cassert>
+
+namespace coco
+{
+Instr *Op::parent(void) const
+{
+ const PtrLink<Op, Instr> *op_link = nullptr;
+ get(&op_link);
+ assert(op_link != nullptr);
+
+ return op_link->find(this);
+}
+} // namespace coco
+//
// Conv2D
//
namespace coco
{
-Conv2D::Conv2D(const Param &) : _ker{nullptr}
+Conv2D::Conv2D(const PtrLink<Op, Instr> *op_link, const Param &) : _op_link{op_link}, _ker{nullptr}
{
// NOTE Currently, Param class is just a placeholder
}
TEST(IR_OP_CONV2D, ctor)
{
+ const coco::PtrLink<coco::Op, coco::Instr> op_link;
const coco::Conv2D::Param param{};
- const coco::Conv2D op{param};
+ const coco::Conv2D op{&op_link, param};
// ker() should be initialized as nullptr on construction
ASSERT_EQ(op.ker(), nullptr);
// uses() should be empty on construction
ASSERT_EQ(op.uses().size(), 0);
+ // parent() should be nullptr on construction
+ ASSERT_EQ(op.parent(), nullptr);
}
TEST(IR_OP_CONV2D, asConv2D)
{
- coco::Conv2D op{coco::Conv2D::Param{}};
+ const coco::PtrLink<coco::Op, coco::Instr> op_link;
+ coco::Conv2D op{&op_link, coco::Conv2D::Param{}};
coco::Op *mutable_base = &op;
const coco::Op *immutable_base = &op;
auto obj = obj_mgr.create(nncc::core::ADT::kernel::Shape{1, 1, 3, 3});
// Test 'Conv2D' class
+ const coco::PtrLink<coco::Op, coco::Instr> op_link;
const coco::Conv2D::Param param{};
- coco::Conv2D op{param};
+ coco::Conv2D op{&op_link, param};
op.ker(obj);
ASSERT_EQ(op.ker(), obj);
TEST(IR_OP_CONV2D, accept)
{
// Test 'Conv2D' class
+ const coco::PtrLink<coco::Op, coco::Instr> op_link;
const coco::Conv2D::Param param{};
- coco::Conv2D op{param};
+ coco::Conv2D op{&op_link, param};
coco::Conv2D *mutable_ptr = &op;
const coco::Conv2D *immutable_ptr = &op;