From 0303810e6d00980d9871e518d7fbcf23ea1dbbc9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 26 Aug 2019 16:25:42 +0900 Subject: [PATCH] [logo] Introduce PhaseRunner (#6909) This will introduce PhaseRunner that runs group of Pass(es) that is defined as a Phase Signed-off-by: SaeHie Park --- compiler/logo/include/logo/Phase.h | 75 ++++++++++++++++++++++++++++++++++++++ compiler/logo/src/Phase.cpp | 57 +++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 compiler/logo/include/logo/Phase.h create mode 100644 compiler/logo/src/Phase.cpp diff --git a/compiler/logo/include/logo/Phase.h b/compiler/logo/include/logo/Phase.h new file mode 100644 index 0000000..1a1a6f0 --- /dev/null +++ b/compiler/logo/include/logo/Phase.h @@ -0,0 +1,75 @@ +/* + * 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 + +#include + +#include +#include + +namespace logo +{ + +// Phase is a collection of Pass(es) +using Phase = std::vector>; + +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 class PhaseRunner; + +template <> class PhaseRunner +{ +public: + PhaseRunner(loco::Graph *graph) : _graph{graph} + { + // DO NOTHING + } + +public: + void run(const Phase &) const; + +private: + loco::Graph *_graph; +}; + +template <> class PhaseRunner +{ +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__ diff --git a/compiler/logo/src/Phase.cpp b/compiler/logo/src/Phase.cpp new file mode 100644 index 0000000..6964302 --- /dev/null +++ b/compiler/logo/src/Phase.cpp @@ -0,0 +1,57 @@ +/* + * 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 + +namespace logo +{ + +void PhaseRunner::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::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 -- 2.7.4