@@ -5201,37 +5201,30 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
5201
5201
5202
5202
void verifyBranches (const SILFunction *F) {
5203
5203
// Verify no critical edge.
5204
- auto isCriticalEdgePred = [](const TermInst *T, unsigned EdgeIdx) {
5205
- assert (T->getSuccessors ().size () > EdgeIdx && " Not enough successors" );
5206
-
5204
+ auto requireNonCriticalSucc = [this ](const TermInst *termInst,
5205
+ const Twine &message) {
5207
5206
// A critical edge has more than one outgoing edges from the source
5208
5207
// block.
5209
- auto SrcSuccs = T->getSuccessors ();
5210
- if (SrcSuccs.size () <= 1 )
5211
- return false ;
5212
-
5213
- // And its destination block has more than one predecessor.
5214
- SILBasicBlock *DestBB = SrcSuccs[EdgeIdx];
5215
- assert (!DestBB->pred_empty () && " There should be a predecessor" );
5216
- if (DestBB->getSinglePredecessorBlock ())
5217
- return false ;
5208
+ auto succBlocks = termInst->getSuccessorBlocks ();
5209
+ if (succBlocks.size () <= 1 )
5210
+ return ;
5218
5211
5219
- return true ;
5212
+ for (const SILBasicBlock *destBB : succBlocks) {
5213
+ // And its destination block has more than one predecessor.
5214
+ _require (destBB->getSinglePredecessorBlock (), message);
5215
+ }
5220
5216
};
5221
5217
5222
- for (auto &BB : *F) {
5223
- const TermInst *TI = BB .getTerminator ();
5224
- CurInstruction = TI ;
5218
+ for (auto &bb : *F) {
5219
+ const TermInst *termInst = bb .getTerminator ();
5220
+ CurInstruction = termInst ;
5225
5221
5226
- // FIXME: In OSSA, critical edges will never be allowed.
5227
- // In Lowered SIL, they are allowed on unconditional branches only.
5228
- // if (!(isSILOwnershipEnabled() && F->hasOwnership()))
5229
- if (AllowCriticalEdges && isa<CondBranchInst>(TI))
5230
- continue ;
5231
-
5232
- for (unsigned Idx = 0 , e = BB.getSuccessors ().size (); Idx != e; ++Idx) {
5233
- require (!isCriticalEdgePred (TI, Idx),
5234
- " non cond_br critical edges not allowed" );
5222
+ if (isSILOwnershipEnabled () && F->hasOwnership ()) {
5223
+ requireNonCriticalSucc (termInst, " critical edges not allowed in OSSA" );
5224
+ }
5225
+ // In Lowered SIL, they are allowed on conditional branches only.
5226
+ if (!AllowCriticalEdges && !isa<CondBranchInst>(termInst)) {
5227
+ requireNonCriticalSucc (termInst, " only cond_br critical edges allowed" );
5235
5228
}
5236
5229
}
5237
5230
}
0 commit comments