Skip to content

Commit 0f892b6

Browse files
authored
Merge pull request #31274 from meg-gupta/cherrypickflag
2 parents d8bd62d + 6c3857b commit 0f892b6

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

include/swift/SILOptimizer/Analysis/Analysis.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class SILAnalysis : public DeleteNotificationHandler {
137137
/// specific verification will do so.
138138
virtual void verify(SILFunction *F) const { verify(); }
139139

140+
virtual void forcePrecompute(SILFunction *F) {}
141+
140142
/// Perform a potentially more expensive verification of the state of this
141143
/// analysis.
142144
///
@@ -234,6 +236,15 @@ class FunctionAnalysisBase : public SILAnalysis {
234236
return it.second.get();
235237
}
236238

239+
virtual void forcePrecompute(SILFunction *f) override {
240+
// Check that the analysis can handle this function.
241+
verifyFunction(f);
242+
243+
auto &it = storage.FindAndConstruct(f);
244+
if (!it.second)
245+
it.second = newFunctionAnalysis(f);
246+
}
247+
237248
/// Invalidate all information in this analysis.
238249
virtual void invalidate() override {
239250
deleteAllAnalysisProviders();

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ class SILPassManager {
242242
}
243243
}
244244

245+
/// Precompute all analyses.
246+
void forcePrecomputeAnalyses(SILFunction *F) {
247+
for (auto *A : Analyses) {
248+
A->forcePrecompute(F);
249+
}
250+
}
251+
245252
/// Verify all analyses, limiting the verification to just this one function
246253
/// if possible.
247254
///

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ llvm::cl::list<std::string>
103103
llvm::cl::desc("Verify the module/analyses after we run "
104104
"a pass from this list"));
105105

106+
llvm::cl::list<std::string> SILForceVerifyAroundPass(
107+
"sil-verify-force-analysis-around-pass",
108+
llvm::cl::desc("For the given passes, precompute analyses before the pass "
109+
"and verify analyses after the pass"));
110+
106111
llvm::cl::opt<bool> SILVerifyWithoutInvalidation(
107112
"sil-verify-without-invalidation", llvm::cl::init(false),
108113
llvm::cl::desc("Verify after passes even if the pass has not invalidated"));
@@ -111,6 +116,11 @@ llvm::cl::opt<bool> SILDisableSkippingPasses(
111116
"sil-disable-skipping-passes", llvm::cl::init(false),
112117
llvm::cl::desc("Do not skip passes even if nothing was changed"));
113118

119+
llvm::cl::opt<bool> SILForceVerifyAll(
120+
"sil-verify-force-analysis", llvm::cl::init(false),
121+
llvm::cl::desc("For all passes, precompute analyses before the pass and "
122+
"verify analyses after the pass"));
123+
114124
static llvm::ManagedStatic<std::vector<unsigned>> DebugPassNumbers;
115125

116126
namespace {
@@ -421,7 +431,19 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
421431
Mod->registerDeleteNotificationHandler(SFT);
422432
if (breakBeforeRunning(F->getName(), SFT))
423433
LLVM_BUILTIN_DEBUGTRAP;
434+
if (SILForceVerifyAll ||
435+
SILForceVerifyAroundPass.end() !=
436+
std::find_if(SILForceVerifyAroundPass.begin(),
437+
SILForceVerifyAroundPass.end(), MatchFun)) {
438+
forcePrecomputeAnalyses(F);
439+
}
424440
SFT->run();
441+
if (SILForceVerifyAll ||
442+
SILForceVerifyAroundPass.end() !=
443+
std::find_if(SILForceVerifyAroundPass.begin(),
444+
SILForceVerifyAroundPass.end(), MatchFun)) {
445+
verifyAnalyses(F);
446+
}
425447
assert(analysesUnlocked() && "Expected all analyses to be unlocked!");
426448
Mod->removeDeleteNotificationHandler(SFT);
427449

test/SILOptimizer/sil_combine_concrete_existential.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -O -emit-sil -sil-verify-all -Xllvm -sil-disable-pass=function-signature-opts %s | %FileCheck %s
2+
// %target-swift-frontend -O -emit-sil -Xllvm -sil-verify-force-analysis-around-pass=devirtualizer -Xllvm -sil-disable-pass=function-signature-opts %s | %FileCheck %s
23

34
//===----------------------------------------------------------------------===//
45
// testReturnSelf: Call to a protocol extension method with

0 commit comments

Comments
 (0)