File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
include/swift/SILOptimizer/Utils Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,14 @@ class SILLoopInfo;
3838// / Compute the set of reachable blocks.
3939class ReachableBlocks {
4040 BasicBlockSet visited;
41+ bool isComputed;
4142
4243public:
43- ReachableBlocks (SILFunction *function) : visited(function) {}
44+ ReachableBlocks (SILFunction *function)
45+ : visited(function), isComputed(false ) {}
46+
47+ // / Populate `visited` with the blocks reachable in the function.
48+ void compute ();
4449
4550 // / Invoke \p visitor for each reachable block in \p f in worklist order (at
4651 // / least one predecessor has been visited--defs are always visited before
Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ bool ReachableBlocks::visit(function_ref<bool(SILBasicBlock *)> visitor) {
4141 return true ;
4242}
4343
44+ void ReachableBlocks::compute () {
45+ // Visit all the blocks without doing any extra work.
46+ visit ([](SILBasicBlock *) { return true ; });
47+ isComputed = true ;
48+ }
49+
4450ReachingReturnBlocks::ReachingReturnBlocks (SILFunction *function)
4551 : worklist(function) {
4652 for (SILBasicBlock &block : *function) {
@@ -57,8 +63,7 @@ ReachingReturnBlocks::ReachingReturnBlocks(SILFunction *function)
5763
5864bool swift::removeUnreachableBlocks (SILFunction &f) {
5965 ReachableBlocks reachable (&f);
60- // Visit all the blocks without doing any extra work.
61- reachable.visit ([](SILBasicBlock *) { return true ; });
66+ reachable.compute ();
6267
6368 // Remove the blocks we never reached. Assume the entry block is visited.
6469 // Reachable's visited set contains dangling pointers during this loop.
You can’t perform that action at this time.
0 commit comments