[LLVMdev] Running a pass

John Criswell criswell at cs.uiuc.edu
Tue Dec 15 13:13:16 PST 2009


Juan Carlos Martinez Santos wrote:
> Hello LLVM,
>
> I am following the document "Writing an LLVM Pass". When I ran "opt 
> -load ../../../Debug/lib/MyPass.so -mypass < hello.bc > /dev/null" I 
> got the next error:
>
> ***@ubuntu:~/test$ opt -load ../../llvm/Debug/lib/MyPass.so -mypass < 
> hello.bc > /dev/null
> opt: Pass.cpp:159: void<unnamed>::PassRegistrar::RegisterPass(const 
> llvm::PassInfo&): Assertion `Inserted && "Pass registered multiple 
> times!"' failed.
> Aborted
I don't see any obvious problems with your source code.

Are you compiling this file as part of your own project, or did you add 
it to your LLVM source tree (e.g., placing MyPass.cpp into 
lib/Transforms in the LLVM source tree)?  If you did the latter, it's 
possible that your pass is being compiled into the opt program 
automatically by the LLVM build system, and so when you do a -load of 
your dynamic library, you get your pass defined twice.

An easy way to test this is to run opt --help-hidden and see if "mypass" 
is in the list.

-- John T.

>
> To compile MyPass I used "make" command instead of "gmake", could it 
> be the problem? Or maybe I just type (copy) something wrong? Could 
> someone take a look of my files and point my errors out?
>
> Thanks in advance,
>
>  Juan Carlos
>
> *****************
> *** Makefile ***
> *****************
> LEVEL = ../../..
> LIBRARYNAME = MyPass
> LOADABLE_MODULE = 1
> LLVMLIBS = LLVMCore.a LLVMSupport.a LLVMSystem.a
> include $(LEVEL)/Makefile.common
>
> **********************
> *** MyPass.cpp ***
> **********************
> #include "llvm/Pass.h"
> #include "llvm/Function.h"
> #include "llvm/Support/raw_ostream.h"
>
> using namespace llvm;
>
> namespace {
> struct MyPass : public FunctionPass {
>
>     static char ID;
>         MyPass() : FunctionPass(&ID) {}
>
>          virtual bool runOnFunction(Function &F) {
>            errs() << "MyPass: " << F.getName() << "\n";
>            return false;
>          }
>        };  // end of struct MyPass
>
> char MyPass::ID = 0;
> RegisterPass<MyPass> X("mypass", "My first Pass",
>                       false /* Only looks at CFG */,
>                       false /* Analysis Pass */);
> }  // end of anonymous namespace
>
>
> -- 
> Juan Carlos




More information about the llvm-dev mailing list