[LLVMdev] getAnalysis<LoopInfo> from ModulePass

ether zhhb etherzhhb at gmail.com
Wed Sep 15 05:49:06 PDT 2010


hi,

On Wed, Sep 15, 2010 at 8:21 PM, Mariusz Grad <mariusz.grad at gmail.com> wrote:
> Hi,
>
> I wrote tiny ModulePass which iterates over functions and then uses getAnalysis<LoopInfo> in order to get informations about the loop.
> It compiles smoothly, but whenever I try to run it I got error like this:
> opt: .. PassAnalysisSupport.h:203: AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*) const [with AnalysisType = llvm::LoopInfo]: Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.
> What actually this assertion means?
>
> Whenever I change the ModulePass to the FunctionPass the code bellow works just fine.
>
> Here is the code:
> # ============================== #
>
> #define DEBUG_TYPE "bb_info"
> #include "llvm/Pass.h"
> #include "llvm/Function.h"
> #include <llvm/Module.h>
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/ADT/Statistic.h"
> #include "llvm/Analysis/LoopInfo.h"
>
> using namespace llvm;
>
> namespace {
>  struct bb_info: public ModulePass {
>    static char ID;
>
>    bb_info() : ModulePass(&ID) {}
>
>      void getLoopInfo(const Function& F) const {
>        const LoopInfo *LI =  &getAnalysis<LoopInfo> ();
you may try &getAnalysis<LoopInfo> (F);
please have a look at the declaration of  getAnalysis for detail information.

best regards
ether

>        Function::const_iterator BB = F.begin(), E = F.end();
>        for (; BB != E; ++BB)
>          errs() << BB->getName() << " " << LI->getLoopDepth(&*BB) << "\n";
>    };
>
>    virtual bool runOnModule(Module &M) {
>      Module::const_iterator f_it = M.begin(), f_ite = M.end();
>      for ( ; f_it != f_ite; ++f_it )
>      {
>        errs() << f_it->getName() << '\n';
>        if (!f_it->isDeclaration())
>          getLoopInfo(*f_it);
>      }
>      return true;
>    }
>
>    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>      AU.setPreservesAll();
>      AU.addRequired<LoopInfo> ();
>    }
>  };
> }
>
> char bb_info::ID = 0;
> static RegisterPass<bb_info> Y("bb_info", "testing ..");
>
> --
> Mariusz Grad
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list