getAnalysis*() called on an analysis that was not " "'required' by pass!

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

getAnalysis*() called on an analysis that was not " "'required' by pass!

john hull
Hello,

I'd appreciate it if anyone can tell me what the error message means and point out what I am doing wrong.
Thank you.


I am trying to use the result of the DominatorTree analysis in my ModulePass class as explained in the section "Writing an LLVM Pass".
http://llvm.org/docs/WritingAnLLVMPass.html#interaction
I called the method "addRequired<DominatorTree>()" in the method "getAnalysisUsage(AnalysisUsage&)", but I get the following error message.

opt: /usr/local/llvm/llvm/include/llvm/PassAnalysisSupport.h:193: AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*) const [with AnalysisType = llvm::DominatorTree]: Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.

The following is the command I typed in:
opt -load /usr/local/llvm/install/lib/mymodulepass.so -mymodulepass <idct.bc > /dev/null

Here are the header and implementation files of my class with just the bare minimum that produces the error messages.
(MyModulePass.h)
#ifndef MYMODULEPASS_H
#define MYMODULEPASS_H
#include "llvm/Pass.h"

namespace llvm {
        class MyModulePass : public ModulePass {
        public:
                static char ID; // Pass identification, replacement for typeid
                MyModulePass();
                virtual bool runOnModule(Module &M);
                virtual void getAnalysisUsage(AnalysisUsage &Info) const;

        };

        extern RegisterPass<MyModulePass> X_MyModulePass;
}

#endif

(MyModulePass.cpp)
#include <iostream>
#include "MyModulePass.h"
#include "llvm/Module.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasAnalysis.h"

using namespace llvm;

// ID, register
char llvm::MyModulePass::ID = 0;
RegisterPass<llvm::MyModulePass> llvm::X_MyModulePass("mymodulepass", "My Module Pass");

MyModulePass::MyModulePass() : ModulePass((intptr_t)&MyModulePass::ID) {
}

bool MyModulePass::runOnModule(Module &m) {
        for (Module::const_iterator f = m.begin(); f != m.end(); ++f)
                DominatorTree &dt = getAnalysis<DominatorTree>();

        return false;
}

void MyModulePass::getAnalysisUsage(AnalysisUsage &info) const {
        info.addRequired<DominatorTree>();
}


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: getAnalysis*() called on an analysis that was not " "'required' by pass!

Wojciech Matyjewicz
Hi,

> bool MyModulePass::runOnModule(Module &m) {
>         for (Module::const_iterator f = m.begin(); f != m.end(); ++f)
>                 DominatorTree &dt = getAnalysis<DominatorTree>();
>
>         return false;
> }

DominatorTree is a function-level analysis, while your pass is a
module-level one. It means you have to point the function you want the
analysis result for. Try using:

  getAnalysis<DominatorTree>(*f);

(It would probably require changing const_iterator to iterator)

Getting analysis result is valid only for function definitions, not
declarations. Hence, it is necessary to check f->isDeclaration() before
calling getAnalysis().

Wojtek
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev