| 37 | }; |
| 38 | |
| 39 | bool DeadNodeQueryServiceImpl::isDeadNode(loco::Node *node) |
| 40 | { |
| 41 | auto g = node->graph(); |
| 42 | auto input_nodes_vec = loco::input_nodes(g); |
| 43 | auto output_nodes_vec = loco::output_nodes(g); |
| 44 | |
| 45 | auto input_nodes = std::set<loco::Node *>(input_nodes_vec.begin(), input_nodes_vec.end()); |
| 46 | auto output_nodes = std::set<loco::Node *>(output_nodes_vec.begin(), output_nodes_vec.end()); |
| 47 | auto active_nodes = loco::active_nodes(output_nodes_vec); |
| 48 | |
| 49 | if (active_nodes.find(node) != active_nodes.end()) |
| 50 | return false; |
| 51 | // input and output nodes are not dead node even if it is not active. |
| 52 | if (input_nodes.find(node) != input_nodes.end()) |
| 53 | return false; |
| 54 | |
| 55 | // if node is one of virtual mulitple outputs, we need to ask the real node |
| 56 | if (auto circle_node = dynamic_cast<luci::CircleNode *>(node)) |
| 57 | { |
| 58 | VirtualOutputDetector d; |
| 59 | if (circle_node->accept(&d)) |
| 60 | { |
| 61 | assert(node->arity() == 1); |
| 62 | loco::Node *real_node = node->arg(0); |
| 63 | if (active_nodes.find(real_node) != active_nodes.end()) |
| 64 | return false; |
| 65 | if (input_nodes.find(real_node) != input_nodes.end()) |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | } // namespace luci |