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;
38
38
// / Compute the set of reachable blocks.
39
39
class ReachableBlocks {
40
40
BasicBlockSet visited;
41
+ bool isComputed;
41
42
42
43
public:
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 ();
44
49
45
50
// / Invoke \p visitor for each reachable block in \p f in worklist order (at
46
51
// / 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) {
41
41
return true ;
42
42
}
43
43
44
+ void ReachableBlocks::compute () {
45
+ // Visit all the blocks without doing any extra work.
46
+ visit ([](SILBasicBlock *) { return true ; });
47
+ isComputed = true ;
48
+ }
49
+
44
50
ReachingReturnBlocks::ReachingReturnBlocks (SILFunction *function)
45
51
: worklist(function) {
46
52
for (SILBasicBlock &block : *function) {
@@ -57,8 +63,7 @@ ReachingReturnBlocks::ReachingReturnBlocks(SILFunction *function)
57
63
58
64
bool swift::removeUnreachableBlocks (SILFunction &f) {
59
65
ReachableBlocks reachable (&f);
60
- // Visit all the blocks without doing any extra work.
61
- reachable.visit ([](SILBasicBlock *) { return true ; });
66
+ reachable.compute ();
62
67
63
68
// Remove the blocks we never reached. Assume the entry block is visited.
64
69
// Reachable's visited set contains dangling pointers during this loop.
You can’t perform that action at this time.
0 commit comments