Compute Library
 21.11
PassManager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 Arm Limited.
3  *
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  */
25 
27 
28 namespace arm_compute
29 {
30 namespace graph
31 {
33  : _passes()
34 {
35 }
36 
37 const std::vector<std::unique_ptr<IGraphMutator>> &PassManager::passes() const
38 {
39  return _passes;
40 }
41 
43 {
44  return (index >= _passes.size()) ? nullptr : _passes.at(index).get();
45 }
46 
47 void PassManager::append(std::unique_ptr<IGraphMutator> pass, bool conditional)
48 {
49  if(pass && conditional)
50  {
51  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Appending mutating pass : " << pass->name() << std::endl);
52  _passes.push_back(std::move(pass));
53  }
54 }
55 
57 {
58  _passes.clear();
59 }
60 
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 
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 
85 void PassManager::run_index(Graph &g, size_t index)
86 {
87  if(index >= _passes.size())
88  {
89  return;
90  }
91 
92  auto &pass = _passes.at(index);
93  if(pass != nullptr)
94  {
95  ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl);
96  pass->mutate(g);
97  }
98 }
99 } // namespace graph
100 } // namespace arm_compute
IGraphMutator * pass(size_t index)
Accessor of a pass at a given index.
Definition: PassManager.cpp:42
void run_index(Graph &g, size_t index)
Runs a specific mutation pass on a given graph.
Definition: PassManager.cpp:85
decltype(strategy::transforms) typedef type
#define ARM_COMPUTE_LOG_GRAPH_INFO(x)
Definition: Logger.h:54
Copyright (c) 2017-2021 Arm Limited.
virtual void mutate(Graph &g)=0
Walk the graph and perform a specific mutation.
void clear()
Clears all the passes.
Definition: PassManager.cpp:56
virtual const char * name()=0
Returns mutator name.
void run_type(Graph &g, IGraphMutator::MutationType type)
Runs a mutation passes of a specific type on a given graph.
Definition: PassManager.cpp:73
Graph class.
Definition: Graph.h:53
void append(std::unique_ptr< IGraphMutator > pass, bool conditional=true)
Appends a mutation pass.
Definition: PassManager.cpp:47
virtual MutationType type() const =0
Returns mutation type.
const std::vector< std::unique_ptr< IGraphMutator > > & passes() const
Mutation passes accessors.
Definition: PassManager.cpp:37
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
Definition: Logger.h:50
Graph mutator interface.
Definition: IGraphMutator.h:35
void run_all(Graph &g)
Runs all the mutation passes on a given graph.
Definition: PassManager.cpp:61