Skip to content

DeadCodeElim: remove unreachable basic blocks #2597

@acl-cqc

Description

@acl-cqc

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.

Metadata

Metadata

Assignees

Labels

A-rustArea: Rust codeC-perfCategory: PR/issue with code/suggestions for performance improvements

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions