@@ -681,6 +681,25 @@ void SILBuilder::emitScopedBorrowOperation(SILLocation loc, SILValue original,
681681 createEndBorrow (loc, value);
682682}
683683
684+ SILPhiArgument *SILBuilder::createSwitchOptional (
685+ SILLocation loc, SILValue operand,
686+ SILBasicBlock *someBB, SILBasicBlock *noneBB,
687+ ValueOwnershipKind forwardingOwnershipKind,
688+ ProfileCounter someCount,
689+ ProfileCounter noneCount) {
690+ ProfileCounter counts[] = {someCount, noneCount};
691+ std::optional<ArrayRef<ProfileCounter>> countsArg = std::nullopt ;
692+ if (someCount || noneCount) countsArg = counts;
693+
694+ auto &ctx = getASTContext ();
695+ auto sei = createSwitchEnum (loc, operand, /* default*/ nullptr ,
696+ {{ctx.getOptionalSomeDecl (), someBB},
697+ {ctx.getOptionalNoneDecl (), noneBB}},
698+ countsArg, /* default*/ ProfileCounter (),
699+ forwardingOwnershipKind);
700+ return sei->createResult (someBB, operand->getType ().unwrapOptionalType ());
701+ }
702+
684703// / Attempt to propagate ownership from \p operand to the returned forwarding
685704// / ownership where the forwarded value has type \p targetType. If this fails,
686705// / return Owned forwarding ownership instead.
0 commit comments