[coco] Manage DepSet/ReadSet/UpdateSet in Bag (#1518)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Sep 2018 07:04:23 +0000 (16:04 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 17 Sep 2018 07:04:23 +0000 (16:04 +0900)
This commit moves DepSet/ReadSet/UpdateSet in BagInto into Bag. This is
the first step to unify Bag and BagInfo class.

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

index 4959168..e3a5b12 100644 (file)
@@ -83,8 +83,24 @@ public:
   // NOTE Unlike replaceWith(b), replaceAllDepsWith(b) has no restriction
   void replaceAllDepsWith(Bag *);
 
+public:
+  // WARN Only Dep is allowed to access this method
+  DepSet *deps(void) { return &_deps; }
+  // WARN Only Read is allowed to access this method
+  ReadSet *reads(void) { return &_reads; }
+  // WARN Only Update is allowed to access this method
+  UpdateSet *updates(void) { return &_updates; }
+
 private:
   std::unique_ptr<BagInfo> _info;
+
+private:
+  /** @brief Links to dependent Object(s) */
+  DepSet _deps;
+  /** @brief Direct reads (not through Object) */
+  ReadSet _reads;
+  /** @brief Direct updates (not through Object) */
+  UpdateSet _updates;
 };
 
 // @brief Return a set of objects that depends on a given bag
index 626f342..f098f2c 100644 (file)
@@ -57,29 +57,10 @@ private:
   uint32_t const _size;
 
 public:
-  DepSet *deps(void) { return &_deps; }
-  const DepSet *deps(void) const { return &_deps; }
-
-public:
-  ReadSet *reads(void) { return &_reads; }
-  const ReadSet *reads(void) const { return &_reads; }
-
-public:
-  UpdateSet *updates(void) { return &_updates; }
-  const UpdateSet *updates(void) const { return &_updates; }
-
-public:
   BagMask *mask(void) { return &_mask; }
   const BagMask *mask(void) const { return &_mask; }
 
 private:
-  /** @brief Links to dependent Object(s) */
-  DepSet _deps;
-  /** @brief Direct reads (not through Object) */
-  ReadSet _reads;
-  /** @brief Direct updates (not through Object) */
-  UpdateSet _updates;
-
   BagMask _mask;
 };
 
index 1175606..c55c93b 100644 (file)
@@ -20,9 +20,9 @@ Bag::Bag(std::unique_ptr<BagInfo> &&info) : _info{std::move(info)}
 Bag::~Bag()
 {
   // All the references over a bag SHOULD be dropped before its destruction
-  assert(_info->deps()->size() == 0);
-  assert(_info->reads()->size() == 0);
-  assert(_info->updates()->size() == 0);
+  assert(deps()->size() == 0);
+  assert(reads()->size() == 0);
+  assert(updates()->size() == 0);
 }
 
 uint32_t Bag::size(void) const { return _info->size(); }
@@ -30,9 +30,9 @@ uint32_t Bag::size(void) const { return _info->size(); }
 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(); }
-const ReadSet *Bag::reads(void) const { return _info->reads(); }
-const UpdateSet *Bag::updates(void) const { return _info->updates(); }
+const DepSet *Bag::deps(void) const { return &_deps; }
+const ReadSet *Bag::reads(void) const { return &_reads; }
+const UpdateSet *Bag::updates(void) const { return &_updates; }
 
 void Bag::replaceWith(Bag *b)
 {
index d1a6d13..7429900 100644 (file)
@@ -16,11 +16,8 @@ void Dep::bag(Bag *bag)
     // Remove bag <-> dep link
     // TODO Remove unnecessary indentation
     {
-      auto info = _bag->_info.get();
-      assert(info != nullptr);
-      assert(info->deps()->find(this) != info->deps()->end());
-
-      info->deps()->erase(this);
+      assert(_bag->deps()->find(this) != _bag->deps()->end());
+      _bag->deps()->erase(this);
     }
 
     // Reset _bag
@@ -37,9 +34,7 @@ void Dep::bag(Bag *bag)
     // Create bag <-> dep link
     // TODO Remove unnecessary indentation
     {
-      auto info = _bag->_info.get();
-      assert(info != nullptr);
-      info->deps()->insert(this);
+      _bag->deps()->insert(this);
     }
   }
 
index 66b5334..9e1b82a 100644 (file)
@@ -18,9 +18,7 @@ void Read::bag(Bag *bag)
   {
     // TODO Remove unnecessary indentation
     {
-      auto info = _bag->_info.get();
-      assert(info != nullptr);
-      info->reads()->erase(this);
+      _bag->reads()->erase(this);
     }
     _bag = nullptr;
   }
@@ -32,9 +30,7 @@ void Read::bag(Bag *bag)
     _bag = bag;
     // TODO Remove unnecessary indentation
     {
-      auto info = _bag->_info.get();
-      assert(info != nullptr);
-      info->reads()->insert(this);
+      _bag->reads()->insert(this);
     }
   }
 
index 48b6db9..3a37701 100644 (file)
@@ -18,9 +18,7 @@ void Update::bag(Bag *bag)
   {
     // TODO Remove unnecessary indentation
     {
-      auto info = _bag->_info.get();
-      assert(info != nullptr);
-      info->updates()->erase(this);
+      _bag->updates()->erase(this);
     }
     _bag = nullptr;
   }
@@ -32,9 +30,7 @@ void Update::bag(Bag *bag)
     _bag = bag;
     // TODO Remove unnecessary indentation
     {
-      auto info = _bag->_info.get();
-      assert(info != nullptr);
-      info->updates()->insert(this);
+      _bag->updates()->insert(this);
     }
   }