Merge pull request #35521 from eeckstein/sil-bitfields

SIL: add a utility which can manage per-block bitfields and flags efficiently.
This commit is contained in:
eeckstein
2021-01-22 08:39:13 +01:00
committed by GitHub
15 changed files with 366 additions and 42 deletions

View File

@@ -19,13 +19,10 @@ using namespace swift;
/// Invoke \p visitor for each reachable block in \p f in worklist order (at
/// least one predecessor has been visited).
bool ReachableBlocks::visit(SILFunction *f,
function_ref<bool(SILBasicBlock *)> visitor) {
assert(visited.empty() && "blocks already visited");
bool ReachableBlocks::visit(function_ref<bool(SILBasicBlock *)> visitor) {
// Walk over the CFG, starting at the entry block, until all reachable blocks
// are visited.
SILBasicBlock *entryBB = f->getEntryBlock();
SILBasicBlock *entryBB = visited.getFunction()->getEntryBlock();
SmallVector<SILBasicBlock *, 8> worklist = {entryBB};
visited.insert(entryBB);
while (!worklist.empty()) {
@@ -34,7 +31,7 @@ bool ReachableBlocks::visit(SILFunction *f,
return false;
for (auto &succ : bb->getSuccessors()) {
if (visited.insert(succ).second)
if (visited.insert(succ))
worklist.push_back(succ);
}
}
@@ -71,9 +68,9 @@ void swift::removeDeadBlock(SILBasicBlock *bb) {
}
bool swift::removeUnreachableBlocks(SILFunction &f) {
ReachableBlocks reachable;
ReachableBlocks reachable(&f);
// Visit all the blocks without doing any extra work.
reachable.visit(&f, [](SILBasicBlock *) { return true; });
reachable.visit([](SILBasicBlock *) { return true; });
// Remove the blocks we never reached. Assume the entry block is visited.
// Reachable's visited set contains dangling pointers during this loop.