From 2c149ea1d1399ec67cfa75c193b9579f9a3861ba 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: Mon, 1 Oct 2018 11:21:11 +0900 Subject: [PATCH] [coco] Support Object destruction (#1685) * [coco] Support Object destruction This commit introduces 'destroy' method in ObjectManager, which allows users to destruct Object(s) allocated via ObjectManager. Signed-off-by: Jonghyun Park * Fix typos --- contrib/coco/core/include/coco/IR/ObjectManager.h | 9 +++++++++ contrib/coco/core/src/IR/ObjectManager.cpp | 7 +++++++ contrib/coco/core/src/IR/ObjectManager.test.cpp | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/ObjectManager.h b/contrib/coco/core/include/coco/IR/ObjectManager.h index 3cf8912..585ca03 100644 --- a/contrib/coco/core/include/coco/IR/ObjectManager.h +++ b/contrib/coco/core/include/coco/IR/ObjectManager.h @@ -41,6 +41,15 @@ public: KernelObject *create(const nncc::core::ADT::kernel::Shape &shape); template T *create(void); + +public: + /** + * @brief Destroy (= deallocate) an Object entity + * + * NOTE An Object SHOULD HAVE NO DEF & USES to be destructed + * NOTE An Object WILL BE unlinked from its dependent bag (if has) on destruction + */ + void destroy(Object *o); }; } // namespace coco diff --git a/contrib/coco/core/src/IR/ObjectManager.cpp b/contrib/coco/core/src/IR/ObjectManager.cpp index f829475..fdb223f 100644 --- a/contrib/coco/core/src/IR/ObjectManager.cpp +++ b/contrib/coco/core/src/IR/ObjectManager.cpp @@ -53,4 +53,11 @@ KernelObject *ObjectManager::create(const nncc::core::ADT::kernel::Shape &shape) return take(std::move(kernel)); } +void ObjectManager::destroy(Object *o) +{ + assert(o->def() == nullptr); + assert(o->uses()->size() == 0); + release(o); +} + } // namespace coco diff --git a/contrib/coco/core/src/IR/ObjectManager.test.cpp b/contrib/coco/core/src/IR/ObjectManager.test.cpp index 206807c..4e80a6d 100644 --- a/contrib/coco/core/src/IR/ObjectManager.test.cpp +++ b/contrib/coco/core/src/IR/ObjectManager.test.cpp @@ -15,6 +15,7 @@ */ #include "coco/IR/ObjectManager.h" +#include "coco/IR/BagManager.h" #include "coco/IR/FeatureObject.h" #include "coco/IR/KernelObject.h" @@ -58,3 +59,19 @@ TEST(IR_OBJECT_MANAGER, create_feature_with_template) ASSERT_EQ(feature->layout(), nullptr); } + +TEST(IR_OBJECT_MANAGER, destroy) +{ + coco::BagManager bag_mgr; + coco::ObjectManager obj_mgr; + + auto bag = bag_mgr.create(3); + auto feature = obj_mgr.create(); + + feature->bag(bag); + + obj_mgr.destroy(feature); + + // Object SHOULD BE unlinked from its dependent bag on destruction + ASSERT_EQ(bag->deps()->size(), 0); +} -- 2.7.4