Skip to content

Commit

Permalink
fix(pass): refactor treeify pass
Browse files Browse the repository at this point in the history
This commit fixes bugs with the treeify pass that rendered it
useless on non-trivial control flow graphs. In particular, it
failed to properly handle loops, aside from some trivial cases.
An especially egregious issue, was failing to account for how
to treeify the body of a loop, while preserving control flow
along loopback edges, or edges which escape loops at a join
point (i.e. all control flow exiting a loop leaves along the
same edge).

Furthermore, it was improperly copying subgraphs during the actual
treeification process, and detaching blocks from the function when
they were still reachable along other paths. These issues were all
caused by using outdated analyses to answer questions about blocks,
while also using the real-time state of the function to answer others,
resulting in a mix of old and new information that produced incorrect
control flow graphs when nested loops were involved.

The pass has been rewritten in such a way to ensure that all of the
these issues are resolved. We now primarily rely on the real-time
state of the function for most things, but also track enough state
about changes made to the CFG, to be able to rely on the analyses
computed on the original CFG to answer questions about relationships
between blocks (since the new blocks introduced to the function by
treeification, must be at least the same as the original CFG, or
otherwise must adhere to the rules governing the output of
treeification). Additionally, we now rely on more abstract properties of
the control flow graph to determine how to apply treeification, so as to
ensure that not only loops, but other forms of interesting control flow
are handled properly. Specifically, we now only treeify blocks which are
known to have multiple predecessors that all dominate the candidate
block (or at a minimum, control flow must always flow through the
predecessor first on its way to the candidate block). This ensures that
we do not attempt to treeify a loop from within the loop, only the parts
of a loop body which remain within the loop prior to
continuation/escape.
  • Loading branch information
bitwalker committed Jun 5, 2024
1 parent 74603c3 commit 4e49eb9
Showing 1 changed file with 268 additions and 167 deletions.
Loading

0 comments on commit 4e49eb9

Please sign in to comment.