Skip to content

Commit e8c68ea

Browse files
committed
---
yaml --- r: 347739 b: refs/heads/master c: 34d5f41 h: refs/heads/master i: 347737: f86d4b9 347735: b988573
1 parent 08dde84 commit e8c68ea

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e61525b38c9ad06de1ab7875b65f05b92d8466ff
2+
refs/heads/master: 34d5f41e9085a69382c421ac4d124dbc31cd9428
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/SILOptimizer/Utils/CFG.cpp

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -640,46 +640,29 @@ bool swift::splitAllCondBrCriticalEdgesWithNonTrivialArgs(SILFunction &Fn,
640640
return true;
641641
}
642642

643-
namespace {
644-
class RemoveUnreachable {
645-
SILFunction &Fn;
646-
llvm::SmallSet<SILBasicBlock *, 8> Visited;
647-
public:
648-
RemoveUnreachable(SILFunction &Fn) : Fn(Fn) { }
649-
void visit(SILBasicBlock *BB);
650-
bool run();
651-
};
652-
} // end anonymous namespace
653-
654-
void RemoveUnreachable::visit(SILBasicBlock *BB) {
655-
if (!Visited.insert(BB).second)
656-
return;
643+
bool swift::removeUnreachableBlocks(SILFunction &Fn) {
644+
// All reachable blocks, but does not include the entry block.
645+
llvm::SmallPtrSet<SILBasicBlock *, 8> Visited;
657646

658-
for (auto &Succ : BB->getSuccessors())
659-
visit(Succ);
660-
}
647+
// Walk over the CFG, starting at the entry block, until all reachable blocks are visited.
648+
llvm::SmallVector<SILBasicBlock *, 8> Worklist(1, Fn.getEntryBlock());
649+
while (!Worklist.empty()) {
650+
SILBasicBlock *BB = Worklist.pop_back_val();
651+
for (auto &Succ : BB->getSuccessors()) {
652+
if (Visited.insert(Succ).second)
653+
Worklist.push_back(Succ);
654+
}
655+
}
661656

662-
bool RemoveUnreachable::run() {
657+
// Remove the blocks we never reached. Exclude the entry block from the iteration because it's
658+
// not included in the Visited set.
663659
bool Changed = false;
664-
665-
// Clear each time we run so that we can run multiple times.
666-
Visited.clear();
667-
668-
// Visit all blocks reachable from the entry block of the function.
669-
visit(&*Fn.begin());
670-
671-
// Remove the blocks we never reached.
672-
for (auto It = Fn.begin(), End = Fn.end(); It != End; ) {
660+
for (auto It = std::next(Fn.begin()), End = Fn.end(); It != End; ) {
673661
auto *BB = &*It++;
674662
if (!Visited.count(BB)) {
675663
removeDeadBlock(BB);
676664
Changed = true;
677665
}
678666
}
679-
680667
return Changed;
681668
}
682-
683-
bool swift::removeUnreachableBlocks(SILFunction &Fn) {
684-
return RemoveUnreachable(Fn).run();
685-
}

0 commit comments

Comments
 (0)