Exactly what I was looking for.  Thanks a lot.<div><br></div><div>Brent<br><br><div class="gmail_quote">On Sat, Nov 5, 2011 at 2:35 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Brent,<br>
<div class="im"><br>
> The code in this setup will be optimized according to the optimizer pipeline one<br>
> sets up as in the code below.  I find that if I only use the passes below the<br>
> quality of the code is not that good<br>
<br>
</div>code quality will be dreadful if you don't promote memory accesses to registers<br>
right at the start, using eg mem2reg or scalarrepl.<br>
<div class="im"><br>
  (for example inlining is not aggressive<br>
> enough) -- moreover the number of passes is overwhelming and the order in which<br>
> they are specified seems important and I do not have the expertise to set that<br>
> up.  What I would like, is to set up the passes in exactly the same as clang -O2<br>
> or llvm-gcc -O2 do.  Is there some way to get that behavior using the api below?<br>
<br>
</div>You can use a PassManagerBuilder for this.  For some reason it is tucked away in<br>
an obscure corner of include: include/llvm/Transforms/IPO/PassManagerBuilder.h<br>
<br>
Ciao, Duncan.<br>
<div class="im"><br>
>   How do language implementors do this in the LLVM environment?<br>
><br>
> Thank you for any help.  And thank you for this great tool.<br>
><br>
> Brent<br>
><br>
>    FunctionPassManager OurFPM(TheModule);<br>
><br>
>    // Set up the optimizer pipeline.  Start with registering info about how the<br>
>    // target lays out data structures.<br>
>    OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));<br>
>    // Provide basic AliasAnalysis support for GVN.<br>
>    OurFPM.add(createBasicAliasAnalysisPass());<br>
>    // Do simple"peephole"  optimizations and bit-twiddling optzns.<br>
>    OurFPM.add(createInstructionCombiningPass());<br>
>    // Reassociate expressions.<br>
>    OurFPM.add(createReassociatePass());<br>
>    // Eliminate Common SubExpressions.<br>
>    OurFPM.add(createGVNPass());<br>
>    // Simplify the control flow graph (deleting unreachable blocks, etc).<br>
>    OurFPM.add(createCFGSimplificationPass());<br>
><br>
>    OurFPM.doInitialization();<br>
><br>
>    // Set the global so the code gen can use this.<br>
>    TheFPM =&OurFPM;<br>
><br>
>    // Run the main"interpreter loop"  now.<br>
>    MainLoop();<br>
><br>
><br>
><br>
</div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>