[coco] Introduce replaceAllDepsWith (#1472)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 12 Sep 2018 23:12:25 +0000 (08:12 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 12 Sep 2018 23:12:25 +0000 (08:12 +0900)
This commit introduces replaceAllDepsWith method in Bag.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Bag.h
contrib/coco/core/src/IR.test.cpp
contrib/coco/core/src/IR/Bag.cpp

index b3e4bf8..3ac8c03 100644 (file)
@@ -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<BagInfo> _info;
 };
index 5371a42..792e476 100644 (file)
@@ -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);
index 4038028..1175606 100644 (file)
@@ -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;