[LLVMdev] How to supply a non-default constructor to RegisterPass ?

Andrew Trick atrick at apple.com
Fri Oct 4 21:34:23 PDT 2013


On Sep 30, 2013, at 10:11 PM, Dirk Schroetter <dschroetter at googlemail.com> wrote:

> Folks,
> 
> I did read the documentation but I am at a loss still.
> 
> I do have the following:
> 
> Pass *createFooPass (char *foo1) {
>  return new FooPass (foo1);
> }
> 
> static RegisterPass<FooPass> X("foo-pass", "foo", false, true);
> 
> Where exactly do I supply the non-default crore in this example ?

Sorry for the non-answer, but AFAIK the pass registry can’t understand a non-default ctor. I personally don’t like non-default pass ctors anyway. You have at least three better options
- If you have different versions of a pass, just make them different passes that share implementation.
- If you have a pass that can be configured in different modes, get the mode from the current context within the pass. Maybe a Function attribute can be used, or ask TargetMachine/TargetOptions within backend passes.
- Get what you need from an existing ImmutablePass, like TargetTransformInfo, TargetPassConfig, or create your own Immutable pass.

-Andy



More information about the llvm-dev mailing list