mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SILOptimizer: add basic block utilities ReachingReturnBlocks and NonErrorHandlingBlocks
* ReachingReturnBlocks: computes the set of blocks from which a path to the return-block exists (does not include paths to a throw-block) * NonErrorHandlingBlocks: computes the set of blocks which are not used for error handling, i.e. not (exclusively) reachable from the error-block of a try_apply
This commit is contained in:
@@ -39,6 +39,33 @@ bool ReachableBlocks::visit(function_ref<bool(SILBasicBlock *)> visitor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ReachingReturnBlocks::ReachingReturnBlocks(SILFunction *function)
|
||||
: worklist(function) {
|
||||
for (SILBasicBlock &block : *function) {
|
||||
if (isa<ReturnInst>(block.getTerminator()))
|
||||
worklist.push(&block);
|
||||
}
|
||||
|
||||
while (SILBasicBlock *block = worklist.pop()) {
|
||||
for (SILBasicBlock *pred : block->getPredecessorBlocks()) {
|
||||
worklist.pushIfNotVisited(pred);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NonErrorHandlingBlocks::NonErrorHandlingBlocks(SILFunction *function)
|
||||
: worklist(function->getEntryBlock()) {
|
||||
while (SILBasicBlock *block = worklist.pop()) {
|
||||
if (auto ta = dyn_cast<TryApplyInst>(block->getTerminator())) {
|
||||
worklist.pushIfNotVisited(ta->getNormalBB());
|
||||
} else {
|
||||
for (SILBasicBlock *succ : block->getSuccessorBlocks()) {
|
||||
worklist.pushIfNotVisited(succ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove all instructions in the body of \p bb in safe manner by using
|
||||
/// undef.
|
||||
void swift::clearBlockBody(SILBasicBlock *bb) {
|
||||
|
||||
Reference in New Issue
Block a user