Hi all, I am trying to load a profile information (llvmprof.out) which has been separately created, to get the execution count of each basic block and use it to estimate the execution count of machine basic blocks for getting how many times any instruction gets executed, for ARM specifically. The error on running the code comes as: clang: PassManager.cpp:601: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed. when run through the following command: clang -march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf -integrated-as simple.c -c -o simple.o The following is my code for the pass. file: ARMInstrStats.cpp #include "llvm/Function.h" #include "llvm/Pass.h" #include "ARM.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Target/TargetMachine.h" //#define DEBUG_TYPE "instruction-count" #include "llvm/Support/Debug.h" //#include "ProfilingUtils.h" #include "llvm/InitializePasses.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/ProfileInfo.h" #include "llvm/Analysis/ProfileInfoLoader.h" #include "llvm/Transforms/Instrumentation.h" #include <stdio.h> #include <cstdio> #include <fstream> using namespace llvm; using namespace std; namespace llvm{ struct McProfInf oMsProfI[1000]; } namespace { class ARMInstrStats : public MachineFunctionPass { private: int cnt; ProfileInfoLoader &PIL; public: static char ID; explicit ARMInstrStats(ProfileInfoLoader &_PIL) : MachineFunctionPass(ID), PIL(_PIL){ printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); } virtual const char *getPassName() const { return "ARM Instr Stats Pass"; } void processMBB(const MachineBasicBlock &MBB) { //double execcnt=1; int blckno=0; blckno=MBB.getNumber(); ProfileInfo &PI=getAnalysis<ProfileInfo>(); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); const BasicBlock *BB=MBB.getBasicBlock(); if(BB!=NULL) printf("\nBB is not null"); //execcnt=getAnalysis<ProfileInfo>().getExecutionCount(BB); double execcnt=PI.getExecutionCount(BB); printf("\nBlock No=%d,ExecCnt=%f",blckno,execcnt); if(blckno!=-1) { oMsProfI[cnt].blockno=blckno; oMsProfI[cnt].execcnt=execcnt; cnt++; } } bool runOnMachineFunction(MachineFunction &MF) { //MPI=&getAnalysis<MachineProfileInfo>(); cnt=0; printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) processMBB(*I); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); return false; }; void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); AU.addRequired<ProfileInfo>(); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); MachineFunctionPass::getAnalysisUsage(AU); }; }; } //} char ARMInstrStats::ID = 0; namespace llvm { FunctionPass *createARMInstrStatsPass(ProfileInfoLoader &PIL) { PassRegistry &Registry=*PassRegistry::getPassRegistry(); initializeAnalysis(Registry); initializeInstrumentation(Registry); initializeCodeGen(Registry); initializeTarget(Registry); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); return new ARMInstrStats(PIL); } } The following changes have been made to the file ARMTargetMachine.cpp in the function bool ARMPassConfig::addPreEmitPass(): bool ARMPassConfig::addPreEmitPass() { if (getARMSubtarget().isThumb2()) { if (!getARMSubtarget().prefers32BitThumb()) PM->add(createThumb2SizeReductionPass()); // Constant island pass work on unbundled instructions. addPass(UnpackMachineBundlesID); } PM->add(createARMConstantIslandPass()); for(int iCnt=0;iCnt<1000;iCnt++){ oMsProfI[iCnt].blockno=0; oMsProfI[iCnt].execcnt=0; } PassRegistry &Registry=*PassRegistry::getPassRegistry(); initializeAnalysis(Registry); initializeCodeGen(Registry); initializeTarget(Registry); LLVMContext &Context = getGlobalContext(); // Read in the bitcode file... std::string ErrorMessage; OwningPtr<MemoryBuffer> Buffer; error_code ec; Module *M = 0; char BitcodeFile[100]; FILE* fp=fopen("profile.ini","r"); if(fp) fscanf(fp,"%s\n",BitcodeFile); if (!(ec = MemoryBuffer::getFileOrSTDIN(BitcodeFile, Buffer))) { M = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage); } ProfileInfoLoader PIL("llvm-prof","llvmprof.out",*M); PM->add(createProfileLoaderPass("llvmprof.out")); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); PM->add(createARMInstrStatsPass(PIL)); printf("\n%s:%d",__FILE__,__LINE__); fflush(stdout); return true; } Can anyone find what is wrong with this approach and c? Thanks and Regards, Ranajoy Pal -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120926/ec08dc93/attachment.html>