2 * Copyright (c) 2019 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 #include <logo/RemoveForwardNodePass.h>
19 #include <loco/IR/CanonicalDialect.h>
20 #include <loco/IR/CanonicalNode.h>
27 bool RemoveForwardNodePass::run(loco::Graph *g)
29 struct Collector final : public loco::CanonicalNodeMutableVisitor<void>
31 void visit(loco::Forward *node) final
33 if (node->input() != nullptr)
35 candidates.insert(node);
39 void visit(loco::Node *) final { return; }
41 std::set<loco::Forward *> candidates;
46 for (auto node : loco::all_nodes(g))
48 if (node->dialect() == loco::CanonicalDialect::get())
50 auto canonical_node = loco::must_cast<loco::CanonicalNode *>(node);
51 canonical_node->accept(&collector);
55 for (auto node : collector.candidates)
57 replace(node).with(node->input());
61 return collector.candidates.size() > 0;