blob: 9a889e1da34522109816adb0e5fa460d527fd5e8 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2019 Arm Limited.
Georgios Pinitasd8734b52017-12-22 15:27:52 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#include "arm_compute/graph/PassManager.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000025
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010026#include "arm_compute/graph/Logger.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000027
28namespace arm_compute
29{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010030namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000031{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010032PassManager::PassManager() : _passes()
Georgios Pinitasd8734b52017-12-22 15:27:52 +000033{
34}
35
36const std::vector<std::unique_ptr<IGraphMutator>> &PassManager::passes() const
37{
38 return _passes;
39}
40
41IGraphMutator *PassManager::pass(size_t index)
42{
43 return (index >= _passes.size()) ? nullptr : _passes.at(index).get();
44}
45
Georgios Pinitas1c32bf3962018-11-12 18:36:19 +000046void PassManager::append(std::unique_ptr<IGraphMutator> pass, bool conditional)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000047{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010048 if (pass && conditional)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000049 {
50 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Appending mutating pass : " << pass->name() << std::endl);
51 _passes.push_back(std::move(pass));
52 }
53}
54
55void PassManager::clear()
56{
57 _passes.clear();
58}
59
60void PassManager::run_all(Graph &g)
61{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 for (auto &pass : _passes)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000063 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010064 if (pass)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000065 {
66 ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
67 pass->mutate(g);
68 }
69 }
70}
71
Georgios Pinitasf4261ad2019-12-02 11:58:19 +000072void PassManager::run_type(Graph &g, IGraphMutator::MutationType type)
73{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010074 for (auto &pass : _passes)
Georgios Pinitasf4261ad2019-12-02 11:58:19 +000075 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010076 if (pass && (pass->type() == type))
Georgios Pinitasf4261ad2019-12-02 11:58:19 +000077 {
78 ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
79 pass->mutate(g);
80 }
81 }
82}
83
84void PassManager::run_index(Graph &g, size_t index)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000085{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010086 if (index >= _passes.size())
Georgios Pinitasd8734b52017-12-22 15:27:52 +000087 {
88 return;
89 }
90
91 auto &pass = _passes.at(index);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092 if (pass != nullptr)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000093 {
Georgios Pinitasf4261ad2019-12-02 11:58:19 +000094 ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
Georgios Pinitasd8734b52017-12-22 15:27:52 +000095 pass->mutate(g);
96 }
97}
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010098} // namespace graph
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099} // namespace arm_compute