Skip to content

Commit 242bf15

Browse files
committed
Support try_apply and yield in swift::replaceBranchTarget
1 parent 6da902e commit 242bf15

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/SILOptimizer/Utils/CFGOptUtils.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,42 @@ void swift::replaceBranchTarget(TermInst *t, SILBasicBlock *oldDest,
417417
return;
418418
}
419419

420+
case TermKind::TryApplyInst: {
421+
auto *tai = cast<TryApplyInst>(t);
422+
SILBasicBlock *normalBB =
423+
(oldDest == tai->getNormalBB() ? newDest : tai->getNormalBB());
424+
SILBasicBlock *errorBB =
425+
(oldDest == tai->getErrorBB() ? newDest : tai->getErrorBB());
426+
SmallVector<SILValue, 8> args;
427+
for (SILValue arg : tai->getArguments()) {
428+
args.push_back(arg);
429+
}
430+
builder.createTryApply( tai->getLoc(), tai->getCallee(),
431+
tai->getSubstitutionMap(), args, normalBB, errorBB,
432+
tai->getSpecializationInfo());
433+
tai->eraseFromParent();
434+
return;
435+
}
436+
437+
case TermKind::YieldInst: {
438+
auto *yi = cast<YieldInst>(t);
439+
SILBasicBlock *resumeBB =
440+
(oldDest == yi->getResumeBB() ? newDest : yi->getResumeBB());
441+
SILBasicBlock *unwindBB =
442+
(oldDest == yi->getUnwindBB() ? newDest : yi->getUnwindBB());
443+
SmallVector<SILValue, 8> args;
444+
for (SILValue arg : yi->getYieldedValues()) {
445+
args.push_back(arg);
446+
}
447+
builder.createYield(yi->getLoc(), args,resumeBB, unwindBB);
448+
yi->eraseFromParent();
449+
return;
450+
}
451+
420452
case TermKind::ReturnInst:
421453
case TermKind::ThrowInst:
422-
case TermKind::TryApplyInst:
423454
case TermKind::UnreachableInst:
424455
case TermKind::UnwindInst:
425-
case TermKind::YieldInst:
426456
llvm_unreachable(
427457
"Branch target cannot be replaced for this terminator instruction!");
428458
}

0 commit comments

Comments
 (0)