From cba5d61748e4ccf5f0d860e2cbfecbae0851b649 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 13:05:11 +0900 Subject: [PATCH] [enco] Insert Copy after Eval if necessary (#1796) This commit revises data layout conversion pass to insert Copy after Eval if necessary. Signed-off-by: Jonghyun Park --- .../core/src/Transforms/DataLayoutConversion.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp b/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp index e114571..4cd1d49 100644 --- a/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp +++ b/contrib/enco/core/src/Transforms/DataLayoutConversion.cpp @@ -87,6 +87,29 @@ void insert_copy_before_load(coco::Load *load) } } +/** + * @brief Insert Copy after Eval if necessary + */ +void insert_copy_after_eval(coco::Eval *eval) +{ + if (auto out = eval->out()) + { + if (auto ofm = out->asFeature()) + { + if (ofm->layout()->id() != coco::FeatureLayouts::BHWC::uid()) + { + auto oldobj = ofm; + auto newobj = clone_feature(oldobj); + + eval->out(newobj); + + auto copy = make_copy(newobj, oldobj); + copy->insertAfter(eval); + } + } + } +} + class ShuffleGen : public coco::Instr::Mutator { public: @@ -207,6 +230,24 @@ std::set loads(coco::Module *m) return res; } +/** + * @brief Return the set of every (allocated) Eval instruction in a given module + */ +std::set evals(coco::Module *m) +{ + std::set res; + + for (uint32_t n = 0; n < m->entity()->instr()->size(); ++n) + { + if (auto eval = m->entity()->instr()->at(n)->asEval()) + { + res.insert(eval); + } + } + + return res; +} + class NormalizePass { private: @@ -226,6 +267,12 @@ void NormalizePass::runOnModule(coco::Module *m) const insert_copy_before_load(load); } + // Insert Copy after all Eval Instr (if necessary) + for (auto eval : evals(m)) + { + insert_copy_after_eval(eval); + } + for (auto blk = m->block()->head(); blk; blk = blk->next()) { for (auto ins = blk->instr()->head(); ins; ins = ins->next()) -- 2.7.4