Make dependency between certain analysis passes transitive
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Wed, 21 Apr 2021 12:18:32 +0000 (14:18 +0200)
committerBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Tue, 4 May 2021 09:50:08 +0000 (11:50 +0200)
commit3655f0757f2b4b61419446b326410118658826ba
tree9b949496423f791ce83ea7a0e2f496c04f46af54
parent1db4dbba24dd36bd5a91ed58bd9d92dce2060c9f
Make dependency between certain analysis passes transitive

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.

Differential Revision: https://reviews.llvm.org/D100958
llvm/lib/Analysis/LazyBlockFrequencyInfo.cpp
llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
llvm/lib/Analysis/LoopAccessAnalysis.cpp
llvm/test/Other/pr49950.ll [new file with mode: 0644]