Repository navigation
fir: --apply passes for dead_elim, const_fold and dce - #1156
Merged
Merged
Conversation
fir-g now accepts --apply PASSES (dead_elim, all). The pass rewrites the FirG: unreachable functions are dropped and function, block, callee and operand metadata are remapped. Ops are bucketed by op_block during compaction because the lowerer interleaves them across blocks. Reports and --opts run on the rewritten graph and show what was removed. Towards #686.
FirG ops now carry real operand value edges, an operator code, and the literal text of CONST ops. The lowerer records them at each site, and compaction remaps operand values through the value map. --apply accepts const_fold (and all): BINOP/UNOP ops over integer and boolean literals fold to a CONST in place. The report shows the folded count next to the dead_elim result. Towards #686.
const_fold leaves folded operands stranded and expression statements produce unused results. --apply dce drops CONST/BINOP/UNOP ops whose result is never an operand, iterating to a fixpoint through a generalized op-level compaction. all now runs const_fold, dce, then dead_elim. Towards #686.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
flow fir-gcan now apply optimisation passes, not only report candidates (#686).--apply PASSEStakes a comma list from{dead_elim, const_fold, dce, all}. Reports,--optscandidates, routing and benchmarks all run on the rewritten graph.op_operand_countkeeps its declared arity so existing report counts are unchanged.dead_elimcompacts the graph to reachable functions, remapping function, block, op and value ids. Compaction buckets ops byop_blockrather than slicing: the lowerer interleaves ops across blocks, which had silently dropped theping -> pongedge of a recursive pair.const_foldrewrites BINOP/UNOP over integer and boolean literals to a CONST in place (i64 arithmetic, division by zero left alone).dcedrops pure result ops whose value is never an operand, iterated to a fixpoint through a generalised op-level compaction. It collects the CONSTs stranded by const_fold.allruns const_fold, then dce, then dead_elim.Baseline:
fir gate: 60 passedbefore this branch;68 passed, 0 failedafter, with the ten new--applycases plustests/fir/programs/fold.flow(foldable literals, a discarded expression, and a non-foldable variable operand).Not in scope: inlining and pipeline fusion. FIR-G has no variable or loop structure to splice or fuse over; that is a larger IR change than a pass.
Test plan
./flow tool tests/fir/run.flow— 68 passed, 0 failedanalysis.flow --apply dead_elimkeeps both edges of the recursiveping/pongpair and dropsdeadfold.flow --apply allfolds 4 ops, dce removes 8 stranded CONSTs--apply watand bare--applyproduce argparse-style errors with exit code 2