[coco] Store a mapping from Bag to BagInfo (#796)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 25 Jul 2018 06:54:54 +0000 (15:54 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 25 Jul 2018 06:54:54 +0000 (15:54 +0900)
This commit revises BagManager to update the mapping from Bag to BagInfo
for future use.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/BagManager.h
contrib/coco/core/src/IR/BagManager.cpp
contrib/coco/core/src/IR/BagManager.test.cpp
contrib/coco/core/src/IR/Module.cpp

index b3cddeb..f08bf55 100644 (file)
@@ -4,13 +4,24 @@
 #include "coco/IR/Bag.h"
 
 #include "coco/ADT/PtrManager.h"
+#include "coco/ADT/PtrLink.h"
 
 namespace coco
 {
 
-struct BagManager : public PtrManager<Bag>
+class BagManager : public PtrManager<Bag>
 {
+public:
+  BagManager(PtrLink<Bag, BagInfo> *link) : _link{link}
+  {
+    // DO NOTHING
+  }
+
+public:
   Bag *create(uint32_t size);
+
+private:
+  PtrLink<Bag, BagInfo> * const _link;
 };
 
 } // namespace coco
index 96177a5..1fddf3a 100644 (file)
@@ -7,7 +7,15 @@ namespace coco
 
 Bag *BagManager::create(uint32_t size)
 {
-  return take(nncc::foundation::make_unique<Bag>(size));
+  auto info = nncc::foundation::make_unique<BagInfo>(size);
+  auto info_ptr = info.get();
+
+  auto bag = nncc::foundation::make_unique<Bag>(std::move(info));
+  auto bag_ptr = bag.get();
+
+  _link->set(bag_ptr, info_ptr);
+
+  return take(std::move(bag));
 }
 
 } // namespace coco
index fb5cd73..d944ed7 100644 (file)
@@ -4,9 +4,17 @@
 
 TEST(IR_BAG_MANAGER, create)
 {
-  coco::BagManager mgr;
+  coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
+  coco::BagManager mgr{&bag_link};
 
   auto bag = mgr.create(3);
 
   ASSERT_EQ(bag->size(), 3);
+
+  // BagManager SHOULD update Bag->BagInfo link properly
+  ASSERT_NE(bag_link.find(bag), nullptr);
+
+  auto info = bag_link.find(bag);
+
+  ASSERT_EQ(info->size(), 3);
 }
index 91f6a6a..c492eee 100644 (file)
@@ -65,6 +65,7 @@ namespace
 class ModuleImpl final : public coco::Module
 {
 public:
+  std::unique_ptr<coco::PtrLink<coco::Bag, coco::BagInfo>> _bag_link;
   std::unique_ptr<coco::PtrLink<coco::Instr, coco::Block>> _instr_link;
   std::unique_ptr<coco::PtrLink<coco::Block, coco::Module>> _block_link;
 
@@ -104,6 +105,7 @@ namespace coco
 
 std::unique_ptr<Module> Module::create(void)
 {
+  auto bag_link = nncc::foundation::make_unique<coco::PtrLink<Bag, BagInfo>>();
   auto ins_link = nncc::foundation::make_unique<coco::PtrLink<Instr, Block>>();
   auto blk_link = nncc::foundation::make_unique<coco::PtrLink<Block, Module>>();
 
@@ -111,7 +113,7 @@ std::unique_ptr<Module> Module::create(void)
 
   auto mgr = nncc::foundation::make_unique<::EntityManagerImpl>();
   {
-    mgr->_bag = nncc::foundation::make_unique<coco::BagManager>();
+    mgr->_bag = nncc::foundation::make_unique<coco::BagManager>(bag_link.get());
     mgr->_object = nncc::foundation::make_unique<coco::ObjectManager>();
     mgr->_op = nncc::foundation::make_unique<coco::OpManager>();
     mgr->_instr = nncc::foundation::make_unique<coco::InstrManager>(ins_link.get());
@@ -126,6 +128,7 @@ std::unique_ptr<Module> Module::create(void)
   m->_input = nncc::foundation::make_unique<coco::InputList>();
   m->_output = nncc::foundation::make_unique<coco::OutputList>();
 
+  m->_bag_link = std::move(bag_link);
   m->_instr_link = std::move(ins_link);
   m->_block_link = std::move(blk_link);