2 * Copyright (c) 2021 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.
19 #include "UnusedOperandEliminationPass.h"
25 * @file UnusedOperandEliminationPass.cc
26 * @brief This file contains UnusedOperandEliminationPass class implementation
36 void UnusedOperandEliminationPass::run()
38 util::Set<ir::OperandIndex> used;
40 _graph.operations().iterate([&](const ir::OperationIndex &, const ir::IOperation &node) {
41 for (auto &&ind : (node.getInputs() + node.getOutputs()) | ir::Remove::UNDEFINED)
47 // Graph's inputs/outputs are always considered as used
48 for (auto &&ind : (_graph.getInputs() + _graph.getOutputs()) | ir::Remove::UNDEFINED)
53 _graph.operands().iterate([&](const ir::OperandIndex &ind, const ir::Operand &) {
54 if (!used.contains(ind))
56 VERBOSE() << "Remove unused operand " << ind << std::endl;
57 _graph.operands().remove(ind);
63 } // namespace compiler