--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOGO_PHASE_H__
+#define __LOGO_PHASE_H__
+
+#include <logo/Pass.h>
+
+#include <loco.h>
+
+#include <vector>
+#include <memory>
+
+namespace logo
+{
+
+// Phase is a collection of Pass(es)
+using Phase = std::vector<std::unique_ptr<Pass>>;
+
+enum class PhaseStrategy
+{
+ // Run all the passes until there is no pass that makes a change
+ Saturate,
+ // Same as Saturate but will restart from the first when there is a change
+ Restart,
+};
+
+template <PhaseStrategy S> class PhaseRunner;
+
+template <> class PhaseRunner<PhaseStrategy::Saturate>
+{
+public:
+ PhaseRunner(loco::Graph *graph) : _graph{graph}
+ {
+ // DO NOTHING
+ }
+
+public:
+ void run(const Phase &) const;
+
+private:
+ loco::Graph *_graph;
+};
+
+template <> class PhaseRunner<PhaseStrategy::Restart>
+{
+public:
+ PhaseRunner(loco::Graph *graph) : _graph{graph}
+ {
+ // DO NOTHING
+ }
+
+public:
+ void run(const Phase &) const;
+
+private:
+ loco::Graph *_graph;
+};
+
+} // namespace logo
+
+#endif // __LOGO_PHASE_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 <logo/Phase.h>
+
+namespace logo
+{
+
+void PhaseRunner<PhaseStrategy::Saturate>::run(const Phase &phase) const
+{
+ for (bool changed = true; changed;)
+ {
+ changed = false;
+
+ for (auto &pass : phase)
+ {
+ bool pass_changed = pass->run(_graph);
+ changed = changed || pass_changed;
+ }
+ }
+}
+
+void PhaseRunner<PhaseStrategy::Restart>::run(const Phase &phase) const
+{
+ for (bool changed = true; changed;)
+ {
+ changed = false;
+
+ for (auto &pass : phase)
+ {
+ if (pass->run(_graph))
+ {
+ changed = true;
+ }
+
+ if (changed)
+ {
+ break;
+ }
+ }
+ }
+}
+
+} // namespace logo