[LLVMdev] Cannot use function pass in a module pass
Alexey Bakhirkin
abakhirkin at gmail.com
Thu Jun 16 10:22:33 PDT 2011
Thanks, John.
There were a couple of function declarations in the module, and
'getAnalysis' failed for those.
By the way, what do you mean by "in older versions of LLVM"? I'm quite
sure I was using the latest llvm trunk.
2011/6/16 John Criswell <criswell at cs.uiuc.edu>:
> On 6/15/11 6:46 PM, Alexey Bakhirkin wrote:
>> 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:
>
> This may not be your problem, but in older versions of LLVM, you cannot
> call getAnalysis<FunctionPassName>(F) if F is a function with no body.
> You need to do something like:
>
> if (!(F->isDeclaration())) {
> getAnalysis<FunctionPassName>(F);
> ...
> }
>
> -- John T.
>
>> [***@*** ***]$ 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");
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> _______________________________________________
> 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