[LLVMdev] Get Analysis from PassManager
    Andreas Neustifter 
    e0325716 at student.tuwien.ac.at
       
    Thu Jun  4 08:18:45 PDT 2009
    
    
  
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkon5dUACgkQPiYq0rq7s/BB/gCfQEaRL5ZrAralWrYFnnkO7heU
v6kAnR+HLruRNj/IGoTh8ud//U1xHBMc
=jC9S
-----END PGP SIGNATURE-----
    
    
More information about the llvm-dev
mailing list