--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __COCO_IR_EVAL_H__
+#define __COCO_IR_EVAL_H__
+
+#include "coco/IR/Instr.h"
+#include "coco/IR/Def.h"
+#include "coco/IR/Step.h"
+
+namespace coco
+{
+
+/**
+ * @brief Evaluate an Object from a given Op
+ */
+class Eval final : public Instr, public Object::Producer
+{
+public:
+ explicit Eval();
+
+public:
+ Eval *asEval(void) override { return this; }
+ const Eval *asEval(void) const override { return this; }
+
+public:
+ std::set<Bag *> reads(void) const override;
+ std::set<Bag *> updates(void) const override;
+
+public:
+ Instr *loc(void) override { return this; }
+
+public:
+ Object *out(void) const { return _out.value(); }
+ void out(Object *obj) { _out.value(obj); }
+
+public:
+ Op *op(void) const { return _step.op(); }
+ void op(Op *op) { _step.op(op); }
+
+private:
+ Def _out;
+ Step _step;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_EVAL_H__
// INSTR(Name)
+INSTR(Eval)
INSTR(UnitF)
INSTR(Shuffle)
INSTR(Copy)
#define __COCO_IR_INSTR_MANAGER_H__
#include "coco/IR/Instr.h"
+#include "coco/IR/Eval.h"
#include "coco/IR/UnitF.h"
#include "coco/IR/Shuffle.h"
#include "coco/IR/Copy.h"
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "coco/IR/Eval.h"
+#include "coco/IR/Op.h"
+
+#include <cassert>
+
+namespace
+{
+std::set<coco::Bag *> &operator+=(std::set<coco::Bag *> &res, const coco::Object *o)
+{
+ if (o != nullptr && o->bag() != nullptr)
+ {
+ res.insert(o->bag());
+ }
+ return res;
+}
+} // namespace
+
+namespace coco
+{
+
+Eval::Eval() : _out{this}
+{
+ // DO NOTHING
+}
+
+std::set<Bag *> Eval::reads(void) const
+{
+ std::set<Bag *> res;
+
+ if (auto e = op())
+ {
+ for (auto obj : e->uses())
+ {
+ res += obj;
+ }
+ }
+
+ return res;
+}
+
+std::set<Bag *> Eval::updates(void) const
+{
+ std::set<Bag *> res;
+
+ res += out();
+
+ return res;
+}
+
+} // namespace coco
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "coco/IR/Eval.h"
+#include "coco/IR/ObjectManager.h"
+#include "coco/IR/OpManager.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+class EvalTest : public ::testing::Test
+{
+public:
+ virtual ~EvalTest() = default;
+
+protected:
+ coco::Eval *allocate(void)
+ {
+ auto ins = new coco::Eval{};
+ _allocated.emplace_back(ins);
+ return ins;
+ }
+
+private:
+ std::vector<std::unique_ptr<coco::Instr>> _allocated;
+};
+} // namespace
+
+TEST_F(EvalTest, constructor)
+{
+ auto ins = allocate();
+
+ ASSERT_EQ(ins->out(), nullptr);
+ ASSERT_EQ(ins->op(), nullptr);
+ ASSERT_TRUE(ins->reads().empty());
+ ASSERT_TRUE(ins->updates().empty());
+}
+
+TEST_F(EvalTest, asEval)
+{
+ auto ins = allocate();
+
+ coco::Instr *mutable_ptr = ins;
+ const coco::Instr *immutable_ptr = ins;
+
+ ASSERT_NE(mutable_ptr->asEval(), nullptr);
+ ASSERT_EQ(mutable_ptr->asEval(), immutable_ptr->asEval());
+}
namespace coco
{
+template <> Eval *InstrManager::create(void)
+{
+ auto ins = nncc::foundation::make_unique<Eval>();
+ modulize(ins.get());
+ return take(std::move(ins));
+}
+
template <> UnitF *InstrManager::create(void)
{
auto ins = nncc::foundation::make_unique<UnitF>();