[coco] Support Object destruction (#1685)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 1 Oct 2018 02:21:11 +0000 (11:21 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 1 Oct 2018 02:21:11 +0000 (11:21 +0900)
* [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 <jh1302.park@samsung.com>
* Fix typos

contrib/coco/core/include/coco/IR/ObjectManager.h
contrib/coco/core/src/IR/ObjectManager.cpp
contrib/coco/core/src/IR/ObjectManager.test.cpp

index 3cf8912..585ca03 100644 (file)
@@ -41,6 +41,15 @@ public:
   KernelObject *create(const nncc::core::ADT::kernel::Shape &shape);
 
   template <typename T> 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
index f829475..fdb223f 100644 (file)
@@ -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
index 206807c..4e80a6d 100644 (file)
@@ -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<coco::FeatureObject>();
+
+  feature->bag(bag);
+
+  obj_mgr.destroy(feature);
+
+  // Object SHOULD BE unlinked from its dependent bag on destruction
+  ASSERT_EQ(bag->deps()->size(), 0);
+}