Accessing function analyses inside a loop pass

Hi everyone,

I am trying to access functions analyses (in particular DependenceInfo) inside a loop pass. As per the documentation on the new pass manager says, I used :
const auto &FAM = LAM.getResult<FunctionAnalysisManagerLoopProxy>(L, AR).getManager();

But FunctionAnalysisManagerLoopProxy is defined as a typedef to a class which does not have a getManager member, whereas FunctionAnalysisManagerCGSCCProxy used in the documentation have it.

Should I conclude it is not possible to access these analyses ? Should I made my pass a function pass instead of a loop pass ?

According to the comments for OuterAnalysisManagerProxy, the underlying class for FunctionAnalysisManagerLoopProxy, you cannot get the full AnalysisManager interface (e.g. getResult). Instead, you only have APIs that have constant behavior. More specifically, APIs that don’t potentially trigger an analysis, like getCachedResult.

Ok thanks ! Seems like I read the manual too fast… That being said, using getCachedResult<DependenceAnalysis> with the following opt passes

opt -passes='function(require<da>), loop(my_loop_pass)'

triggers an assertion :

opt: llvm/include/llvm/IR/PassManager.h:826: 
void llvm::AnalysisManager<llvm::Function>::verifyNotInvalidated(IRUnitT &, typename PassT::Result *) const [IRUnitT = llvm::Function, ExtraArgTs = <>, PassT = llvm::DependenceAnalysis]: 
Assertion `!Result->invalidate(IR, PA, Inv) && "Cached result cannot be invalidated"' failed.

I am not sure to understand the concept behind the invalidate function, it look likes it can be used to check if the analysis could be invalidated, but also invalidate it somehow ? Which means I don’t
understand the assertion. Also, I don’t understand why would the analyses ever be invalid since I run them just before the loop pass.

I’ve read the commit which added the assertion (⚙ D72893 [NewPassManager] Add assertions when getting statefull cached analysis.), and it looks like it is not possible to get statefull analysis from an outer pass. Does it means I have to write my loop pass as a function pass instead to benefit from dependency analyses ?