[LLVMdev] Running a pass
sabre at nondot.org
Wed Aug 13 15:39:01 PDT 2003
On Wed, 13 Aug 2003, Rahul Joshi wrote:
> I want to run the Mem2Reg pass on a function without using the the LLVM opt utility. I wrote some code, which I am not sure is correct:
> // find the dominance frontier of the CFG
> DominanceFrontier DF;
> // try to promote stack allocated variables
> PromoteMemToReg(function->getRegAllocas(), DF, *tgt_data);
This won't work. Passes are supposed to be run by the PassManager (see
http://llvm.cs.uiuc.edu/docs/WritingAnLLVMPass.html), which figures out
what the dependencies of the passes are.
In this case, DominanceFrontier depends on DominatorTree (which depends on
DominatorSet), all of which the PassManager automatically figures out and
If you want to run the mem2reg pass, this means you need to do something
along these lines:
PM.run(M); // M is your module.
Alternatively, if you just want to run it a function-at-a-time, you can
use the new FunctionPassManager which Brian just checked in.
> Is this supposed to work? Or what is the preferred way passes
> are to be run on functions? With the above code, my program
> crashes even before main(), when doing some static
> initialization in Type.cpp.
I'm not sure what is causing this problem, if main is not even executing
yet, then it shouldn't matter what your main does. :)
More information about the llvm-dev