Skip to content

Commit 3ee8265

Browse files
committed
Make dependency between certain analysis passes transitive (reapply)
LazyBlockFrequenceInfoPass, LazyBranchProbabilityInfoPass and LoopAccessLegacyAnalysis all cache pointers to their nestled required analysis passes. One need to use addRequiredTransitive to describe that the nestled passes can't be freed until those analysis passes no longer are used themselves. There is still a bit of a mess considering the getLazyBPIAnalysisUsage and getLazyBFIAnalysisUsage functions. Those functions are used from both Transform, CodeGen and Analysis passes. I figure it is OK to use addRequiredTransitive also when being used from Transform and CodeGen passes. On the other hand, I figure we must do it when used from other Analysis passes. So using addRequiredTransitive should be more correct here. An alternative solution would be to add a bool option in those functions to let the user tell if it is a analysis pass or not. Since those lazy passes will be obsolete when new PM has conquered the world I figure we can leave it like this right now. Intention with the patch is to fix PR49950. It at least solves the problem for the reproducer in PR49950. However, that reproducer need five passes in a specific order, so there are lots of various "solutions" that could avoid the crash without actually fixing the root cause. This is a reapply of commit 3655f07, that was reverted in 33ff3c2 due to problems with assertions in the polly lit tests. That problem is supposed to be solved by also adjusting ScopPass to explicitly preserve LazyBlockFrequencyInfo and LazyBranchProbabilityInfo (it already preserved OptimizationRemarkEmitter which depends on those lazy passes). Differential Revision: https://reviews.llvm.org/D100958
1 parent 85460a2 commit 3ee8265

File tree

5 files changed

+97
-15
lines changed

5 files changed

+97
-15
lines changed

llvm/lib/Analysis/LazyBlockFrequencyInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
4545
// We require DT so it's available when LI is available. The LI updating code
4646
// asserts that DT is also present so if we don't make sure that we have DT
4747
// here, that assert will trigger.
48-
AU.addRequired<DominatorTreeWrapperPass>();
49-
AU.addRequired<LoopInfoWrapperPass>();
48+
AU.addRequiredTransitive<DominatorTreeWrapperPass>();
49+
AU.addRequiredTransitive<LoopInfoWrapperPass>();
5050
AU.setPreservesAll();
5151
}
5252

@@ -61,8 +61,8 @@ bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
6161

6262
void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
6363
LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
64-
AU.addRequired<LazyBlockFrequencyInfoPass>();
65-
AU.addRequired<LoopInfoWrapperPass>();
64+
AU.addRequiredTransitive<LazyBlockFrequencyInfoPass>();
65+
AU.addRequiredTransitive<LoopInfoWrapperPass>();
6666
}
6767

6868
void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {

llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
4646
// We require DT so it's available when LI is available. The LI updating code
4747
// asserts that DT is also present so if we don't make sure that we have DT
4848
// here, that assert will trigger.
49-
AU.addRequired<DominatorTreeWrapperPass>();
50-
AU.addRequired<LoopInfoWrapperPass>();
51-
AU.addRequired<TargetLibraryInfoWrapperPass>();
49+
AU.addRequiredTransitive<DominatorTreeWrapperPass>();
50+
AU.addRequiredTransitive<LoopInfoWrapperPass>();
51+
AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
5252
AU.setPreservesAll();
5353
}
5454

@@ -63,9 +63,9 @@ bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
6363
}
6464

6565
void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
66-
AU.addRequired<LazyBranchProbabilityInfoPass>();
67-
AU.addRequired<LoopInfoWrapperPass>();
68-
AU.addRequired<TargetLibraryInfoWrapperPass>();
66+
AU.addRequiredTransitive<LazyBranchProbabilityInfoPass>();
67+
AU.addRequiredTransitive<LoopInfoWrapperPass>();
68+
AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
6969
}
7070

7171
void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,12 +2281,12 @@ bool LoopAccessLegacyAnalysis::runOnFunction(Function &F) {
22812281
}
22822282

22832283
void LoopAccessLegacyAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
2284-
AU.addRequired<ScalarEvolutionWrapperPass>();
2285-
AU.addRequired<AAResultsWrapperPass>();
2286-
AU.addRequired<DominatorTreeWrapperPass>();
2287-
AU.addRequired<LoopInfoWrapperPass>();
2284+
AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
2285+
AU.addRequiredTransitive<AAResultsWrapperPass>();
2286+
AU.addRequiredTransitive<DominatorTreeWrapperPass>();
2287+
AU.addRequiredTransitive<LoopInfoWrapperPass>();
22882288

2289-
AU.setPreservesAll();
2289+
AU.setPreservesAll();
22902290
}
22912291

