From 7fdf92a1f10c8a92fe5d4b53cbdd710f3d8edec7 Mon Sep 17 00:00:00 2001 From: Mark Lacey Date: Mon, 9 Nov 2015 10:08:01 -0800 Subject: [PATCH] Invalidate the call graph at the end of several passes. Without further changes to maintain the call graph, these passes all break the call graph once it tracks potential calls to deinits (e.g. from strong_release, etc.). I measure approximately 1.3% increase in stdlib build time with this change. The compile-time cost of this change will be reduced with forthcoming changes to allow invalidating only the portion of the call graph for a single function. --- lib/SILPasses/ARC/ARCSequenceOpts.cpp | 2 +- lib/SILPasses/COWArrayOpt.cpp | 2 -- lib/SILPasses/ClosureSpecializer.cpp | 2 -- lib/SILPasses/CopyForwarding.cpp | 9 ++++----- lib/SILPasses/DeadObjectElimination.cpp | 2 +- lib/SILPasses/GlobalOpt.cpp | 4 ---- lib/SILPasses/SILCombiner/SILCombine.cpp | 9 +-------- lib/SILPasses/SILLowerAggregateInstrs.cpp | 2 +- 8 files changed, 8 insertions(+), 24 deletions(-) diff --git a/lib/SILPasses/ARC/ARCSequenceOpts.cpp b/lib/SILPasses/ARC/ARCSequenceOpts.cpp index d5f36b55afc82..81d5dadcaeed7 100644 --- a/lib/SILPasses/ARC/ARCSequenceOpts.cpp +++ b/lib/SILPasses/ARC/ARCSequenceOpts.cpp @@ -259,7 +259,7 @@ class ARCSequenceOpts : public SILFunctionTransform { if (processFunction(*getFunction(), false, AA, POTA, LRFI, LI, RCFI)) { processFunction(*getFunction(), true, AA, POTA, LRFI, LI, RCFI); - invalidateAnalysis(SILAnalysis::PreserveKind::ProgramFlow); + invalidateAnalysis(SILAnalysis::PreserveKind::Branches); } } diff --git a/lib/SILPasses/COWArrayOpt.cpp b/lib/SILPasses/COWArrayOpt.cpp index 9ec2e7f141f6e..501ae5022c0af 100644 --- a/lib/SILPasses/COWArrayOpt.cpp +++ b/lib/SILPasses/COWArrayOpt.cpp @@ -2352,9 +2352,7 @@ class SwiftArrayOptPass : public SILFunctionTransform { // We preserve the dominator tree and call graph. Let's // invalidate everything else. DA->lockInvalidation(); - CGA->lockInvalidation(); invalidateAnalysis(SILAnalysis::PreserveKind::Nothing); - CGA->unlockInvalidation(); DA->unlockInvalidation(); } } diff --git a/lib/SILPasses/ClosureSpecializer.cpp b/lib/SILPasses/ClosureSpecializer.cpp index 9b1a797902eb4..75500529ee430 100644 --- a/lib/SILPasses/ClosureSpecializer.cpp +++ b/lib/SILPasses/ClosureSpecializer.cpp @@ -877,9 +877,7 @@ class SILClosureSpecializerTransform : public SILModuleTransform { // We maintain the call graph, but delete calls, and introduce new // calls and branches in the cloned functions. if (Changed) { - CGA->lockInvalidation(); invalidateAnalysis(SILAnalysis::PreserveKind::Nothing); - CGA->unlockInvalidation(); } // If for testing purposes we were asked to not eliminate dead closures, diff --git a/lib/SILPasses/CopyForwarding.cpp b/lib/SILPasses/CopyForwarding.cpp index 8b27e998dd5ff..4ef86cad2349f 100644 --- a/lib/SILPasses/CopyForwarding.cpp +++ b/lib/SILPasses/CopyForwarding.cpp @@ -1064,7 +1064,7 @@ class CopyForwardingPass : public SILFunctionTransform // Perform NRVO for (auto Copy : NRVOCopies) { performNRVO(Copy); - invalidateAnalysis(SILAnalysis::PreserveKind::ProgramFlow); + invalidateAnalysis(SILAnalysis::PreserveKind::Branches); } // Perform Copy Forwarding. @@ -1088,11 +1088,10 @@ class CopyForwardingPass : public SILFunctionTransform } while (Forwarding.hasForwardedToCopy()); } if (Forwarding.hasChangedCFG()) - // We've split critical edges so we can't preserve CFG, but we did not - // change calls so we can preserve them. - invalidateAnalysis(SILAnalysis::PreserveKind::Calls); + // We've split critical edges so we can't preserve CFG. + invalidateAnalysis(SILAnalysis::PreserveKind::Nothing); else - invalidateAnalysis(SILAnalysis::PreserveKind::ProgramFlow); + invalidateAnalysis(SILAnalysis::PreserveKind::Branches); } StringRef getName() override { return "Copy Forwarding"; } diff --git a/lib/SILPasses/DeadObjectElimination.cpp b/lib/SILPasses/DeadObjectElimination.cpp index 7770f5accbcca..94d24b0f3b05d 100644 --- a/lib/SILPasses/DeadObjectElimination.cpp +++ b/lib/SILPasses/DeadObjectElimination.cpp @@ -703,7 +703,7 @@ class DeadObjectElimination : public SILFunctionTransform { CG = CGA->getCallGraphOrNull(); if (processFunction(*getFunction())) - invalidateAnalysis(SILAnalysis::PreserveKind::ProgramFlow); + invalidateAnalysis(SILAnalysis::PreserveKind::Branches); } StringRef getName() override { return "Dead Object Elimination"; } diff --git a/lib/SILPasses/GlobalOpt.cpp b/lib/SILPasses/GlobalOpt.cpp index 31c4ddd92cd61..18fb016df5353 100644 --- a/lib/SILPasses/GlobalOpt.cpp +++ b/lib/SILPasses/GlobalOpt.cpp @@ -914,11 +914,7 @@ class SILGlobalOptPass : public SILModuleTransform auto *CGA = PM->getAnalysis(); if (SILGlobalOpt(getModule(), DA, CGA->getCallGraphOrNull()).run()) { // Preserve the CallGraph analysis. - if (CGA) - CGA->lockInvalidation(); invalidateAnalysis(SILAnalysis::PreserveKind::Nothing); - if (CGA) - CGA->unlockInvalidation(); } } diff --git a/lib/SILPasses/SILCombiner/SILCombine.cpp b/lib/SILPasses/SILCombiner/SILCombine.cpp index 322381480b437..0232c57bf01fd 100644 --- a/lib/SILPasses/SILCombiner/SILCombine.cpp +++ b/lib/SILPasses/SILCombiner/SILCombine.cpp @@ -361,15 +361,8 @@ class SILCombine : public SILFunctionTransform { bool Changed = Combiner.runOnFunction(*getFunction()); if (Changed) { - // Ignore invalidation messages for all analyses that we keep up to date - // manually. - CGA->lockInvalidation(); - - // Invalidate everything else. + // Invalidate everything. invalidateAnalysis(SILAnalysis::PreserveKind::Nothing); - - // Unlock all of the analyses that we locked. - CGA->unlockInvalidation(); } } diff --git a/lib/SILPasses/SILLowerAggregateInstrs.cpp b/lib/SILPasses/SILLowerAggregateInstrs.cpp index 8702289ea9265..7975abc17395b 100644 --- a/lib/SILPasses/SILLowerAggregateInstrs.cpp +++ b/lib/SILPasses/SILLowerAggregateInstrs.cpp @@ -261,7 +261,7 @@ class SILLowerAggregate : public SILFunctionTransform { F->getName() << " *****\n"); bool Changed = processFunction(*F); if (Changed) - invalidateAnalysis(SILAnalysis::PreserveKind::ProgramFlow); + invalidateAnalysis(SILAnalysis::PreserveKind::Branches); } StringRef getName() override { return "Lower Aggregate Instructions"; }