[LLVMdev] Running specific passes

Chris Lattner sabre at nondot.org
Fri Nov 26 08:56:22 PST 2004


On Fri, 26 Nov 2004, Vladimir Prus wrote:
> in the implementation of some analysis, I need to change the program and then
> invoke Mem2Reg pass. That pass, in turn, requires other analysis, so I must

Usually you want to do this at a higher level, why not just use 'opt
-yourpass -mem2reg'?

Alternatively, if you don't want to do that, you can build mem2reg into
your pass if it works better.  To do this, your pass needs to
'addRequired' DominatorTree and DominatorFrontier, then use the
interfaces exposed through
include/llvm/Transforms/Utils/PromoteMemToReg.h.

-Chris

> use PassManager. Here's the code I ended up with:
>
>         bool runOnFunction(llvm::Function& m)
>         {
>             visit(m);
>
>             ExistingModuleProvider mp(m.getParent());
>             FunctionPassManager pm(&mp);
>             .....
>             //m.add(createPromoteMemoryToRegister());
>             pm.run(m);
>
> There are several problems, though:
>
> 1. This looks inefficient -- the analyses necessary for Mem2Reg will be run
> again, even if they are already run by the global pass manager. But how to
> ask the global pass manager to run a pass immediately?
>
> 2. This does not work. ExistingModuleProvider takes ownership of m.getParent()
> and deletes it at the end.
>
> 3. This does not work. The Mem2Reg pass requires TargetData which does not
> seem to be available. The only reason why it requires it, is to pass to
> lib/Transforms/Utils/PromoteMemoryToRegister.cpp:isAllocaPromotable, which
> does not use that data at all.
>
> Could anybody suggest a better solution?
>
> - Volodya
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list