22922292
char LoopAccessLegacyAnalysis::ID = 0;

llvm/test/Other/pr49950.ll

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
; RUN: opt < %s -o /dev/null -enable-new-pm=0 -block-freq -opt-remark-emitter -memoryssa -inject-tli-mappings -pgo-memop-opt -verify-loop-info -debug-pass=Details 2>&1 | FileCheck %s
2+
3+
; REQUIRES: asserts
4+
5+
; This is a heavily reduced reproducer for the problem found in
6+
; https://bugs.llvm.org/show_bug.cgi?id=49950 when doing fuzzy
7+
; testing (including non-standard pipelines).
8+
;
9+
; The problem manifested as having a pass structure like this
10+
; when it failed (as given by using -debug-pass=Details):
11+
;
12+
; Target Library Information
13+
; Target Transform Information
14+
; Profile summary info
15+
; Assumption Cache Tracker
16+
; ModulePass Manager
17+
; FunctionPass Manager
18+
; Dominator Tree Construction
19+
; Natural Loop Information
20+
; Post-Dominator Tree Construction
21+
; Branch Probability Analysis
22+
; Block Frequency Analysis
23+
; -- Branch Probability Analysis
24+
; Lazy Branch Probability Analysis
25+
; Lazy Block Frequency Analysis
26+
; Optimization Remark Emitter
27+
; Basic Alias Analysis (stateless AA impl)
28+
; Function Alias Analysis Results
29+
; Memory SSA
30+
; -- Dominator Tree Construction
31+
; -- Function Alias Analysis Results
32+
; -- Basic Alias Analysis (stateless AA impl)
33+
; -- Memory SSA
34+
; Inject TLI Mappings
35+
; -- Inject TLI Mappings
36+
; PGOMemOPSize
37+
; -- Block Frequency Analysis
38+
; -- Post-Dominator Tree Construction
39+
; -- Optimization Remark Emitter
40+
; -- Lazy Branch Probability Analysis
41+
; -- Natural Loop Information
42+
; -- Lazy Block Frequency Analysis
43+
; -- PGOMemOPSize
44+
; Module Verifier
45+
; -- Module Verifier
46+
; -- Target Library Information
47+
; -- Profile summary info
48+
; -- Assumption Cache Tracker
49+
; Bitcode Writer
50+
; -- Bitcode Writer
51+
;
52+
; One might notice that "Dominator Tree Construction" is dropped after
53+
; "Memory SSA", while for example "Natural Loop Information" stick around
54+
; a bit longer. This despite "Dominator Tree Construction" being transitively
55+
; required by "Natural Loop Information".
56+
; The end result was that we got crashes when doing verification of loop
57+
; info after "Inject TLI Mappings" (since the dominator tree had been
58+
; removed too early).
59+
60+
; Verify that both domintator tree and loop info are kept until after
61+
; PGOMemOPSize:
62+
;
63+
; CHECK: Dominator Tree Construction
64+
; CHECK-NOT: -- Dominator Tree Construction
65+
; CHECK: Memory SSA
66+
; CHECK-NOT: -- Dominator Tree Construction
67+
; CHECK: Inject TLI Mappings
68+
; CHECK-NOT: -- Dominator Tree Construction
69+
; CHECK: PGOMemOPSize
70+
; CHECK-DAG: -- Dominator Tree Construction
71+
; CHECK-DAG: -- Natural Loop Information
72+
; CHECK-DAG: -- PGOMemOPSize
73+
; CHECK: Bitcode Writer
74+
75+
define void @foo() {
76+
entry:
77+
ret void
78+
}

polly/lib/Analysis/ScopPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "polly/ScopInfo.h"
1515
#include "llvm/Analysis/BasicAliasAnalysis.h"
1616
#include "llvm/Analysis/GlobalsModRef.h"
17+
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
18+
#include "llvm/Analysis/LazyBranchProbabilityInfo.h"
1719
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
1820
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
1921
#include "llvm/Analysis/TargetTransformInfo.h"
@@ -50,6 +52,8 @@ void ScopPass::getAnalysisUsage(AnalysisUsage &AU) const {
5052
AU.addPreserved<ScalarEvolutionWrapperPass>();
5153
AU.addPreserved<SCEVAAWrapperPass>();
5254
AU.addPreserved<OptimizationRemarkEmitterWrapperPass>();
55+
AU.addPreserved<LazyBlockFrequencyInfoPass>();
56+
AU.addPreserved<LazyBranchProbabilityInfoPass>();
5357
AU.addPreserved<RegionInfoPass>();
5458
AU.addPreserved<ScopInfoRegionPass>();
5559
AU.addPreserved<TargetTransformInfoWrapperPass>();

0 commit comments

Comments
 (0)