Hi all,<br><br>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:<br>


clang: PassManager.cpp:601: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed.<br><br>when run through the following command:<br>


clang -march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf -integrated-as simple.c -c -o simple.o<br><br><br>The following is my code for the pass. file: ARMInstrStats.cpp<br><br>#include "llvm/Function.h"
<br>#include "llvm/Pass.h"
<br>#include "ARM.h" 
<br>#include "llvm/CodeGen/MachineFunctionPass.h"
<br>#include "llvm/CodeGen/MachineLoopInfo.h"
<br>#include "llvm/CodeGen/MachineFunction.h"
<br> <br>#include "llvm/CodeGen/MachineFunctionPass.h"
<br>#include "llvm/Target/TargetMachine.h"
<br> <br>//#define DEBUG_TYPE "instruction-count"
<br>#include "llvm/Support/Debug.h"
<br>//#include "ProfilingUtils.h"
<br>#include "llvm/InitializePasses.h"
<br>#include "llvm/Support/raw_ostream.h"
<br>#include "llvm/Analysis/Passes.h"
<br> <br>#include "llvm/Analysis/ProfileInfo.h"
<br>#include "llvm/Analysis/ProfileInfoLoader.h"
<br>#include "llvm/Transforms/Instrumentation.h"
<br>#include <stdio.h>
<br>#include <cstdio>
<br>#include <fstream>
<br> <br>using namespace llvm;
<br>using namespace std;
<br> <br><br>namespace llvm{
<br>struct McProfInf oMsProfI[1000];
<br>}
<br>namespace {
<br><br> <br>class ARMInstrStats : public MachineFunctionPass {
<br>private:
<br><br>  int cnt;
<br>    ProfileInfoLoader &PIL;
<br><br>public:
<br>  static char ID;
<br>  explicit ARMInstrStats(ProfileInfoLoader &_PIL) : MachineFunctionPass(ID), PIL(_PIL){
<br> <br>      <br>        printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br>}
<br>   <br> <br>virtual const char *getPassName() const {
<br>return "ARM Instr Stats Pass";
<br>}
<br>  void processMBB(const MachineBasicBlock &MBB) {
<br>   
<br>     <br>    //double execcnt=1;
<br>    int blckno=0;
<br>    blckno=MBB.getNumber();
<br><br>    ProfileInfo &PI=getAnalysis<ProfileInfo>();
<br>    printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br>    const BasicBlock *BB=MBB.getBasicBlock();
<br>    if(BB!=NULL)
<br>        printf("\nBB is not null");
<br>    //execcnt=getAnalysis<ProfileInfo>().getExecutionCount(BB);
<br>    double execcnt=PI.getExecutionCount(BB);
<br>    printf("\nBlock No=%d,ExecCnt=%f",blckno,execcnt);
<br>    if(blckno!=-1)
<br>    {
<br>        oMsProfI[cnt].blockno=blckno;
<br>        oMsProfI[cnt].execcnt=execcnt;
<br>        cnt++;
<br>    }
<br>  }
<br> <br>  bool runOnMachineFunction(MachineFunction &MF) {
<br>    //MPI=&getAnalysis<MachineProfileInfo>();
<br>    cnt=0;
<br>        printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br>    for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
<br>         I != E; ++I)
<br>      processMBB(*I);
<br>        printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br>    return false;
<br>  };
<br> <br>  void getAnalysisUsage(AnalysisUsage &AU) const {
<br>    AU.setPreservesAll();
<br>        printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br><br>    AU.addRequired<ProfileInfo>();
<br>        printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br>    MachineFunctionPass::getAnalysisUsage(AU);
<br>  };
<br><br>};
<br>}
<br> <br>//}
<br>char ARMInstrStats::ID = 0;
<br><br>namespace llvm {
<br>FunctionPass *createARMInstrStatsPass(ProfileInfoLoader &PIL) {
<br> PassRegistry &Registry=*PassRegistry::getPassRegistry();
<br>       <br>        initializeAnalysis(Registry);
<br> <br> <br>        initializeInstrumentation(Registry);
<br> <br>        initializeCodeGen(Registry);
<br>        initializeTarget(Registry);
<br>       <br>        printf("\n%s:%d",__FILE__,__LINE__);
<br>    fflush(stdout);
<br>  return new ARMInstrStats(PIL);
<br>}
<br>}<br><br><br>The following changes have been made to the file ARMTargetMachine.cpp in the function bool ARMPassConfig::addPreEmitPass():<br>bool ARMPassConfig::addPreEmitPass() {<br>  if (getARMSubtarget().isThumb2()) {<br>


    if (!getARMSubtarget().prefers32BitThumb())<br>      PM->add(createThumb2SizeReductionPass());<br><br>    // Constant island pass work on unbundled instructions.<br>    addPass(UnpackMachineBundlesID);<br>  }<br><br>


  PM->add(createARMConstantIslandPass());<br>  for(int iCnt=0;iCnt<1000;iCnt++){<br>    oMsProfI[iCnt].blockno=0;<br>    oMsProfI[iCnt].execcnt=0;<br>}<br>    PassRegistry &Registry=*PassRegistry::getPassRegistry();<br>


    initializeAnalysis(Registry);<br>    initializeCodeGen(Registry);    <br>    initializeTarget(Registry);    <br> <br>    LLVMContext &Context = getGlobalContext();<br><br><br>  // Read in the bitcode file...<br>   std::string ErrorMessage;<br>


  OwningPtr<MemoryBuffer> Buffer;<br>  error_code ec;<br>  Module *M = 0;<br>    char BitcodeFile[100];<br>    FILE* fp=fopen("profile.ini","r");<br>    if(fp)<br>        fscanf(fp,"%s\n",BitcodeFile);<br>


  if (!(ec = MemoryBuffer::getFileOrSTDIN(BitcodeFile, Buffer))) {<br>      M = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage);<br>  }<br>    ProfileInfoLoader PIL("llvm-prof","llvmprof.out",*M);<br>


    PM->add(createProfileLoaderPass("llvmprof.out"));<br>    printf("\n%s:%d",__FILE__,__LINE__);<br>    fflush(stdout);<br>    <br>    PM->add(createARMInstrStatsPass(PIL));<br>   <br>    printf("\n%s:%d",__FILE__,__LINE__);<br>


    fflush(stdout);<br>  return true;<br>}<br><br><br>Can anyone find what is wrong with this approach and c?<br><br clear="all">Thanks and Regards,<br>Ranajoy Pal<br>