From 33c63b176806da6a5385fd98d9dc2577474801cd 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, 30 Aug 2018 10:43:57 +0900 Subject: [PATCH] [enco] Introduce usage analysis helpers (#1239) * [enco] Introduce usage analysis helpers This commit introduces several helper functions that allows us to easily analyze how bags and blocks are related with each other. Signed-off-by: Jonghyun Park * Add assert on blk --- contrib/enco/core/src/Usage.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ contrib/enco/core/src/Usage.h | 23 +++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 contrib/enco/core/src/Usage.cpp create mode 100644 contrib/enco/core/src/Usage.h diff --git a/contrib/enco/core/src/Usage.cpp b/contrib/enco/core/src/Usage.cpp new file mode 100644 index 0000000..7f132d4 --- /dev/null +++ b/contrib/enco/core/src/Usage.cpp @@ -0,0 +1,72 @@ +#include "Usage.h" + +namespace enco +{ + +std::set readers(coco::Bag *bag) +{ + std::set res; + + for (auto read : bag->reads()) + { + assert(read != nullptr); + auto instr = read->loc(); + assert(instr != nullptr); + auto block = instr->parent(); + assert(block != nullptr); + + res.insert(block); + } + + return res; +} + +std::set updaters(coco::Bag *bag) +{ + std::set res; + + for (auto update : bag->updates()) + { + assert(update != nullptr); + auto instr = update->loc(); + assert(instr != nullptr); + auto block = instr->parent(); + assert(block != nullptr); + + res.insert(block); + } + + return res; +} + +std::set reads(coco::Block *blk) +{ + std::set res; + + for (auto ins = blk->instr()->head(); ins; ins = ins->next()) + { + for (auto bag : ins->reads()) + { + res.insert(bag); + } + } + + return res; +} + +std::set updates(coco::Block *blk) +{ + std::set res; + + for (auto ins = blk->instr()->head(); ins; ins = ins->next()) + { + for (auto bag : ins->updates()) + { + res.insert(bag); + } + } + + return res; +} + +} // namespace enco diff --git a/contrib/enco/core/src/Usage.h b/contrib/enco/core/src/Usage.h new file mode 100644 index 0000000..5637d9f --- /dev/null +++ b/contrib/enco/core/src/Usage.h @@ -0,0 +1,23 @@ +#ifndef __ENCO_USAGE_H__ +#define __ENCO_USAGE_H__ + +#include "coco/IR.h" + +#include + +namespace enco +{ + +/// @brief Returns the set of blocks that reads a given bag +std::set readers(coco::Bag *bag); +/// @brief Return the set of blocks that updates a given bag +std::set updaters(coco::Bag *bag); + +/// @brief Returns the set of bags that a given block reads +std::set reads(coco::Block *blk); +/// @brief Returns the set of bags that a given block updates +std::set updates(coco::Block *blk); + +} // namespace enco + +#endif // __ENCO_USAGE_H__ -- 2.7.4