Skip to content

Commit 058f9c4

Browse files
committed
[NFC] ReachableBlocks: Extract compute method.
In preparation for adding more users.
1 parent 1dde278 commit 058f9c4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/swift/SILOptimizer/Utils/BasicBlockOptUtils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ class SILLoopInfo;
3838
/// Compute the set of reachable blocks.
3939
class ReachableBlocks {
4040
BasicBlockSet visited;
41+
bool isComputed;
4142

4243
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();
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

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
4450
ReachingReturnBlocks::ReachingReturnBlocks(SILFunction *function)
4551
: worklist(function) {
4652
for (SILBasicBlock &block : *function) {
@@ -57,8 +63,7 @@ ReachingReturnBlocks::ReachingReturnBlocks(SILFunction *function)
5763

5864
bool 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.

0 commit comments

Comments
 (0)