About adding a pass into llvm

I have seen

INITIALIZE_PASS(LiveVariables, “livevars”, “Live Variable Analysis”, false, false);
in the llvm/lib/codegen/LiveVariables.cpp, where LiveVariables is a subclass of MachineFunctionPass, and

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static RegisterPass passName ## _info(arg, name, cfg, analysis)

in PassSupport.h

Is this code used to register and initialize a pass? This kind of registration is just the way illustrated in the hello example at http://llvm.org/docs/WritingAnLLVMPass.html#registration.

My problem is:
I wrote a pass (Mypass), also a subclass of MachineFunctionPass. And I wrote the similar statement:
INITIALIZE_PASS(Mypass, “mypass”, “Access Analysis”, false, false);
aiming to register and initialize this new pass. I rebuilt the llvm with the newly added pass, but when I used llc -help-hidden, I could not found the “-mypass” option. How could I enable the new pass and the related option?

Hi Li Qingan,

I have seen
INITIALIZE_PASS(LiveVariables, "livevars", "Live Variable Analysis", false, false);
in the llvm/lib/codegen/LiveVariables.cpp, where LiveVariables is a subclass of
MachineFunctionPass, and
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
   static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis)
in PassSupport.h

Is this code used to register and initialize a pass? This kind of registration
is just the way illustrated in the hello example at
http://llvm.org/docs/WritingAnLLVMPass.html#registration.

how you do this depends on whether your pass will be built in to LLVM, or
whether it will be dynamically loaded by opt at runtime. The HelloWorld
example on the web-page you mentions shows how to do it when a pass is to
be dynamically loaded - this means using RegisterPass. If your pass is to
be built into LLVM then you can copy what other passes do. Note that in
this case you typically need to modify include/llvm/Transforms/Scalar.h
and include/llvm/LinkAllPasses.h.

My problem is:
I wrote a pass (Mypass), also a subclass of MachineFunctionPass. And I wrote the
similar statement:
INITIALIZE_PASS(Mypass, "mypass", "Access Analysis", false, false);
aiming to register and initialize this new pass. I rebuilt the llvm with the
newly added pass, but when I used llc -help-hidden, I could not found the
"-mypass" option. How could I enable the new pass and the related option?

In this third case of adding a codegen pass, you will need to add your pass to
include/llvm/CodeGen/Passes.h and have it be added to the pass manager in
lib/CodeGen/LLVMTargetMachine.cpp

Ciao, Duncan.