@@ -62,6 +62,15 @@ using ArgumentIndexMap = llvm::SmallDenseMap<int, int>;
62
62
// Utilities
63
63
// ===----------------------------------------------------------------------===//
64
64
65
+ // / Return the single return value of the function.
66
+ static SILValue findReturnValue (SILFunction *F) {
67
+ auto RBB = F->findReturnBB ();
68
+ if (RBB == F->end ())
69
+ return SILValue ();
70
+ auto Term = dyn_cast<ReturnInst>(RBB->getTerminator ());
71
+ return Term->getOperand ();
72
+ }
73
+
65
74
// / Return the single apply found in this function.
66
75
static SILInstruction *findOnlyApply (SILFunction *F) {
67
76
SILInstruction *OnlyApply = nullptr ;
@@ -103,6 +112,9 @@ class FunctionSignatureTransform {
103
112
// / The RC identity analysis we are using.
104
113
RCIdentityAnalysis *RCIA;
105
114
115
+ // / Post order analysis we are using.
116
+ PostOrderAnalysis *PO;
117
+
106
118
// The function signature mangler we are using.
107
119
FunctionSignatureSpecializationMangler &FM;
108
120
@@ -220,11 +232,12 @@ class FunctionSignatureTransform {
220
232
// / Constructor.
221
233
FunctionSignatureTransform (SILFunction *F,
222
234
AliasAnalysis *AA, RCIdentityAnalysis *RCIA,
235
+ PostOrderAnalysis *PO,
223
236
FunctionSignatureSpecializationMangler &FM,
224
237
ArgumentIndexMap &AIM,
225
238
llvm::SmallVector<ArgumentDescriptor, 4 > &ADL,
226
239
llvm::SmallVector<ResultDescriptor, 4 > &RDL)
227
- : F(F), NewF(nullptr ), AA(AA), RCIA(RCIA), FM(FM),
240
+ : F(F), NewF(nullptr ), AA(AA), RCIA(RCIA), PO(PO), FM(FM),
228
241
AIM (AIM), shouldModifySelfArgument(false ), ArgumentDescList(ADL),
229
242
ResultDescList(RDL) {}
230
243
@@ -646,10 +659,14 @@ bool FunctionSignatureTransform::OwnedToGuaranteedAnalyzeResults() {
646
659
647
660
bool SignatureOptimize = false ;
648
661
if (ResultDescList[0 ].hasConvention (ResultConvention::Owned)) {
662
+ auto RV = findReturnValue (F);
663
+ if (!RV)
664
+ return false ;
649
665
auto &RI = ResultDescList[0 ];
650
666
// We have an @owned return value, find the epilogue retains now.
651
- ConsumedResultToEpilogueRetainMatcher ReturnRetainMap (RCIA->get (F), AA, F);
652
- auto Retains = ReturnRetainMap.getEpilogueRetains ();
667
+ auto Retains =
668
+ computeEpilogueARCInstructions (EpilogueARCContext::EpilogueARCKind::Retain,
669
+ RV, F, PO->get (F), AA, RCIA->get (F));
653
670
// We do not need to worry about the throw block, as the return value is only
654
671
// going to be used in the return block/normal block of the try_apply
655
672
// instruction.
@@ -880,6 +897,7 @@ class FunctionSignatureOpts : public SILFunctionTransform {
880
897
auto *AA = PM->getAnalysis <AliasAnalysis>();
881
898
auto *RCIA = getAnalysis<RCIdentityAnalysis>();
882
899
CallerAnalysis *CA = PM->getAnalysis <CallerAnalysis>();
900
+ auto *PO = PM->getAnalysis <PostOrderAnalysis>();
883
901
884
902
const CallerAnalysis::FunctionInfo &FuncInfo = CA->getCallerInfo (F);
885
903
@@ -910,7 +928,7 @@ class FunctionSignatureOpts : public SILFunctionTransform {
910
928
}
911
929
912
930
// Owned to guaranteed optimization.
913
- FunctionSignatureTransform FST (F, AA, RCIA, FM, AIM,
931
+ FunctionSignatureTransform FST (F, AA, RCIA, PO, FM, AIM,
914
932
ArgumentDescList, ResultDescList);
915
933
916
934
bool Changed = false ;
0 commit comments