[coco] Support partial shuffling (#1382)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 6 Sep 2018 10:54:46 +0000 (19:54 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 6 Sep 2018 10:54:46 +0000 (19:54 +0900)
Shuffle instruction now uses 'map' instead of 'vector' to store
element transfers between two bags.

This change allows users to encode partial shuffling in coco IR.

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

index 00908c0..759ced7 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "coco/ADT/PtrLink.h"
 
-#include <vector>
+#include <map>
 
 namespace coco
 {
@@ -46,7 +46,13 @@ public:
   void into(Bag *);
 
 public:
-  const ElemID &at(uint32_t n) const { return _content.at(n); }
+  /**
+   * Let M be the return of at(N). This means that N-th element in the destination
+   * bag will be filled with the value of M-th element in the source bag.
+   *
+   * NOTE at(n) may be undefined on partial shuffle
+   */
+  const ElemID &at(uint32_t n) const { return _content.at(ElemID{n}); }
 
 public:
   void insert(const ElemID &from, const ElemID &into);
@@ -59,7 +65,7 @@ private:
   UpdateSlot<Bag> _into;
 
 private:
-  std::vector<ElemID> _content;
+  std::map<ElemID /* DST */, ElemID /* SRC */> _content;
 };
 
 } // namespace coco
index 08926cb..afa1926 100644 (file)
@@ -15,7 +15,7 @@ std::set<coco::Bag *> &operator+=(std::set<coco::Bag *> &res, coco::Bag *b)
 namespace coco
 {
 
-void Shuffle::insert(const ElemID &from, const ElemID &into) { _content.at(into.value()) = from; }
+void Shuffle::insert(const ElemID &from, const ElemID &into) { _content[into] = from; }
 
 std::set<Bag *> Shuffle::reads(void) const
 {
@@ -36,11 +36,6 @@ std::set<Bag *> Shuffle::updates(void) const
 }
 
 void Shuffle::from(Bag *b) { _from.value(b); }
-
-void Shuffle::into(Bag *b)
-{
-  _into.value(b);
-  _content.resize((b == nullptr) ? 0 : b->size());
-}
+void Shuffle::into(Bag *b) { _into.value(b); }
 
 } // namespace coco