[coco] Refine Bag::reads method interface (#1446)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 11 Sep 2018 08:07:16 +0000 (17:07 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 11 Sep 2018 08:07:16 +0000 (17:07 +0900)
This commit refines Bag::reads method to support constant-time access
over Read links.

Note that this commit introduces semantic changes over Bag::reads
method, but does not change the semantics of readers helper.

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

index 98092ad..3e7c72c 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "coco/IR/ObjectSet.h"
 #include "coco/IR/DepSet.h"
+#include "coco/IR/ReadSet.h"
 #include "coco/IR/Locatable.h"
 
 #include <set>
@@ -58,8 +59,8 @@ public:
 public:
   // @brief Return the set of Dep links that point to this bag
   const DepSet *deps(void) const;
-  // WARN This method will be deprecated. Please below "readers" instead
-  ReaderSet reads(void) const;
+  // @brief Return the set of Read links that point to this bag
+  const ReadSet *reads(void) const;
   // WARN This method will be dpercated. Please use below "updaters" instead
   UpdaterSet updates(void) const;
 
index 021f8e8..2962ece 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __COCO_IR_READ_SET_H__
 #define __COCO_IR_READ_SET_H__
 
-#include "coco/IR/Read.h"
+#include "coco/IR/Read.forward.h"
 
 #include <set>
 
index 1876213..bd4d621 100644 (file)
@@ -2,6 +2,7 @@
 #include "coco/IR/BagInfo.h"
 
 #include "coco/IR/Object.h"
+#include "coco/IR/Read.h"
 
 #include <nncc/foundation/Memory.h>
 
@@ -24,28 +25,7 @@ bool Bag::isInput(void) const { return _info->mask()->masked(BagMask::Input); }
 bool Bag::isOutput(void) const { return _info->mask()->masked(BagMask::Output); }
 
 const DepSet *Bag::deps(void) const { return _info->deps(); }
-
-Bag::ReaderSet Bag::reads(void) const
-{
-  Bag::ReaderSet res;
-
-  for (auto obj : dependent_objects(this))
-  {
-    for (auto use : *obj->user())
-    {
-      res.insert(use);
-    }
-  }
-
-  for (auto read : *_info->reads())
-  {
-    auto reader = read->reader();
-    assert(reader != nullptr);
-    res.insert(reader);
-  }
-
-  return res;
-}
+const ReadSet *Bag::reads(void) const { return _info->reads(); }
 
 Bag::UpdaterSet Bag::updates(void) const
 {
@@ -84,7 +64,28 @@ ObjectSet dependent_objects(const Bag *b)
   return res;
 }
 
-Bag::ReaderSet readers(const Bag *b) { return b->reads(); }
+Bag::ReaderSet readers(const Bag *b)
+{
+  Bag::ReaderSet res;
+
+  for (auto obj : dependent_objects(b))
+  {
+    for (auto use : *obj->user())
+    {
+      res.insert(use);
+    }
+  }
+
+  for (auto read : *b->reads())
+  {
+    auto reader = read->reader();
+    assert(reader != nullptr);
+    res.insert(reader);
+  }
+
+  return res;
+}
+
 Bag::UpdaterSet updaters(const Bag *b) { return b->updates(); }
 
 } // namespace coco
index c1859d8..dbb3409 100644 (file)
@@ -14,6 +14,6 @@ TEST(IR_BAG, ctor_should_set_size)
   ASSERT_EQ(b.size(), 3);
 
   // Bag has no read/updates at the beginning
-  EXPECT_EQ(b.reads().size(), 0);
+  EXPECT_EQ(b.reads()->size(), 0);
   EXPECT_EQ(b.updates().size(), 0);
 }
index 8fa4d9e..88f70f2 100644 (file)
@@ -40,22 +40,14 @@ TEST_F(ReadTest, value)
 
   ASSERT_EQ(slot.bag(), bag);
 
-  {
-    auto reads = bag->reads();
-
-    ASSERT_EQ(reads.size(), 1);
-    ASSERT_NE(reads.find(&read), reads.end());
-  }
+  ASSERT_EQ(bag->reads()->size(), 1);
+  ASSERT_NE(bag->reads()->find(&slot), bag->reads()->end());
 
   slot.bag(nullptr);
 
-  {
-    auto reads = bag->reads();
-
-    ASSERT_EQ(slot.bag(), nullptr);
+  ASSERT_EQ(slot.bag(), nullptr);
 
-    ASSERT_EQ(reads.size(), 0);
-  }
+  ASSERT_EQ(bag->reads()->size(), 0);
 }
 
 TEST_F(ReadTest, unlink_on_destruction)
@@ -69,5 +61,5 @@ TEST_F(ReadTest, unlink_on_destruction)
     read.bag(bag);
   }
 
-  ASSERT_EQ(bag->reads().size(), 0);
+  ASSERT_EQ(bag->reads()->size(), 0);
 }