From e648c53c5c7c68caeea1a154ef6335350ce75a4b Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 23 Feb 2016 10:47:57 +0000 Subject: [PATCH] [PM] Remove an overly aggressive assert now that I can actually test the pattern that triggers it. This essentially requires an immutable function analysis, as that will survive anything we do to invalidate it. When we have such patterns, the function analysis manager will not get cleared between runs of the proxy. If we actually need an assert about how things are queried, we can add more elaborate machinery for computing it, but so far I'm not aware of significant value provided. Thanks to Justin Lebar for noticing this when he made a (seemingly innocuous) change to FunctionAttrs that is enough to trigger it in one test there. Now it is covered by a direct test of the pass manager code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261627 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CGSCCPassManager.cpp | 1 - unittests/Analysis/CGSCCPassManagerTest.cpp | 32 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/CGSCCPassManager.cpp b/lib/Analysis/CGSCCPassManager.cpp index 9cceed4ba87..efffc8e4eba 100644 --- a/lib/Analysis/CGSCCPassManager.cpp +++ b/lib/Analysis/CGSCCPassManager.cpp @@ -50,7 +50,6 @@ char FunctionAnalysisManagerCGSCCProxy::PassID; FunctionAnalysisManagerCGSCCProxy::Result FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C) { - assert(FAM->empty() && "Function analyses ran prior to the CGSCC proxy!"); return Result(*FAM); } diff --git a/unittests/Analysis/CGSCCPassManagerTest.cpp b/unittests/Analysis/CGSCCPassManagerTest.cpp index 49611d6dd3d..8d219e29844 100644 --- a/unittests/Analysis/CGSCCPassManagerTest.cpp +++ b/unittests/Analysis/CGSCCPassManagerTest.cpp @@ -102,6 +102,30 @@ private: char TestFunctionAnalysis::PassID; +class TestImmutableFunctionAnalysis { +public: + struct Result { + bool invalidate(Function &, const PreservedAnalyses &) { return false; } + }; + + static void *ID() { return (void *)&PassID; } + static StringRef name() { return "TestImmutableFunctionAnalysis"; } + + TestImmutableFunctionAnalysis(int &Runs) : Runs(Runs) {} + + Result run(Function &F, FunctionAnalysisManager *AM) { + ++Runs; + return Result(); + } + +private: + static char PassID; + + int &Runs; +}; + +char TestImmutableFunctionAnalysis::PassID; + struct TestModulePass { TestModulePass(int &RunCount) : RunCount(RunCount) {} @@ -155,6 +179,9 @@ struct TestSCCPass { TestFunctionAnalysis::Result &FAR = FAM.getResult(N.getFunction()); AnalyzedInstrCount += FAR.InstructionCount; + + // Just ensure we get the immutable results. + (void)FAM.getResult(N.getFunction()); } } @@ -234,6 +261,10 @@ TEST_F(CGSCCPassManagerTest, Basic) { FunctionAnalysisManager FAM(/*DebugLogging*/ true); int FunctionAnalysisRuns = 0; FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); }); + int ImmutableFunctionAnalysisRuns = 0; + FAM.registerPass([&] { + return TestImmutableFunctionAnalysis(ImmutableFunctionAnalysisRuns); + }); CGSCCAnalysisManager CGAM(/*DebugLogging*/ true); int SCCAnalysisRuns = 0; @@ -277,6 +308,7 @@ TEST_F(CGSCCPassManagerTest, Basic) { EXPECT_EQ(1, ModuleAnalysisRuns); EXPECT_EQ(4, SCCAnalysisRuns); EXPECT_EQ(6, FunctionAnalysisRuns); + EXPECT_EQ(6, ImmutableFunctionAnalysisRuns); EXPECT_EQ(4, SCCPassRunCount1); EXPECT_EQ(14, AnalyzedInstrCount1);