From 9e396895850bf34a2cf0d60b099158ffe7d19621 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 25 Jul 2018 15:54:54 +0900 Subject: [PATCH] [coco] Store a mapping from Bag to BagInfo (#796) This commit revises BagManager to update the mapping from Bag to BagInfo for future use. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/BagManager.h | 13 ++++++++++++- contrib/coco/core/src/IR/BagManager.cpp | 10 +++++++++- contrib/coco/core/src/IR/BagManager.test.cpp | 10 +++++++++- contrib/coco/core/src/IR/Module.cpp | 5 ++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/BagManager.h b/contrib/coco/core/include/coco/IR/BagManager.h index b3cddeb..f08bf55 100644 --- a/contrib/coco/core/include/coco/IR/BagManager.h +++ b/contrib/coco/core/include/coco/IR/BagManager.h @@ -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 +class BagManager : public PtrManager { +public: + BagManager(PtrLink *link) : _link{link} + { + // DO NOTHING + } + +public: Bag *create(uint32_t size); + +private: + PtrLink * const _link; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/BagManager.cpp b/contrib/coco/core/src/IR/BagManager.cpp index 96177a5..1fddf3a 100644 --- a/contrib/coco/core/src/IR/BagManager.cpp +++ b/contrib/coco/core/src/IR/BagManager.cpp @@ -7,7 +7,15 @@ namespace coco Bag *BagManager::create(uint32_t size) { - return take(nncc::foundation::make_unique(size)); + auto info = nncc::foundation::make_unique(size); + auto info_ptr = info.get(); + + auto bag = nncc::foundation::make_unique(std::move(info)); + auto bag_ptr = bag.get(); + + _link->set(bag_ptr, info_ptr); + + return take(std::move(bag)); } } // namespace coco diff --git a/contrib/coco/core/src/IR/BagManager.test.cpp b/contrib/coco/core/src/IR/BagManager.test.cpp index fb5cd73..d944ed7 100644 --- a/contrib/coco/core/src/IR/BagManager.test.cpp +++ b/contrib/coco/core/src/IR/BagManager.test.cpp @@ -4,9 +4,17 @@ TEST(IR_BAG_MANAGER, create) { - coco::BagManager mgr; + coco::PtrLink 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); } diff --git a/contrib/coco/core/src/IR/Module.cpp b/contrib/coco/core/src/IR/Module.cpp index 91f6a6a..c492eee 100644 --- a/contrib/coco/core/src/IR/Module.cpp +++ b/contrib/coco/core/src/IR/Module.cpp @@ -65,6 +65,7 @@ namespace class ModuleImpl final : public coco::Module { public: + std::unique_ptr> _bag_link; std::unique_ptr> _instr_link; std::unique_ptr> _block_link; @@ -104,6 +105,7 @@ namespace coco std::unique_ptr Module::create(void) { + auto bag_link = nncc::foundation::make_unique>(); auto ins_link = nncc::foundation::make_unique>(); auto blk_link = nncc::foundation::make_unique>(); @@ -111,7 +113,7 @@ std::unique_ptr Module::create(void) auto mgr = nncc::foundation::make_unique<::EntityManagerImpl>(); { - mgr->_bag = nncc::foundation::make_unique(); + mgr->_bag = nncc::foundation::make_unique(bag_link.get()); mgr->_object = nncc::foundation::make_unique(); mgr->_op = nncc::foundation::make_unique(); mgr->_instr = nncc::foundation::make_unique(ins_link.get()); @@ -126,6 +128,7 @@ std::unique_ptr Module::create(void) m->_input = nncc::foundation::make_unique(); m->_output = nncc::foundation::make_unique(); + m->_bag_link = std::move(bag_link); m->_instr_link = std::move(ins_link); m->_block_link = std::move(blk_link); -- 2.7.4