Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / ir / pass / PermutationEliminationPass.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __ONERT_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__
18 #define __ONERT_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__
19
20 #include "ir/OperationVisitor.h"
21 #include "LoweredOperationPass.h"
22
23 namespace onert
24 {
25 namespace ir
26 {
27 namespace pass
28 {
29
30 /**
31  * @brief An optimization pass that removes Permute operations if possible
32  *
33  * There may be some Permute operations that are inserted by PermutationInsertionPass or other
34  * passes. This pass checks all Permute operations and eliminates them if Permute in/out tensors
35  * are compatible and layouts match.
36  *
37  * Permute input tensor is kept and the output is removed for all the cases, except model outputs.
38  * As all output tensors have to be controlflow backend, so the output is kept.
39  *
40  * @note This is an optimization pass which means that everything should work fine even if this pass
41  *       was skipped.
42  */
43 class PermutationEliminationPass : public LoweredOperationPass, public OperationVisitor
44 {
45 public:
46   using LoweredOperationPass::LoweredOperationPass;
47
48 public:
49   std::string id() final { return "PermutationEliminationPass"; }
50
51 public:
52   void callback(const OperationIndex &i, Operation &n) final;
53
54 private:
55   void visit(const operation::Permute &) final;
56
57 private:
58   ir::OperationIndex _op_ind;
59 };
60
61 } // namespace pass
62 } // namespace ir
63 } // namespace onert
64
65 #endif // __ONERT_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__