[cfe-dev] [llvm-dev] Is there a way to pass Optimization passes to clang?

Mehdi Amini via cfe-dev cfe-dev at lists.llvm.org
Wed Dec 2 10:14:32 PST 2015


Adding CC: cfe-dev 

> On Dec 2, 2015, at 9:56 AM, Phil Tomson via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> 0 down vote <> favorite <http://stackoverflow.com/questions/34049511/how-to-pass-optimization-passes-to-clang#>
> I'm trying to debug an issue for a new target where a testcase fails with -O1 optimization and passes with -O0 optimization.
> 
> I got a list of optimization passes being performed when 'clang -O1' is called like this:
> 
> llvm-as < /dev/null | opt -O1 -disable-output -debug-pass=Arguments
> Which results in:
> 
> Pass Arguments:  -no-aa -tbaa -targetlibinfo -basicaa -notti -preverify -domtree -verify -simplifycfg -domtree -sroa -early-cse -lower-expect
> Pass Arguments:  -targetlibinfo -no-aa -tbaa -basicaa -notti -globalopt -ipsccp -deadargelim -instcombine -simplifycfg -basiccg -prune-eh -inline-cost -always-inline -functionattrs -sroa -domtree -early-cse -simplify-libcalls -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -memcpyopt -sccp -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -adce -simplifycfg -instcombine -strip-dead-prototypes -preverify -domtree -verify
> 
> (BTW: why are there two Pass Arguments lists returned there?)
> 
This is because the middle-end and the backend are using a different PassManager (I don’t think there is any reason for doing this but that’s how it’s implemented in clang).

> Now my intent is to figure out which optimization pass is causing the problem by trying each one until I hit the same problem as with -O1, but clang itself doesn't seem to allow these commandline options, for example:
> 
> clang -loops -lcssa ....
> Results in:
> 
> clang: warning: -loops: 'linker' input unused
> clang: warning: -lcssa: 'linker' input unused
> 
> 
> (Makes sense as it conflicts with the -l command line opt) 
> So is there a way to pass these in on the command line? (or bonus if 
> there's a way to specify a file which contains a list of optimization 
> passes to perform)
> 
> Note: I realize there must be a way to break everything up into stages and use opt at some point and pass the optimization command line options to it, but I've got a pretty large set of Makefiles which would need to change to do that.
> 
> 

There is no way that I know of (but modifying the PassManagerBuilder and rebuilding clang). But you may start by bisecting the input files compiling half of them with O1 and the other half with O0 and recurse till you find the file that is miscompiled with O1. Then you can use opt to test variant of the pipeline on this file and relink manually.

— 
Mehdi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151202/5ce3b1d0/attachment.html>


More information about the cfe-dev mailing list