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

Andreas Neustifter astifter-llvm at gmx.at
Tue Oct 13 00:51:10 PDT 2009


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



More information about the llvm-dev mailing list