From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Wed, 12 Sep 2018 23:12:25 +0000 (+0900) Subject: [coco] Introduce replaceAllDepsWith (#1472) X-Git-Tag: nncc_backup~1830 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2dd245541b6ca629febd29bbc7caade770fe039;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Introduce replaceAllDepsWith (#1472) This commit introduces replaceAllDepsWith method in Bag. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/Bag.h b/contrib/coco/core/include/coco/IR/Bag.h index b3e4bf8..3ac8c03 100644 --- a/contrib/coco/core/include/coco/IR/Bag.h +++ b/contrib/coco/core/include/coco/IR/Bag.h @@ -71,6 +71,11 @@ public: // NOTE reaplceWith(b) works correctly only when b is neither Input nor Output void replaceWith(Bag *b); + // @brief Replace all the occurence of a bag in Object with another bag + // + // NOTE Unlike replaceWith(b), replaceAllDepsWith(b) has no restriction + void replaceAllDepsWith(Bag *); + private: std::unique_ptr _info; }; diff --git a/contrib/coco/core/src/IR.test.cpp b/contrib/coco/core/src/IR.test.cpp index 5371a42..792e476 100644 --- a/contrib/coco/core/src/IR.test.cpp +++ b/contrib/coco/core/src/IR.test.cpp @@ -253,6 +253,12 @@ TEST(IR, bag_replaceWith) ASSERT_EQ(shuffle_1->into(), bag_1); ASSERT_EQ(shuffle_2->from(), bag_1); + bag_1->replaceAllDepsWith(bag_2); + + ASSERT_EQ(obj->bag(), bag_2); + ASSERT_EQ(shuffle_1->into(), bag_1); + ASSERT_EQ(shuffle_2->from(), bag_1); + bag_1->replaceWith(bag_2); ASSERT_EQ(obj->bag(), bag_2); diff --git a/contrib/coco/core/src/IR/Bag.cpp b/contrib/coco/core/src/IR/Bag.cpp index 4038028..1175606 100644 --- a/contrib/coco/core/src/IR/Bag.cpp +++ b/contrib/coco/core/src/IR/Bag.cpp @@ -38,14 +38,7 @@ void Bag::replaceWith(Bag *b) { assert(!isInput() && !isOutput()); - // Replace all the occurence inside Dep - while (!(deps()->empty())) - { - auto dep = *(deps()->begin()); - assert(dep->bag() == this); - dep->bag(b); - } - + replaceAllDepsWith(b); // Replace all the occurence inside Read while (!(reads()->empty())) { @@ -67,6 +60,17 @@ void Bag::replaceWith(Bag *b) assert(updates()->empty()); } +void Bag::replaceAllDepsWith(Bag *b) +{ + // Replace all the occurence inside Dep + while (!(deps()->empty())) + { + auto dep = *(deps()->begin()); + assert(dep->bag() == this); + dep->bag(b); + } +} + ObjectSet dependent_objects(const Bag *b) { ObjectSet res;