0

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.

Aroic
  • 479
  • 2
  • 12

1 Answers1

3

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.

Bruce Shen
  • 572
  • 3
  • 13
  • 1
    I actually figured this out on my own just a few days ago. It turns out doInitialization is called by all other passes before any are run, so I was trying to get the analysis of a pass that had yet to be run. Thanks! – Aroic Oct 29 '19 at 16:46