简体   繁体   中英

LLVM GetAnalysis() failing with required passes

I have a custom set of passes created using LLVM to run on some bitcode. I've managed to get it to compile, but whenever I try to run it with a pass that calls getAnalysis() on another pass type it fails with:

Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.

The custom pass that is calling getAnalysis() requires its type, specifically;

bool Operators::doInitialization(){
ParseConfig &parseConfig = getAnalysis<ParseConfig>(); // Fails here.
}
.
.
.
void Operators::getAnalysisUsage(AnalysisUsage &AU) const{
    AU.addRequired<ParseConfig>();
    return;
}

I've spent a few days on this and am quite lost. I know the following is true:

  • ParseConfig is registered successfully via the RegisterPass<> template, and I have stepped through it in GDB to find that it does get registered.
  • Also using GDB I have found that when looking into getAnalysis() that the list of registered passes is always empty (which causes the assertion).

Important Note : I will eventually be using this on a Fortran project which is compiled with Flang, thus the LLVM library version I'm using is the Flang fork (found here ). That fork is right around LLVM 7.1, but the specific files associated with registering passes seems to not be different from the current LLVM library.

Move getAnalysis function from doInitialization to runOnFunction would make it work.


From LLVM page

This method call getAnalysis* returns a reference to the pass desired. You may get a runtime assertion failure if you attempt to get an analysis that you did not declare as required in your getAnalysisUsage implementation. This method can be called by your run* method implementation, or by any other local method invoked by your run* method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM