Use LoopInfo in a non-pass class such as ProfileInfoLoader?

Hi everyone,

I'm adding loop profiling to LLVM built-in profiler. I'm just
wondering in a class that's not a pass, such as ProfileInfoLoader, how
can I get information produced by passes such as LoopInfo and
DominatorTree?

In other words, ProfileInfoLoader is not a pass, so it can't call
AnalysisUsage::addRequired and AnalysisUsage::getAnalysisUsage
directly. Then how can it know if an arbitrary basic block is a loop
header using information/classes/methods available to it?

Thanks a lot!

Wenhao Jia

Hi,

Wenhao Jia wrote:

I'm adding loop profiling to LLVM built-in profiler. I'm just
wondering in a class that's not a pass, such as ProfileInfoLoader, how
can I get information produced by passes such as LoopInfo and
DominatorTree?

I don't know if there is a Best Practice, but usually you have a pass
thats using the non-pass module (ProfileInfoLoader in your case). I use
the getAnalysis in the pass and hand a reference to the analysis to the
non-pass module so it can use it.

Also its possible to hand a reference to the pass itself to the non-pass
class and use this reference to call getAnalysis (pseudo code!):

NonPassModule::someFunction (..., Pass *P) {
  ...
  SomeAnalysis SOA = P->getAnalysis<SomeAnalysis>();
  ...
}

SomePass::runOn... (...) {
  ...
  NonPassModule NPM;
  ...
  NPM.someFunction(..., this);
  ...
}

Hope that helps,

Andi