| 27 | { |
| 28 | |
| 29 | bool RemoveDeadNodeWithQueryPass::run(loco::Graph *g) |
| 30 | { |
| 31 | // Let's enumerate nodes required to compute output nodes |
| 32 | auto active_nodes = loco::active_nodes(loco::output_nodes(g)); |
| 33 | |
| 34 | // List dead(= non-active) nodes candidates |
| 35 | std::set<loco::Node *> candidates; |
| 36 | |
| 37 | for (auto node : loco::all_nodes(g)) |
| 38 | { |
| 39 | if (active_nodes.find(node) == active_nodes.end()) |
| 40 | { |
| 41 | candidates.insert(node); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Find the nodes that should not be dead node in candidates |
| 46 | for (auto it = candidates.begin(); it != candidates.end();) |
| 47 | { |
| 48 | if (auto service = (*it)->dialect()->service<DeadNodeQueryService>()) |
| 49 | { |
| 50 | if (!service->isDeadNode(*it)) |
| 51 | { |
| 52 | it = candidates.erase(it); |
| 53 | continue; |
| 54 | } |
| 55 | } |
| 56 | ++it; |
| 57 | } |
| 58 | |
| 59 | for (auto node : candidates) |
| 60 | { |
| 61 | node->drop(); |
| 62 | } |
| 63 | |
| 64 | for (auto node : candidates) |
| 65 | { |
| 66 | g->nodes()->destroy(node); |
| 67 | } |
| 68 | |
| 69 | return candidates.size() > 0; |
| 70 | } |
| 71 | |
| 72 | } // namespace logo |
nothing calls this directly
no test coverage detected