Hi, How can I use profile information into my pass for performing some analysis. I tried something like: PassManager PassMgr = PassManager(); cl::opt<std::string> ProfileDataFile(cl::Positional, cl::desc("<llvmprof.out file>"), cl::Optional, cl::init("llvmprof.out")); PassMgr.add(createProfileLoaderPass(ProfileDataFile)); PassMgr.run(M); ProfileInfo *PI; PI = &getAnalysis<ProfileInfo>(); But this dosent seem to work. I want to perform profile guided analysis and thus want to use profile info. regards, Ambika
Hi! On 25.02.2010, at 17:33, ambika wrote:> How can I use profile information into my pass for performing some > analysis. > > I tried something like: > > PassManager PassMgr = PassManager(); > cl::opt<std::string> ProfileDataFile(cl::Positional, > cl::desc("<llvmprof.out file>"), > cl::Optional, cl::init("llvmprof.out")); > PassMgr.add(createProfileLoaderPass(ProfileDataFile)); > PassMgr.run(M);This does look good to me, I assume you have a debug build? Then use - debug-pass=Details to see what is going on in the passmanager.> ProfileInfo *PI; > PI = &getAnalysis<ProfileInfo>();This is from the top of my head, but I guess you have to use this inside a pass, do you call this in the same module as the previous code? Or do you use this inside your profile-guided analysis pass? Andi
Ah BTW... On 25.02.2010, at 17:33, ambika wrote:> ProfileInfo *PI; > PI = &getAnalysis<ProfileInfo>();If this _in_ your pass, then you have to register the usage of this in the getAnalysisUsage() method: void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<ProfileInfo>(); } Also you have to ensure that the pass you are using is executed right after the ProfileInfoLoader, currently not all passes are preserving the profile information. If you need intermediate passes I already have a patch that preserves (most) of the information, I'm waiting for after 2.7 to put this in... Andi
I have not made a separate pass. I have done it in single pass ie added ProfileLoaderPass , got information in PI and now I am planning to perform the analysis here itself. I was trying to print information using ProfileInfoPrinter pass but was unable to do it. namespace { class MyAna : public ModulePass { ProfileInfo *PI; public: static char ID; // Class identification, replacement for typeinfo MyAna() : ModulePass(&ID) {} virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequired<ProfileInfo>(); } bool runOnModule(Module &M) { PassManager PassMgr = PassManager(); cl::opt<std::string> ProfileDataFile(cl::Positional, cl::desc("<llvmprof.out file>"), cl::Optional, cl::init("llvmprof.out")); PassMgr.add(createProfileLoaderPass(ProfileDataFile)); PI = &getAnalysis<ProfileInfo>(); } }; } char MyAna::ID = 0; static RegisterPass<MyAna> X("my-ana", "Testing prof info"); What I basically want is to use block profile information in this pass to perform my analysis. Here I created llvmprof.out separately and then i am using it. Is there a way so that it is generated itself for the program? Andreas Neustifter wrote:> Ah BTW... > > On 25.02.2010, at 17:33, ambika wrote: > >> ProfileInfo *PI; >> PI = &getAnalysis<ProfileInfo>(); > > If this _in_ your pass, then you have to register the usage of this in > the getAnalysisUsage() method: > > void getAnalysisUsage(AnalysisUsage &AU) const { > AU.addRequired<ProfileInfo>(); > } > > Also you have to ensure that the pass you are using is executed right > after the ProfileInfoLoader, currently not all passes are preserving > the profile information. > > If you need intermediate passes I already have a patch that preserves > (most) of the information, I'm waiting for after 2.7 to put this in... > > Andi