2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_COMPILER_PASS_PERMUTATION_ELIMINATION_PASS_H__
18 #define __ONERT_COMPILER_PASS_PERMUTATION_ELIMINATION_PASS_H__
20 #include "ir/OperationVisitor.h"
21 #include "LoweredOperationPass.h"
31 * @brief An optimization pass that removes Permute operations if possible
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.
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 builtin backend, so the output is kept.
40 * @note This is an optimization pass which means that everything should work fine even if this pass
43 class PermutationEliminationPass : public LoweredOperationPass, public ir::OperationVisitor
46 using LoweredOperationPass::LoweredOperationPass;
49 std::string id() final { return "PermutationEliminationPass"; }
52 void callback(const ir::OperationIndex &i, ir::Operation &n) final;
55 void visit(const ir::operation::Permute &) final;
58 ir::OperationIndex _op_ind;
62 } // namespace compiler
65 #endif // __ONERT_COMPILER_PASS_PERMUTATION_ELIMINATION_PASS_H__