From ed09cb3d63862202fe4b66b7f644558fc3060954 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: Tue, 11 Sep 2018 17:07:16 +0900 Subject: [PATCH] [coco] Refine Bag::reads method interface (#1446) 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 --- contrib/coco/core/include/coco/IR/Bag.h | 5 +-- contrib/coco/core/include/coco/IR/ReadSet.h | 2 +- contrib/coco/core/src/IR/Bag.cpp | 47 +++++++++++++++-------------- contrib/coco/core/src/IR/Bag.test.cpp | 2 +- contrib/coco/core/src/IR/Read.test.cpp | 18 +++-------- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/Bag.h b/contrib/coco/core/include/coco/IR/Bag.h index 98092ad..3e7c72c 100644 --- a/contrib/coco/core/include/coco/IR/Bag.h +++ b/contrib/coco/core/include/coco/IR/Bag.h @@ -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 @@ -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; diff --git a/contrib/coco/core/include/coco/IR/ReadSet.h b/contrib/coco/core/include/coco/IR/ReadSet.h index 021f8e8..2962ece 100644 --- a/contrib/coco/core/include/coco/IR/ReadSet.h +++ b/contrib/coco/core/include/coco/IR/ReadSet.h @@ -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 diff --git a/contrib/coco/core/src/IR/Bag.cpp b/contrib/coco/core/src/IR/Bag.cpp index 1876213..bd4d621 100644 --- a/contrib/coco/core/src/IR/Bag.cpp +++ b/contrib/coco/core/src/IR/Bag.cpp @@ -2,6 +2,7 @@ #include "coco/IR/BagInfo.h" #include "coco/IR/Object.h" +#include "coco/IR/Read.h" #include @@ -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 diff --git a/contrib/coco/core/src/IR/Bag.test.cpp b/contrib/coco/core/src/IR/Bag.test.cpp index c1859d8..dbb3409 100644 --- a/contrib/coco/core/src/IR/Bag.test.cpp +++ b/contrib/coco/core/src/IR/Bag.test.cpp @@ -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); } diff --git a/contrib/coco/core/src/IR/Read.test.cpp b/contrib/coco/core/src/IR/Read.test.cpp index 8fa4d9e..88f70f2 100644 --- a/contrib/coco/core/src/IR/Read.test.cpp +++ b/contrib/coco/core/src/IR/Read.test.cpp @@ -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); } -- 2.7.4