[coco] Remove links for child-parent relation update (#1522)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Sep 2018 06:50:44 +0000 (15:50 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 17 Sep 2018 06:50:44 +0000 (15:50 +0900)
This commit eliminates all the use of PtrLink as a mean to update
child-parent relation between DLinkedList::Head and DLinkedList::Node.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
15 files changed:
contrib/coco/core/include/coco/ADT/DLinkedList.h
contrib/coco/core/include/coco/IR/Block.h
contrib/coco/core/include/coco/IR/BlockManager.h
contrib/coco/core/include/coco/IR/InstrManager.h
contrib/coco/core/include/coco/IR/Shuffle.h
contrib/coco/core/include/coco/IR/UnitF.h
contrib/coco/core/src/ADT/DLinkedList.test.cpp
contrib/coco/core/src/IR/Block.test.cpp
contrib/coco/core/src/IR/BlockManager.cpp
contrib/coco/core/src/IR/BlockManager.test.cpp
contrib/coco/core/src/IR/Instr.test.cpp
contrib/coco/core/src/IR/InstrManager.cpp
contrib/coco/core/src/IR/InstrManager.test.cpp
contrib/coco/core/src/IR/Module.cpp
contrib/coco/core/src/IR/Shuffle.test.cpp

index 3eee697..6890ab0 100644 (file)
@@ -15,8 +15,7 @@ template <typename Child, typename Parent> struct DLinkedList
   class Head
   {
   public:
-    // TODO _link is no longer used
-    Head(Parent *parent, PtrLink<Child, Parent> *link) : _parent{parent}
+    Head(Parent *parent) : _parent{parent}
     {
       _head = nullptr;
       _tail = nullptr;
index af1eed0..003615d 100644 (file)
@@ -21,9 +21,7 @@ using BlockList = DLinkedList<Block, Module>::Head;
 class Block final : public DLinkedList<Block, Module>::Node
 {
 public:
-  // TODO Update constructor
-  Block(const PtrLink<Block, Module> *, PtrLink<Instr, Block> *instr_link)
-      : _instr{this, instr_link}
+  Block() : _instr{this}
   {
     // DO NOTHING
   }
index 8ee311f..82e2dd6 100644 (file)
@@ -11,17 +11,6 @@ namespace coco
 class BlockManager final : public PtrManager<Block>
 {
 public:
-  BlockManager(const PtrLink<Block, Module> *block_link, PtrLink<Instr, Block> *instr_link)
-      : _block_link{block_link}, _instr_link{instr_link}
-  {
-    // DO NOTHING
-  }
-
-private:
-  const PtrLink<Block, Module> *const _block_link;
-  PtrLink<Instr, Block> *const _instr_link;
-
-public:
   Block *create(void);
 
 public:
index 902fbcf..133e4c4 100644 (file)
@@ -22,9 +22,8 @@ namespace coco
 class InstrManager final : public PtrManager<Instr>
 {
 public:
-  InstrManager(PtrLink<Op, Instr> *op_link, const PtrLink<Instr, Block> *instr_link,
-               const PtrLink<Object, ObjectInfo> *obj_link)
-      : _op_link{op_link}, _instr_link{instr_link}, _obj_link{obj_link}
+  InstrManager(PtrLink<Op, Instr> *op_link, const PtrLink<Object, ObjectInfo> *obj_link)
+      : _op_link{op_link}, _obj_link{obj_link}
   {
     // DO NOTHING
   }
@@ -42,7 +41,6 @@ public:
 
 private:
   PtrLink<Op, Instr> *const _op_link;
-  const PtrLink<Instr, Block> *const _instr_link;
   const PtrLink<Object, ObjectInfo> *const _obj_link;
 };
 
index fe5eeb4..cc22b9f 100644 (file)
@@ -18,8 +18,7 @@ namespace coco
 class Shuffle final : public Instr, public Bag::Reader, public Bag::Updater
 {
 public:
-  // TODO Update constructor interface
-  Shuffle(const PtrLink<Instr, Block> *) : _from{this}, _into{this}
+  Shuffle() : _from{this}, _into{this}
   {
     // DO NOTHING
   }
index 011416d..e2a0c38 100644 (file)
@@ -17,8 +17,7 @@ class UnitF final : public FeatureInstr
 {
 public:
   // TODO Update constructor
-  UnitF(PtrLink<Op, Instr> *op_link, const PtrLink<Instr, Block> *,
-        const PtrLink<Object, ObjectInfo> *obj_link)
+  UnitF(PtrLink<Op, Instr> *op_link, const PtrLink<Object, ObjectInfo> *obj_link)
       : FeatureInstr{obj_link}, _op_link{op_link}
   {
     _step.instr(this);
index c97ca69..56f7264 100644 (file)
@@ -13,7 +13,7 @@ using ChildList = coco::DLinkedList<Child, Parent>::Head;
 class Parent
 {
 public:
-  Parent(coco::PtrLink<Child, Parent> *link) : _list{this, link}
+  Parent() : _list{this}
   {
     // DO NOTHING
   }
@@ -27,12 +27,7 @@ private:
 
 class Child final : public coco::DLinkedList<Child, Parent>::Node
 {
-public:
-  // TODO Update constructor
-  Child(const coco::PtrLink<Child, Parent> *)
-  {
-    // DO NOTHING
-  }
+  // DO NOTHING
 };
 
 } // namespace
@@ -46,13 +41,12 @@ template <> ChildList *DLinkedList<Child, Parent>::head(Parent *p) { return p->c
 
 TEST(ADT_DLINKED_LINK, insert_two_elements)
 {
-  auto link = new coco::PtrLink<::Child, ::Parent>{};
-  auto parent = new ::Parent{link};
+  auto parent = new ::Parent;
 
   ASSERT_EQ(parent->children()->head(), nullptr);
   ASSERT_EQ(parent->children()->tail(), nullptr);
 
-  auto child_1 = new ::Child{link};
+  auto child_1 = new ::Child;
 
   ASSERT_EQ(child_1->parent(), nullptr);
   ASSERT_EQ(child_1->prev(), nullptr);
@@ -67,7 +61,7 @@ TEST(ADT_DLINKED_LINK, insert_two_elements)
   ASSERT_EQ(parent->children()->head(), child_1);
   ASSERT_EQ(parent->children()->tail(), child_1);
 
-  auto child_2 = new ::Child{link};
+  auto child_2 = new ::Child;
 
   ASSERT_EQ(child_2->parent(), nullptr);
   ASSERT_EQ(child_2->prev(), nullptr);
@@ -89,16 +83,14 @@ TEST(ADT_DLINKED_LINK, insert_two_elements)
   delete child_2;
   delete child_1;
   delete parent;
-  delete link;
 }
 
 TEST(ADT_DLINKED_LINK, insertBefore)
 {
-  auto link = new coco::PtrLink<::Child, ::Parent>{};
-  auto parent = new ::Parent{link};
+  auto parent = new ::Parent;
 
-  auto child_1 = new ::Child{link};
-  auto child_2 = new ::Child{link};
+  auto child_1 = new ::Child;
+  auto child_2 = new ::Child;
 
   parent->children()->append(child_1);
   child_2->insertBefore(child_1);
@@ -117,16 +109,14 @@ TEST(ADT_DLINKED_LINK, insertBefore)
   delete child_2;
   delete child_1;
   delete parent;
-  delete link;
 }
 
 TEST(ADT_DLINKED_LINK, prepend_after_append)
 {
-  auto link = new coco::PtrLink<::Child, ::Parent>{};
-  auto parent = new ::Parent{link};
+  auto parent = new ::Parent;
 
-  auto child_1 = new ::Child{link};
-  auto child_2 = new ::Child{link};
+  auto child_1 = new ::Child;
+  auto child_2 = new ::Child;
 
   parent->children()->append(child_1);
   parent->children()->prepend(child_2);
@@ -143,16 +133,14 @@ TEST(ADT_DLINKED_LINK, prepend_after_append)
   delete child_2;
   delete child_1;
   delete parent;
-  delete link;
 }
 
 TEST(ADT_DLINKED_LINK, detach)
 {
-  auto link = new coco::PtrLink<::Child, ::Parent>{};
-  auto parent = new ::Parent{link};
+  auto parent = new ::Parent;
 
-  auto child_1 = new ::Child{link};
-  auto child_2 = new ::Child{link};
+  auto child_1 = new ::Child;
+  auto child_2 = new ::Child;
 
   parent->children()->append(child_1);
   parent->children()->append(child_2);
@@ -182,16 +170,14 @@ TEST(ADT_DLINKED_LINK, detach)
   delete child_2;
   delete child_1;
   delete parent;
-  delete link;
 }
 
 TEST(ADT_DLINKED_LINK, node_destructor)
 {
-  auto link = new coco::PtrLink<::Child, ::Parent>{};
-  auto parent = new ::Parent{link};
+  auto parent = new ::Parent;
 
-  auto child_1 = new ::Child{link};
-  auto child_2 = new ::Child{link};
+  auto child_1 = new ::Child;
+  auto child_2 = new ::Child;
 
   parent->children()->append(child_1);
   parent->children()->append(child_2);
@@ -209,5 +195,4 @@ TEST(ADT_DLINKED_LINK, node_destructor)
   ASSERT_EQ(parent->children()->tail(), nullptr);
 
   delete parent;
-  delete link;
 }
index 3a4c689..a3c3ab7 100644 (file)
@@ -4,9 +4,7 @@
 
 TEST(IR_BLOCK, default_block_has_empty_instr_list)
 {
-  coco::PtrLink<coco::Block, coco::Module> block_link;
-  coco::PtrLink<coco::Instr, coco::Block> instr_link;
-  coco::Block blk{&block_link, &instr_link};
+  coco::Block blk;
 
   ASSERT_TRUE(blk.instr()->empty());
   ASSERT_EQ(blk.instr()->head(), nullptr);
index 38ca33f..4118bd5 100644 (file)
@@ -7,10 +7,7 @@
 namespace coco
 {
 
-Block *BlockManager::create(void)
-{
-  return take(nncc::foundation::make_unique<Block>(_block_link, _instr_link));
-}
+Block *BlockManager::create(void) { return take(nncc::foundation::make_unique<Block>()); }
 
 void BlockManager::destroy(Block *blk)
 {
index 90751a9..f283281 100644 (file)
@@ -13,16 +13,12 @@ public:
   // Create a coco::BlockManager for testing
   coco::BlockManager *allocate(void)
   {
-    auto p = new coco::BlockManager{&_block_link, &_instr_link};
+    auto p = new coco::BlockManager;
     _allocated.emplace_back(p);
     return p;
   }
 
 private:
-  coco::PtrLink<coco::Block, coco::Module> _block_link;
-  coco::PtrLink<coco::Instr, coco::Block> _instr_link;
-
-private:
   std::vector<std::unique_ptr<coco::BlockManager>> _allocated;
 };
 } // namespace
index 9528bd7..296c6ce 100644 (file)
@@ -15,8 +15,6 @@ protected:
   coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
 
   coco::PtrLink<coco::Op, coco::Instr> op_link;
-  // TODO Rename link as instr_link
-  coco::PtrLink<coco::Instr, coco::Block> link;
 
   coco::ObjectManager obj_mgr{&obj_link};
   coco::OpManager op_mgr{&op_link, &obj_link};
@@ -109,7 +107,7 @@ public:
 protected:
   coco::UnitF *allocate(void)
   {
-    auto ins = new coco::UnitF{&op_link, &link, &obj_link};
+    auto ins = new coco::UnitF{&op_link, &obj_link};
     _allocated.emplace_back(ins);
     return ins;
   }
index cf3a8a9..c8fd868 100644 (file)
@@ -11,12 +11,12 @@ namespace coco
 
 template <> UnitF *InstrManager::create(void)
 {
-  return take(nncc::foundation::make_unique<UnitF>(_op_link, _instr_link, _obj_link));
+  return take(nncc::foundation::make_unique<UnitF>(_op_link, _obj_link));
 }
 
 template <> Shuffle *InstrManager::create(void)
 {
-  return take(nncc::foundation::make_unique<Shuffle>(_instr_link));
+  return take(nncc::foundation::make_unique<Shuffle>());
 }
 
 void InstrManager::destroy(Instr *ins)
index 61183d7..25aa636 100644 (file)
@@ -12,18 +12,16 @@ public:
 
 protected:
   coco::PtrLink<coco::Op, coco::Instr> op_link;
-  coco::PtrLink<coco::Instr, coco::Block> ins_link;
   coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
-  coco::InstrManager mgr{&op_link, &ins_link, &obj_link};
+  coco::InstrManager mgr{&op_link, &obj_link};
 };
 } // namespace
 
 TEST(IR_INSTR_MANAGER, create_UnitF)
 {
   coco::PtrLink<coco::Op, coco::Instr> op_link;
-  coco::PtrLink<coco::Instr, coco::Block> link;
   coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
-  coco::InstrManager mgr{&op_link, &link, &obj_link};
+  coco::InstrManager mgr{&op_link, &obj_link};
 
   // Conv2D
   {
index 2a10a58..1fdeadc 100644 (file)
@@ -69,8 +69,6 @@ class ModuleImpl final : public coco::Module
 public:
   std::unique_ptr<coco::PtrLink<coco::Object, coco::ObjectInfo>> _obj_link;
   std::unique_ptr<coco::PtrLink<coco::Op, coco::Instr>> _op_link;
-  std::unique_ptr<coco::PtrLink<coco::Instr, coco::Block>> _instr_link;
-  std::unique_ptr<coco::PtrLink<coco::Block, coco::Module>> _block_link;
 
 public:
   coco::EntityManager *entity(void) override { return _entity.get(); }
@@ -114,8 +112,6 @@ std::unique_ptr<Module> Module::create(void)
 {
   auto obj_link = make_unique<coco::PtrLink<Object, ObjectInfo>>();
   auto op_link = make_unique<coco::PtrLink<Op, Instr>>();
-  auto ins_link = make_unique<coco::PtrLink<Instr, Block>>();
-  auto blk_link = make_unique<coco::PtrLink<Block, Module>>();
 
   auto m = make_unique<::ModuleImpl>();
 
@@ -124,22 +120,19 @@ std::unique_ptr<Module> Module::create(void)
     mgr->_bag = make_unique<coco::BagManager>();
     mgr->_object = make_unique<coco::ObjectManager>(obj_link.get());
     mgr->_op = make_unique<coco::OpManager>(op_link.get(), obj_link.get());
-    mgr->_instr = make_unique<coco::InstrManager>(op_link.get(), ins_link.get(), obj_link.get());
-    mgr->_block = make_unique<coco::BlockManager>(blk_link.get(), ins_link.get());
+    mgr->_instr = make_unique<coco::InstrManager>(op_link.get(), obj_link.get());
+    mgr->_block = make_unique<coco::BlockManager>();
     mgr->_input = make_unique<coco::InputManager>();
     mgr->_output = make_unique<coco::OutputManager>();
   }
   m->_entity = std::move(mgr);
 
-  // NOTE BlockManager and BlockList SHOULD share 'blk_link'
-  m->_block = make_unique<coco::BlockList>(m.get(), blk_link.get());
+  m->_block = make_unique<coco::BlockList>(m.get());
   m->_input = make_unique<coco::InputList>();
   m->_output = make_unique<coco::OutputList>();
 
   m->_obj_link = std::move(obj_link);
   m->_op_link = std::move(op_link);
-  m->_instr_link = std::move(ins_link);
-  m->_block_link = std::move(blk_link);
 
   return std::move(m);
 }
index 3145e26..813fe18 100644 (file)
@@ -14,14 +14,13 @@ public:
 protected:
   coco::Shuffle *allocate(void)
   {
-    auto ins = new coco::Shuffle{&instr_link};
+    auto ins = new coco::Shuffle;
     _allocated.emplace_back(ins);
     return ins;
   }
 
 protected:
   coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-  coco::PtrLink<coco::Instr, coco::Block> instr_link;
 
 private:
   std::vector<std::unique_ptr<coco::Instr>> _allocated;