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
return take(std::move(kernel));
}
+void ObjectManager::destroy(Object *o)
+{
+ assert(o->def() == nullptr);
+ assert(o->uses()->size() == 0);
+ release(o);
+}
+
} // namespace coco
*/
#include "coco/IR/ObjectManager.h"
+#include "coco/IR/BagManager.h"
#include "coco/IR/FeatureObject.h"
#include "coco/IR/KernelObject.h"
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);
+}