[LLVMdev] Running a pass

Juan Carlos Martinez Santos juanc.martinez.santos at gmail.com
Tue Dec 15 13:42:14 PST 2009


Thanks John,

I was just following the instructions; I created a new folder inside of llvm
(/lib/Trasnforms/MyPass). After I run opt --help-hidden, I didn't see
mypass.

However, I found that if I remove the LLVMLIBS (LLVMCore.a LLVMSupport.a
LLVMSystem.a) from the Makefile, the pass works. I found that after
comparing Hello folder (llvm tree) with the information in the website. Now,
it is working as I expected.

Thanks again,

Juan Carlos


On Tue, Dec 15, 2009 at 4:13 PM, John Criswell <criswell at cs.uiuc.edu> wrote:

> 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
>>
>
>


-- 
Juan Carlos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091215/594817f9/attachment.html>


More information about the llvm-dev mailing list