blob: f7e214c1b45b92887fa456b49d08adb2d38152c4 [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{
32PassManager::PassManager()
33 : _passes()
34{
35}
36
37const std::vector<std::unique_ptr<IGraphMutator>> &PassManager::passes() const
38{
39 return _passes;
40}
41
42IGraphMutator *PassManager::pass(size_t index)
43{
44 return (index >= _passes.size()) ? nullptr : _passes.at(index).get();
45}
46
Georgios Pinitas1c32bf3962018-11-12 18:36:19 +000047void PassManager::append(std::unique_ptr<IGraphMutator> pass, bool conditional)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000048{
Georgios Pinitas1c32bf3962018-11-12 18:36:19 +000049 if(pass && conditional)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000050 {
51 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Appending mutating pass : " << pass->name() << std::endl);
52 _passes.push_back(std::move(pass));
53 }
54}
55
56void PassManager::clear()
57{
58 _passes.clear();
59}
60
61void PassManager::run_all(Graph &g)
62{
63 for(auto &pass : _passes)
64 {
65 if(pass)
66 {
67 ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
68 pass->mutate(g);
69 }
70 }
71}
72
Georgios Pinitasf4261ad2019-12-02 11:58:19 +000073void PassManager::run_type(Graph &g, IGraphMutator::MutationType type)
74{
75 for(auto &pass : _passes)
76 {
77 if(pass && (pass->type() == type))
78 {
79 ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
80 pass->mutate(g);
81 }
82 }
83}
84
85void PassManager::run_index(Graph &g, size_t index)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000086{
87 if(index >= _passes.size())
88 {
89 return;
90 }
91
92 auto &pass = _passes.at(index);
Georgios Pinitasd8734b52017-12-22 15:27:52 +000093 if(pass != nullptr)
94 {
Georgios Pinitasf4261ad2019-12-02 11:58:19 +000095 ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
Georgios Pinitasd8734b52017-12-22 15:27:52 +000096 pass->mutate(g);
97 }
98}
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010099} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000100} // namespace arm_compute