Skip to content

Commit f1843d0

Browse files
committed
Wire up the new epilogue retain matcher with FSO
This should have identical behavior as the old epilogue retain matcher. I do not see performance improvement. The compilation time does not show up on Instrument either.
1 parent 23f8eef commit f1843d0

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ using ArgumentIndexMap = llvm::SmallDenseMap<int, int>;
6262
// Utilities
6363
//===----------------------------------------------------------------------===//
6464

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+
6574
/// Return the single apply found in this function.
6675
static SILInstruction *findOnlyApply(SILFunction *F) {
6776
SILInstruction *OnlyApply = nullptr;
@@ -103,6 +112,9 @@ class FunctionSignatureTransform {
103112
/// The RC identity analysis we are using.
104113
RCIdentityAnalysis *RCIA;
105114

115+
/// Post order analysis we are using.
116+
PostOrderAnalysis *PO;
117+
106118
// The function signature mangler we are using.
107119
FunctionSignatureSpecializationMangler &FM;
108120

@@ -220,11 +232,12 @@ class FunctionSignatureTransform {
220232
/// Constructor.
221233
FunctionSignatureTransform(SILFunction *F,
222234
AliasAnalysis *AA, RCIdentityAnalysis *RCIA,
235+
PostOrderAnalysis *PO,
223236
FunctionSignatureSpecializationMangler &FM,
224237
ArgumentIndexMap &AIM,
225238
llvm::SmallVector<ArgumentDescriptor, 4> &ADL,
226239
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),
228241
AIM(AIM), shouldModifySelfArgument(false), ArgumentDescList(ADL),
229242
ResultDescList(RDL) {}
230243

@@ -646,10 +659,14 @@ bool FunctionSignatureTransform::OwnedToGuaranteedAnalyzeResults() {
646659

647660
bool SignatureOptimize = false;
648661
if (ResultDescList[0].hasConvention(ResultConvention::Owned)) {
662+
auto RV = findReturnValue(F);
663+
if (!RV)
664+
return false;
649665
auto &RI = ResultDescList[0];
650666
// 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));
653670
// We do not need to worry about the throw block, as the return value is only
654671
// going to be used in the return block/normal block of the try_apply
655672
// instruction.
@@ -880,6 +897,7 @@ class FunctionSignatureOpts : public SILFunctionTransform {
880897
auto *AA = PM->getAnalysis<AliasAnalysis>();
881898
auto *RCIA = getAnalysis<RCIdentityAnalysis>();
882899
CallerAnalysis *CA = PM->getAnalysis<CallerAnalysis>();
900+
auto *PO = PM->getAnalysis<PostOrderAnalysis>();
883901

884902
const CallerAnalysis::FunctionInfo &FuncInfo = CA->getCallerInfo(F);
885903

@@ -910,7 +928,7 @@ class FunctionSignatureOpts : public SILFunctionTransform {
910928
}
911929

912930
// Owned to guaranteed optimization.
913-
FunctionSignatureTransform FST(F, AA, RCIA, FM, AIM,
931+
FunctionSignatureTransform FST(F, AA, RCIA, PO, FM, AIM,
914932
ArgumentDescList, ResultDescList);
915933

916934
bool Changed = false;

0 commit comments

Comments
 (0)