@@ -784,7 +784,7 @@ void ClosureSpecCloner::populateCloned() {
784
784
namespace {
785
785
786
786
class SILClosureSpecializerTransform : public SILFunctionTransform {
787
- void gatherCallSites (SILFunction *Caller,
787
+ bool gatherCallSites (SILFunction *Caller,
788
788
llvm::SmallVectorImpl<ClosureInfo*> &ClosureCandidates,
789
789
llvm::DenseSet<FullApplySite> &MultipleClosureAI);
790
790
bool specialize (SILFunction *Caller,
@@ -839,7 +839,7 @@ void SILClosureSpecializerTransform::run() {
839
839
invalidateAnalysis (SILAnalysis::InvalidationKind::Everything);
840
840
}
841
841
842
- void SILClosureSpecializerTransform::gatherCallSites (
842
+ bool SILClosureSpecializerTransform::gatherCallSites (
843
843
SILFunction *Caller,
844
844
llvm::SmallVectorImpl<ClosureInfo*> &ClosureCandidates,
845
845
llvm::DenseSet<FullApplySite> &MultipleClosureAI) {
@@ -848,6 +848,8 @@ void SILClosureSpecializerTransform::gatherCallSites(
848
848
// make sure that we do not handle call sites with multiple closure arguments.
849
849
llvm::DenseSet<FullApplySite> VisitedAI;
850
850
851
+ bool CFGChanged = false ;
852
+
851
853
// For each basic block BB in Caller...
852
854
for (auto &BB : *Caller) {
853
855
@@ -918,7 +920,7 @@ void SILClosureSpecializerTransform::gatherCallSites(
918
920
// We could fix this by inserting new arguments more carefully, or
919
921
// changing how we model dynamic Self altogether.
920
922
if (mayBindDynamicSelf (ApplyCallee))
921
- return ;
923
+ return CFGChanged ;
922
924
923
925
// Ok, we know that we can perform the optimization but not whether or
924
926
// not the optimization is profitable. Find the index of the argument
@@ -991,12 +993,15 @@ void SILClosureSpecializerTransform::gatherCallSites(
991
993
}
992
994
if (CInfo) {
993
995
ValueLifetimeAnalysis VLA (CInfo->Closure , UsePoints);
994
- VLA.computeFrontier (CInfo->LifetimeFrontier ,
995
- ValueLifetimeAnalysis::AllowToModifyCFG);
996
+ if (!VLA.computeFrontier (CInfo->LifetimeFrontier ,
997
+ ValueLifetimeAnalysis::AllowToModifyCFG)) {
998
+ CFGChanged = true ;
999
+ }
996
1000
ClosureCandidates.push_back (CInfo);
997
1001
}
998
1002
}
999
1003
}
1004
+ return CFGChanged;
1000
1005
}
1001
1006
1002
1007
bool SILClosureSpecializerTransform::specialize (SILFunction *Caller,
@@ -1008,7 +1013,9 @@ bool SILClosureSpecializerTransform::specialize(SILFunction *Caller,
1008
1013
// ApplyInsts. Check the profitability of specializing the closure argument.
1009
1014
llvm::SmallVector<ClosureInfo*, 8 > ClosureCandidates;
1010
1015
llvm::DenseSet<FullApplySite> MultipleClosureAI;
1011
- gatherCallSites (Caller, ClosureCandidates, MultipleClosureAI);
1016
+ if (gatherCallSites (Caller, ClosureCandidates, MultipleClosureAI)) {
1017
+ invalidateAnalysis (SILAnalysis::InvalidationKind::Branches);
1018
+ }
1012
1019
1013
1020
bool Changed = false ;
1014
1021
for (auto *CInfo : ClosureCandidates) {
0 commit comments