[coco] Explicit Input/Output link from Bag (#1526)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Sep 2018 09:56:25 +0000 (18:56 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 17 Sep 2018 09:56:25 +0000 (18:56 +0900)
This commit revises Bag class to maintain explicit Input/Output link (to
make it easy to manipulate).

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Bag.h
contrib/coco/core/include/coco/IR/Input.forward.h [new file with mode: 0644]
contrib/coco/core/include/coco/IR/Output.forward.h [new file with mode: 0644]
contrib/coco/core/src/IR/Bag.cpp
contrib/coco/core/src/IR/Input.cpp
contrib/coco/core/src/IR/Output.cpp

index e3a5b12..f439eef 100644 (file)
@@ -7,6 +7,8 @@
 #include "coco/IR/DepSet.h"
 #include "coco/IR/ReadSet.h"
 #include "coco/IR/UpdateSet.h"
+#include "coco/IR/Input.forward.h"
+#include "coco/IR/Output.forward.h"
 #include "coco/IR/Locatable.h"
 
 #include <set>
@@ -73,6 +75,10 @@ public:
   const UpdateSet *updates(void) const;
 
 public:
+  Input *input(void) const { return _input; }
+  Output *output(void) const { return _output; }
+
+public:
   // @brief Replace all the occurence of a bag (except those in Input/Output) with another bag
   //
   // NOTE reaplceWith(b) works correctly only when b is neither Input nor Output
@@ -92,6 +98,12 @@ public:
   UpdateSet *updates(void) { return &_updates; }
 
 private:
+  // WARN Only Input is allowed to access this method
+  void input(Input *i) { _input = i; }
+  // WARN Only Output is allowed to access this method
+  void output(Output *o) { _output = o; }
+
+private:
   std::unique_ptr<BagInfo> _info;
 
 private:
@@ -101,6 +113,9 @@ private:
   ReadSet _reads;
   /** @brief Direct updates (not through Object) */
   UpdateSet _updates;
+
+  Input *_input = nullptr;
+  Output *_output = nullptr;
 };
 
 // @brief Return a set of objects that depends on a given bag
diff --git a/contrib/coco/core/include/coco/IR/Input.forward.h b/contrib/coco/core/include/coco/IR/Input.forward.h
new file mode 100644 (file)
index 0000000..ca1aa14
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __COCO_IR_INPUT_FORWARD_H__
+#define __COCO_IR_INPUT_FORWARD_H__
+
+namespace coco
+{
+
+class Input;
+
+} // namespace coco
+
+#endif // __COCO_IR_INPUT_FORWARD_H__
diff --git a/contrib/coco/core/include/coco/IR/Output.forward.h b/contrib/coco/core/include/coco/IR/Output.forward.h
new file mode 100644 (file)
index 0000000..c46fb74
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __COCO_IR_OUTPUT_FORWARD_H__
+#define __COCO_IR_OUTPUT_FORWARD_H__
+
+namespace coco
+{
+
+class Output;
+
+} // namespace coco
+
+#endif // __COCO_IR_OUTPUT_FORWARD_H__
index 90fdb59..5f6f305 100644 (file)
@@ -27,8 +27,8 @@ Bag::~Bag()
 
 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); }
+bool Bag::isInput(void) const { return _input != nullptr; }
+bool Bag::isOutput(void) const { return _output != nullptr; }
 
 const DepSet *Bag::deps(void) const { return &_deps; }
 const ReadSet *Bag::reads(void) const { return &_reads; }
index dff6962..bd172cc 100644 (file)
@@ -13,20 +13,14 @@ Input::Input(const nncc::core::ADT::tensor::Shape &shape) : Arg{shape}
 
 void Input::onTake(Bag *bag)
 {
-  auto info = bag->_info.get();
-  assert(info != nullptr);
-  assert(!info->mask()->masked(BagMask::Input));
-
-  info->mask()->set(BagMask::Input);
+  assert(bag->input() == nullptr);
+  bag->input(this);
 }
 
 void Input::onRelease(Bag *bag)
 {
-  auto info = bag->_info.get();
-  assert(info != nullptr);
-  assert(info->mask()->masked(BagMask::Input));
-
-  info->mask()->unset(BagMask::Input);
+  assert(bag->input() == this);
+  bag->input(nullptr);
 }
 
 } // namespace coco
index 44fd187..9928890 100644 (file)
@@ -11,20 +11,14 @@ Output::Output(const nncc::core::ADT::tensor::Shape &shape) : Arg{shape}
 
 void Output::onTake(Bag *bag)
 {
-  auto info = bag->_info.get();
-  assert(info != nullptr);
-  assert(!info->mask()->masked(BagMask::Output));
-
-  info->mask()->set(BagMask::Output);
+  assert(bag->output() == nullptr);
+  bag->output(this);
 }
 
 void Output::onRelease(Bag *bag)
 {
-  auto info = bag->_info.get();
-  assert(info != nullptr);
-  assert(info->mask()->masked(BagMask::Output));
-
-  info->mask()->unset(BagMask::Output);
+  assert(bag->output() == this);
+  bag->output(nullptr);
 }
 
 } // namespace coco