Hi,
I try to write a tool that uses the PassManager to load profiling
information for a module like this:
...
ModulePass *LoaderPass = createProfileLoaderPass();
PassMgr.add(LoaderPass);
PassMgr.run(*M);
...
I can verify that the pass was run, but how to I get to the ProfileInfo
implemented by that pass?
I tried
...
ProfileInfo PI = LoaderPass->getAnalysis<ProfileInfo>();
...
but this does not seem to return the correct profiling information.
Thanks, Andi
Okay, found it:
Andreas Neustifter wrote:
I try to write a tool that uses the PassManager to load profiling
information for a module like this:
...
ModulePass *LoaderPass = createProfileLoaderPass();
PassMgr.add(LoaderPass);
PassMgr.run(*M);
...
I can verify that the pass was run, but how to I get to the ProfileInfo
implemented by that pass?
I tried
...
ProfileInfo PI = LoaderPass->getAnalysis<ProfileInfo>();
...
but this does not seem to return the correct profiling information.
I have writen a small pass that just does what I need:
namespace {
class LoaderInterface : public ModulePass {
ProfileInfo *PI;
public:
static char ID; // Class identification, replacement for typeinfo
explicit LoaderInterface() : ModulePass(&ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<ProfileInfo>();
}
ProfileInfo* getPI() {
return PI;
}
bool runOnModule(Module &M) {
PI = &getAnalysis<ProfileInfo>();
return false;
}
};
}
char LoaderInterface::ID = 0;
So now I can just use the pass as expected:
....
PassManager PassMgr = PassManager();
PassMgr.add(createProfileLoaderPass());
LoaderInterface *LI = new LoaderInterface();
PassMgr.add(LI);
PassMgr.run(*M);
ProfileInfo *PI = LI->getPI();
....
Andi