[coco] Return Def instead Producer (#1521)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Sep 2018 07:16:24 +0000 (16:16 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 17 Sep 2018 07:16:24 +0000 (16:16 +0900)
This commit revises Object::def method to return a pointer to Def
instead of a pointer to its Producer.

This commit also revises all the related implementations and tests.

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

index 60bfd6f..d73421c 100644 (file)
@@ -4,6 +4,7 @@
 #include "coco/IR/Bag.h"
 #include "coco/IR/Dep.h"
 #include "coco/IR/ObjectInfo.forward.h"
+#include "coco/IR/Def.forward.h"
 
 #include "coco/IR/FeatureObject.forward.h"
 #include "coco/IR/KernelObject.forward.h"
@@ -60,8 +61,8 @@ private:
   ObjectInfo *info(void) const;
 
 public:
-  // WARN These methods are deprecated. Please use 'producer' and 'consumers' instead.
-  Producer *def(void) const;
+  Def *def(void) const;
+  // WARN user methods are deprecated. Please use below 'consumers' instead.
   const ConsumerSet *user(void) const;
 
 private:
index c55c93b..90fdb59 100644 (file)
@@ -114,9 +114,9 @@ Bag::UpdaterSet updaters(const Bag *b)
 
   for (auto obj : dependent_objects(b))
   {
-    if (obj->def())
+    if (auto p = producer(obj))
     {
-      res.insert(obj->def());
+      res.insert(p);
     }
   }
 
index 7abce04..d0711b6 100644 (file)
@@ -48,7 +48,7 @@ TEST_F(DefTest, value)
 
   ASSERT_EQ(slot.value(), o);
 
-  ASSERT_EQ(o->def(), &def);
+  ASSERT_EQ(o->def(), &slot);
 
   slot.value(nullptr);
 
@@ -65,7 +65,7 @@ TEST_F(DefTest, unlink_on_destruction)
   auto slot = make_unique<coco::Def>(&obj_link, &def);
 
   slot->value(o);
-  ASSERT_EQ(o->def(), &def);
+  ASSERT_EQ(o->def(), slot.get());
 
   // Let's destruct the allocated slot
   slot.reset(nullptr);
index 296c6ce..cdba1c6 100644 (file)
@@ -90,7 +90,7 @@ TEST_F(FeatureInstrTest, ofm_update)
   ins.ofm(obj);
   ASSERT_EQ(ins.ofm(), obj);
 
-  ASSERT_EQ(obj->def(), &ins);
+  ASSERT_EQ(coco::producer(obj), &ins);
 }
 
 // TODO Move these tests into UnitF.test.cpp
index 664ba32..2338d08 100644 (file)
@@ -22,9 +22,13 @@ ObjectInfo *Object::info(void) const
   return res;
 }
 
-Object::Producer *Object::def(void) const
+Def *Object::def(void) const { return info()->def(); }
+
+const Object::ConsumerSet *Object::user(void) const { return info()->user(); }
+
+Object::Producer *producer(const Object *obj)
 {
-  if (auto d = info()->def())
+  if (auto d = obj->def())
   {
     return d->producer();
   }
@@ -32,9 +36,6 @@ Object::Producer *Object::def(void) const
   return nullptr;
 }
 
-const Object::ConsumerSet *Object::user(void) const { return info()->user(); }
-
-Object::Producer *producer(const Object *obj) { return obj->def(); }
 Object::ConsumerSet consumers(const Object *obj) { return *(obj->user()); }
 
 } // namespace coco