[LLVMdev] Cannot use function pass in a module pass

Alexey Bakhirkin abakhirkin at gmail.com
Wed Jun 15 16:46:36 PDT 2011


Hi. I'm trying to implement a module pass which can be dynamically
loaded by `opt` (against up-to-date llvm from svn).
Despite what the tutorial
(http://llvm.org/docs/WritingAnLLVMPass.html) states in my module pass
I cannot perform getAnalysis and fetch the function pass result.
When trying to do so `opt` fails with the following mesage:

[***@*** ***]$ opt -load ~/llvm/Debug+Asserts/lib/MyPassLibrary.so
-mymodulepass < input.bc >/dev/null
MyModulePass::runOnModule
MyFunctionPass::runOnFunction(process)
opt: /***/llvm/include/llvm/MyFunctionPass.h:241: AnalysisType&
llvm::Pass::getAnalysisID(llvm::AnalysisID, llvm::Function&) [with
AnalysisType = {anonymous}::MyFunctionPass, llvm::AnalysisID = const
void*]: Assertion `ResultPass && "Unable to find requested analysis
info"' failed.
0  opt             0x0000000000dbcd86
1  opt             0x0000000000dbcb82
2  libpthread.so.0 0x0000003b8f00eeb0
3  libc.so.6       0x0000003b8e835285 gsignal + 53
4  libc.so.6       0x0000003b8e836b9b abort + 379
5  libc.so.6       0x0000003b8e82dc0e
6  libc.so.6       0x0000003b8e82dcb2
7  MyPassLibrary.so 0x00007fb2989ce7e8
8  MyPassLibrary.so 0x00007fb2989ce59f
9  MyPassLibrary.so 0x00007fb2989ce401
10 opt             0x0000000000d39af7
llvm::MPPassManager::runOnModule(llvm::Module&) + 453
11 opt             0x0000000000d39ff8
llvm::PassManagerImpl::run(llvm::Module&) + 130
12 opt             0x0000000000d3a3ff llvm::PassManager::run(llvm::Module&) + 39
13 opt             0x00000000008c6803 main + 4561
14 libc.so.6       0x0000003b8e82139d __libc_start_main + 237
15 opt             0x00000000008b7b69
Stack dump:
0.	Program arguments: opt -load
/***/llvm/Debug+Asserts/lib/MyPassLibrary.so -mymodulepass
1.	Running pass 'My module pass' on module '<stdin>'.
Aborted

--------

My code is similar to the following:

#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

namespace {
  struct MyFunctionPass : public FunctionPass {
    static char ID;
    MyFunctionPass() : FunctionPass(ID) {};

    virtual bool runOnFunction(Function &F) {
      errs() << "MyFunctionPass::runOnFunction(" << F.getName() << ")" << '\n';
      return false;
    }
  };
}

char MyFunctionPass::ID = 0;
static RegisterPass<MyFunctionPass> MyFunctionPassPass("myfunctionpass",
  "My function pass");

namespace {
  struct MyModulePass : public ModulePass {
    static char ID;
    MyModulePass() : ModulePass(ID) {};

    virtual bool runOnModule(Module &M) {
      errs() << "MyModulePass::runOnModule" << '\n';

      for(Module::iterator FI=M.begin(), E=M.end(); FI!=E; ++FI) {
        getAnalysis<MyFunctionPass>(*FI);
      }

      return false;
    }

    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<MyFunctionPass>();
    }
  };
}

char MyModulePass::ID = 0;
static RegisterPass<MyModulePass> MyModulePassPass("mymodulepass",
  "My module pass");



More information about the llvm-dev mailing list