[LLVMdev] loadable passes with dependencies?

Tobias Grosser tobias at grosser.es
Tue Nov 8 01:10:28 PST 2011


On 11/08/2011 03:20 AM, ret val wrote:
> I'm writing a Pass that I would like to remain loadable by opt. The
> pass also requires DominatorTree(for PromoteMemToReg).
>
> Looking for examples the only way I found to require a dependecny is
> by doing something like this:
>          char Hello::ID = 0;
>          namespace llvm { void initializeHelloPass(llvm::PassRegistry&); }
>          INITIALIZE_PASS_BEGIN(Hello, "hello", "Hello World Pass", false, true)
>          INITIALIZE_PASS_DEPENDENCY(DominatorTree)
>          INITIALIZE_PASS_END(Hello, "hello", "Hello World Pass", false, true)
>
> Unfortunately this gives me(when I try to run it).
>        opt: Unknown command line argument '-hello'.
>
> If I instead using RegisterPass like in the guide the Pass is loaded
> fine, a assert is just tripped for not having DominatorTree info. I
> can not seem to mix these 2 ways together or find anything trying todo
> the same.
>
> How should this be done?

Hi,

you can have a look at the approach taken in Polly [1]. Here the 
relevant file in the git repository:

http://repo.or.cz/w/polly-mirror.git/blob/HEAD:/lib/RegisterPasses.cpp

Basically we created a class polly::StaticInitializer which initializes 
in its constructor all passes in the external library (in our case 
Polly). To make sure the constructor is called when loading
the library, we create a global instance of the static initializer.

I am not sure if this is the recommended way, but at least it works for 
us. If there any comments on how to improve this, please let me know.

Cheers
Tobi

[1] http://polly.grosser.es/



More information about the llvm-dev mailing list