[LLVMdev] getAnalysis<LoopInfo> from ModulePass
Mariusz Grad
mariusz.grad at gmail.com
Wed Sep 15 05:21:19 PDT 2010
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> ();
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
More information about the llvm-dev
mailing list