From 533babd6a8fa62e82d8bd08e66b63e1dfacd58a1 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: Thu, 16 Aug 2018 16:50:17 +0900 Subject: [PATCH] [coco] Record Bag Read/Update set (#1052) This commit introduce Bag::Read and Bag::Update class which allows us to query the location of Bag reads and updates. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Bag.h | 21 ++++++++++++++++++++ contrib/coco/core/include/coco/IR/Object.h | 4 ++-- contrib/coco/core/src/IR/Bag.cpp | 31 ++++++++++++++++++++++++++++++ contrib/coco/core/src/IR/Bag.test.cpp | 4 ++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/Bag.h b/contrib/coco/core/include/coco/IR/Bag.h index 38e9a72..2ec9182 100644 --- a/contrib/coco/core/include/coco/IR/Bag.h +++ b/contrib/coco/core/include/coco/IR/Bag.h @@ -5,6 +5,8 @@ #include "coco/IR/ObjectSet.h" +#include + #include namespace coco @@ -24,6 +26,21 @@ namespace coco class Bag { public: + struct Update + { + virtual ~Update() = default; + }; + + using UpdateSet = std::set; + + struct Read + { + virtual ~Read() = default; + }; + + using ReadSet = std::set; + +public: explicit Bag(std::unique_ptr &&info); public: @@ -39,6 +56,10 @@ public: bool isInput(void) const; bool isOutput(void) const; +public: + ReadSet reads(void) const; + UpdateSet updates(void) const; + private: std::unique_ptr _info; }; diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index 2d90efe..1ee0b72 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -20,12 +20,12 @@ namespace coco class Object { public: - struct Def + struct Def : public Bag::Update { virtual ~Def() = default; }; - struct Use + struct Use : public Bag::Read { virtual ~Use() = default; }; diff --git a/contrib/coco/core/src/IR/Bag.cpp b/contrib/coco/core/src/IR/Bag.cpp index fbeb943..5247a85 100644 --- a/contrib/coco/core/src/IR/Bag.cpp +++ b/contrib/coco/core/src/IR/Bag.cpp @@ -1,6 +1,8 @@ #include "coco/IR/Bag.h" #include "coco/IR/BagInfo.h" +#include "coco/IR/Object.h" + #include namespace coco @@ -23,4 +25,33 @@ const ObjectSet *Bag::object(void) const { return _info->object(); } bool Bag::isInput(void) const { return _info->type() == BagType::Input; } bool Bag::isOutput(void) const { return _info->type() == BagType::Output; } +Bag::ReadSet Bag::reads(void) const +{ + Bag::ReadSet res; + + for (auto obj : *object()) + { + for (auto use : *obj->user()) + { + res.insert(use); + } + } + + return res; +} + +Bag::UpdateSet Bag::updates(void) const +{ + Bag::UpdateSet res; + + for (auto obj : *object()) + { + if (obj->def()) + { + res.insert(obj->def()); + } + } + + return res; +} } // namespace coco diff --git a/contrib/coco/core/src/IR/Bag.test.cpp b/contrib/coco/core/src/IR/Bag.test.cpp index e61a9d9..c1859d8 100644 --- a/contrib/coco/core/src/IR/Bag.test.cpp +++ b/contrib/coco/core/src/IR/Bag.test.cpp @@ -12,4 +12,8 @@ TEST(IR_BAG, ctor_should_set_size) coco::Bag b{make_unique(3)}; ASSERT_EQ(b.size(), 3); + + // Bag has no read/updates at the beginning + EXPECT_EQ(b.reads().size(), 0); + EXPECT_EQ(b.updates().size(), 0); } -- 2.7.4