From ada3fec627698868defb92f39af6fec5c503a6f0 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: Thu, 13 Sep 2018 11:20:52 +0900 Subject: [PATCH] [coco] Non-template UseSlot (#1482) This commit rewrites UseSlot as a non-template version. This is a step to support Object-to-Object substitution. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Conv2D.h | 4 ++-- contrib/coco/core/include/coco/IR/Instr.h | 4 ++-- contrib/coco/core/include/coco/IR/UseSlot.h | 8 ++++---- contrib/coco/core/src/IR/Conv2D.cpp | 13 +++++++++++++ contrib/coco/core/src/IR/Instr.cpp | 12 ++++++++++++ contrib/coco/core/src/IR/UseSlot.test.cpp | 4 ++-- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/Conv2D.h b/contrib/coco/core/include/coco/IR/Conv2D.h index 8cb4676..dd7ce5b 100644 --- a/contrib/coco/core/include/coco/IR/Conv2D.h +++ b/contrib/coco/core/include/coco/IR/Conv2D.h @@ -35,10 +35,10 @@ public: Instr *loc(void) override { return parent(); } private: - UseSlot _ker; + UseSlot _ker; public: - KernelObject *ker(void) const { return _ker.value(); } + KernelObject *ker(void) const; void ker(KernelObject *ker); public: diff --git a/contrib/coco/core/include/coco/IR/Instr.h b/contrib/coco/core/include/coco/IR/Instr.h index 46eeacb..f11aa30 100644 --- a/contrib/coco/core/include/coco/IR/Instr.h +++ b/contrib/coco/core/include/coco/IR/Instr.h @@ -165,10 +165,10 @@ public: virtual ~FeatureInstr() = default; private: - UseSlot _ifm; + UseSlot _ifm; public: - FeatureObject *ifm(void) const { return _ifm.value(); } + FeatureObject *ifm(void) const; void ifm(FeatureObject *ifm); private: diff --git a/contrib/coco/core/include/coco/IR/UseSlot.h b/contrib/coco/core/include/coco/IR/UseSlot.h index 9499551..578f772 100644 --- a/contrib/coco/core/include/coco/IR/UseSlot.h +++ b/contrib/coco/core/include/coco/IR/UseSlot.h @@ -8,7 +8,7 @@ namespace coco { -template class UseSlot final +class UseSlot final { public: UseSlot(const PtrLink *obj_link, Object::Consumer *use) @@ -18,10 +18,10 @@ public: } public: - T *value(void) const { return _value; } + Object *value(void) const { return _value; } public: - void value(T *value) + void value(Object *value) { if (_value) { @@ -42,7 +42,7 @@ public: private: UseHook _hook; - T *_value; + Object *_value; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/Conv2D.cpp b/contrib/coco/core/src/IR/Conv2D.cpp index 3f3972b..29570a8 100644 --- a/contrib/coco/core/src/IR/Conv2D.cpp +++ b/contrib/coco/core/src/IR/Conv2D.cpp @@ -1,5 +1,7 @@ #include "coco/IR/Conv2D.h" +#include + namespace coco { @@ -29,4 +31,15 @@ std::set Conv2D::uses(void) const void Conv2D::ker(KernelObject *ker) { _ker.value(ker); } +KernelObject *Conv2D::ker(void) const +{ + if (auto obj = _ker.value()) + { + assert(obj->asKernel() != nullptr); + return obj->asKernel(); + } + + return nullptr; +} + } // namespace coco diff --git a/contrib/coco/core/src/IR/Instr.cpp b/contrib/coco/core/src/IR/Instr.cpp index 7da448d..60e7b8e 100644 --- a/contrib/coco/core/src/IR/Instr.cpp +++ b/contrib/coco/core/src/IR/Instr.cpp @@ -23,6 +23,18 @@ FeatureInstr::FeatureInstr(const PtrLink *obj_link) } void FeatureInstr::ifm(FeatureObject *ifm) { _ifm.value(ifm); } + +FeatureObject *FeatureInstr::ifm(void) const +{ + if (auto obj = _ifm.value()) + { + assert(obj->asFeature() != nullptr); + return obj->asFeature(); + } + + return nullptr; +} + void FeatureInstr::ofm(FeatureObject *ofm) { _ofm.value(ofm); } FeatureObject *FeatureInstr::ofm(void) const diff --git a/contrib/coco/core/src/IR/UseSlot.test.cpp b/contrib/coco/core/src/IR/UseSlot.test.cpp index 1f7773b..0558276 100644 --- a/contrib/coco/core/src/IR/UseSlot.test.cpp +++ b/contrib/coco/core/src/IR/UseSlot.test.cpp @@ -26,7 +26,7 @@ TEST_F(UseSlotTest, constructor) ::mock::Use use; - coco::UseSlot slot{&obj_link, &use}; + coco::UseSlot slot{&obj_link, &use}; ASSERT_EQ(slot.value(), nullptr); } @@ -37,7 +37,7 @@ TEST_F(UseSlotTest, value) ::mock::Use use; - coco::UseSlot slot{&obj_link, &use}; + coco::UseSlot slot{&obj_link, &use}; slot.value(o); -- 2.7.4