Skip to content

Commit 34c48f1

Browse files
committed
Add isNonCriticalEdge fast check for a specific edge.
1 parent 0287a3d commit 34c48f1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/swift/SILOptimizer/Utils/CFGOptUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void replaceBranchTarget(TermInst *t, SILBasicBlock *oldDest,
8383
/// Check if the edge from the terminator is critical.
8484
bool isCriticalEdge(TermInst *t, unsigned edgeIdx);
8585

86+
inline bool isNonCriticalEdge(SILBasicBlock *predBB, SILBasicBlock *succBB) {
87+
return predBB->getSingleSuccessorBlock() == succBB
88+
|| succBB->getSinglePredecessorBlock() == predBB;
89+
}
90+
8691
/// Splits the edge from terminator if it is critical.
8792
///
8893
/// Updates dominance information and loop information if not null.

lib/SILOptimizer/Utils/CFGOptUtils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,10 @@ bool swift::hasCriticalEdges(SILFunction &f, bool onlyNonCondBr) {
601601
if (isa<BranchInst>(bb.getTerminator()))
602602
continue;
603603

604-
for (unsigned idx = 0, e = bb.getSuccessors().size(); idx != e; ++idx)
605-
if (isCriticalEdge(bb.getTerminator(), idx))
604+
for (SILBasicBlock *succBB : bb.getSuccessorBlocks()) {
605+
if (!isNonCriticalEdge(&bb, succBB))
606606
return true;
607+
}
607608
}
608609
return false;
609610
}

0 commit comments

Comments
 (0)