-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Currently DeadCodeElimPass assumes all basic blocks in a CFG are reachable: https://github.com/CQCL/hugr/blob/d4242b60376d65babbd7f9b66ac6b8e8bef9e79b/hugr-passes/src/dead_code.rs#L127
It's actually straightforward to detect+remove blocks that are unreachable in a graph-theoretic sense (perhaps we got confused with actually reachable according to the possible runtime tags of predicates?). Just mark only Entry+Exit as reachable when we see a CFG; and when we see a DataflowBlock, mark it's successors (output_neighbours) as reachable, rather than input_neighbours as currently (appropriate for a dataflow node): https://github.com/CQCL/hugr/blob/d4242b60376d65babbd7f9b66ac6b8e8bef9e79b/hugr-passes/src/dead_code.rs#L139-L140
btw, while in the area, consider renaming DCE "entry points" to "starting points" or "force live" / etc.