From 00206873319e564bf10bce3d2da47f54612d90f6 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: Tue, 11 Sep 2018 19:24:45 +0900 Subject: [PATCH] [coco] Support Instr destruction (#1455) This commit extends InstrManager with destroy method. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/InstrManager.h | 8 ++++++++ contrib/coco/core/src/IR/InstrManager.cpp | 10 ++++++++++ contrib/coco/core/src/IR/InstrManager.test.cpp | 1 + 3 files changed, 19 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/InstrManager.h b/contrib/coco/core/include/coco/IR/InstrManager.h index 80654fa..5dbe54d 100644 --- a/contrib/coco/core/include/coco/IR/InstrManager.h +++ b/contrib/coco/core/include/coco/IR/InstrManager.h @@ -32,6 +32,14 @@ public: public: template Ins *create(void); +public: + // @brief Destroy (= deallocate) an Instr instance + // + // NOTE InstrManager will invoke dispose before deallocation + // NOTE destroy(ins) WILL NOT update ins->parent(). An Instruction SHOULD BE detacted from a + // module before destroy call + void destroy(Instr *); + private: PtrLink *const _op_link; const PtrLink *const _instr_link; diff --git a/contrib/coco/core/src/IR/InstrManager.cpp b/contrib/coco/core/src/IR/InstrManager.cpp index 977e0e1..74480ed 100644 --- a/contrib/coco/core/src/IR/InstrManager.cpp +++ b/contrib/coco/core/src/IR/InstrManager.cpp @@ -4,6 +4,8 @@ #include +#include + namespace coco { @@ -17,4 +19,12 @@ template <> Shuffle *InstrManager::create(void) return take(nncc::foundation::make_unique(_instr_link, _bag_link)); } +void InstrManager::destroy(Instr *ins) +{ + // ins SHOULD BE detached from any block before destroy call + assert(ins->parent() == nullptr); + ins->dispose(); + release(ins); +} + } // namespace coco diff --git a/contrib/coco/core/src/IR/InstrManager.test.cpp b/contrib/coco/core/src/IR/InstrManager.test.cpp index 81c9eb9..5461386 100644 --- a/contrib/coco/core/src/IR/InstrManager.test.cpp +++ b/contrib/coco/core/src/IR/InstrManager.test.cpp @@ -38,4 +38,5 @@ TEST_F(InstrManagerTest, create_Shuffle) { auto ins = mgr.create(); ASSERT_NE(ins, nullptr); + mgr.destroy(ins); } -- 2.7.4