Verify reducibility of control-flow graphs. #215
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SourcePawn is a structured language, which essentially means it does not have
goto
. Having a structured language leads to a very nice control-flow property called reducibility. A reducible control-flow graph guarantees an upper limit on the number of iterations it takes for many graph algorithms to reach a fixpoint. It also means some iterative algorithms can be replaced entirely with much simpler or more efficient variants.While there are ways to make an irreducible graph reducible, there's an advantage to simply not allowing them: it verifies that the compiler is not generating unstructured control-flow. The language has no
goto
statements, so we shouldn't expect to see evidence of them in the bytecode.There are many ways to determine reducibility. The implementation here is quite simple, but requires a bunch of preceding data structures:
A dom B
relationship.A -> B
is a backwards edge (B occurs before A in RPO), then B must dominate A. If not, the graph is not reducible.I read somewhere that step 2 is enough for determining irreducibility, because the number of iterations to reach a fixpoint should be <= 2 for reducible graphs. Indeed that is true for the corpus of .smx files I downloaded. But I can't find where I read this.