From b1d28586dc31f49598460c0226dda1e9f668d8d1 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: Wed, 10 Oct 2018 11:11:43 +0900 Subject: [PATCH] [enco] clone_feature as a non-class helper (#1792) This commit extracts 'clone' method in ShuffleGen as 'clone_feature' which is a non-class helper function. Signed-off-by: Jonghyun Park --- .../core/src/Transforms/DataLayoutConversion.cpp | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp b/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp index 9edc202..2f720b9 100644 --- a/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp +++ b/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp @@ -45,6 +45,23 @@ coco::Copy *make_copy(coco::FeatureObject *from, coco::FeatureObject *into) return copy; } +coco::FeatureObject *clone_feature(const coco::FeatureObject *oldobj) +{ + auto module = oldobj->module(); + auto newobj = module->entity()->object()->create(oldobj->shape()); + newobj->layout(coco::FeatureLayouts::BHWC::create(oldobj->shape())); + + if (auto oldbag = oldobj->bag()) + { + assert(oldbag->module() == module); + // Clone bag only when there is a backing bag for a given feature object + auto newbag = module->entity()->bag()->create(oldbag->size()); + newobj->bag(newbag); + } + + return newobj; +} + class ShuffleGen : public coco::Instr::Mutator { public: @@ -67,17 +84,7 @@ private: coco::FeatureObject *ShuffleGen::clone(const coco::FeatureObject *oldobj) const { - auto newobj = _module->entity()->object()->create(oldobj->shape()); - newobj->layout(coco::FeatureLayouts::BHWC::create(oldobj->shape())); - - if (auto oldbag = oldobj->bag()) - { - // Clone bag only when there is a backing bag for a given feature object - auto newbag = _module->entity()->bag()->create(oldbag->size()); - newobj->bag(newbag); - } - - return newobj; + return clone_feature(oldobj); } void ShuffleGen::mutate(coco::UnitF *unit) -- 2.7.4