[llvm] 951a980 - [Analysis] Make order of analysis executions more stable
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 17 01:33:55 PDT 2023
Author: Bjorn Pettersson
Date: 2023-03-17T09:33:16+01:00
New Revision: 951a980dc7aa61b1d414e7d565166ee8071367c6
URL: https://github.com/llvm/llvm-project/commit/951a980dc7aa61b1d414e7d565166ee8071367c6
DIFF: https://github.com/llvm/llvm-project/commit/951a980dc7aa61b1d414e7d565166ee8071367c6.diff
LOG: [Analysis] Make order of analysis executions more stable
When debugging and using debug-pass-manager (e.g. in regression tests)
we prefer a consistent order in which analysis passes are executed.
But when for example doing
return MyClass(AM.getResult<LoopAnalysis>(F),
AM.getResult<DominatorTreeAnalysis>(F));
then the order in which LoopAnalysis and DominatorTreeAnalysis isn't
guaranteed, and might for example depend on which compiler that is
used when building LLVM.
I've not scanned the full source tree, but this fixes some occurances
of the above pattern found in lib/Analysis.
This problem was discussed briefly in review for D146206.
Added:
Modified:
llvm/lib/Analysis/BlockFrequencyInfo.cpp
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/lib/Analysis/LoopAccessAnalysis.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
index dd84336da604..b18d04cc73db 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
@@ -333,9 +333,10 @@ bool BlockFrequencyInfoWrapperPass::runOnFunction(Function &F) {
AnalysisKey BlockFrequencyAnalysis::Key;
BlockFrequencyInfo BlockFrequencyAnalysis::run(Function &F,
FunctionAnalysisManager &AM) {
+ auto &BP = AM.getResult<BranchProbabilityAnalysis>(F);
+ auto &LI = AM.getResult<LoopAnalysis>(F);
BlockFrequencyInfo BFI;
- BFI.calculate(F, AM.getResult<BranchProbabilityAnalysis>(F),
- AM.getResult<LoopAnalysis>(F));
+ BFI.calculate(F, BP, LI);
return BFI;
}
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index e742416746bc..d01c652333ff 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -1303,11 +1303,12 @@ void BranchProbabilityInfoWrapperPass::print(raw_ostream &OS,
AnalysisKey BranchProbabilityAnalysis::Key;
BranchProbabilityInfo
BranchProbabilityAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
+ auto &LI = AM.getResult<LoopAnalysis>(F);
+ auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
+ auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
+ auto &PDT = AM.getResult<PostDominatorTreeAnalysis>(F);
BranchProbabilityInfo BPI;
- BPI.calculate(F, AM.getResult<LoopAnalysis>(F),
- &AM.getResult<TargetLibraryAnalysis>(F),
- &AM.getResult<DominatorTreeAnalysis>(F),
- &AM.getResult<PostDominatorTreeAnalysis>(F));
+ BPI.calculate(F, LI, &TLI, &DT, &PDT);
return BPI;
}
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index aee14edd3fd6..d8d61d61b92f 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2723,11 +2723,13 @@ bool LoopAccessInfoManager::invalidate(
}
LoopAccessInfoManager LoopAccessAnalysis::run(Function &F,
- FunctionAnalysisManager &AM) {
- return LoopAccessInfoManager(
- AM.getResult<ScalarEvolutionAnalysis>(F), AM.getResult<AAManager>(F),
- AM.getResult<DominatorTreeAnalysis>(F), AM.getResult<LoopAnalysis>(F),
- &AM.getResult<TargetLibraryAnalysis>(F));
+ FunctionAnalysisManager &FAM) {
+ auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
+ auto &AA = FAM.getResult<AAManager>(F);
+ auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
+ auto &LI = FAM.getResult<LoopAnalysis>(F);
+ auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
+ return LoopAccessInfoManager(SE, AA, DT, LI, &TLI);
}
char LoopAccessLegacyAnalysis::ID = 0;
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index cc9abcc7af96..09c64324a89c 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -14305,10 +14305,11 @@ AnalysisKey ScalarEvolutionAnalysis::Key;
ScalarEvolution ScalarEvolutionAnalysis::run(Function &F,
FunctionAnalysisManager &AM) {
- return ScalarEvolution(F, AM.getResult<TargetLibraryAnalysis>(F),
- AM.getResult<AssumptionAnalysis>(F),
- AM.getResult<DominatorTreeAnalysis>(F),
- AM.getResult<LoopAnalysis>(F));
+ auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
+ auto &AC = AM.getResult<AssumptionAnalysis>(F);
+ auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
+ auto &LI = AM.getResult<LoopAnalysis>(F);
+ return ScalarEvolution(F, TLI, AC, DT, LI);
}
PreservedAnalyses
More information about the llvm-commits
mailing list