Phil Tomson via llvm-dev
2015-Dec-02 17:56 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
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?) 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151202/d86c2e75/attachment.html>
Mehdi Amini via llvm-dev
2015-Dec-02 18:14 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
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/llvm-dev/attachments/20151202/5ce3b1d0/attachment-0001.html>
David Chisnall via llvm-dev
2015-Dec-02 18:17 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On 2 Dec 2015, at 17:56, Phil Tomson via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > 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 .... > >If you want to pass LLVM arguments to clang, then you must prefix them with -llvm (e.g. -mllvm -loops -mllvm lcssa). David
Phil Tomson via llvm-dev
2015-Dec-02 18:30 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On Wed, Dec 2, 2015 at 10:17 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:> On 2 Dec 2015, at 17:56, Phil Tomson via llvm-dev <llvm-dev at lists.llvm.org> > wrote: > > > > 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 .... > > > > > > If you want to pass LLVM arguments to clang, then you must prefix them > with -llvm (e.g. -mllvm -loops -mllvm lcssa). > >I just tried this: CFLAGS += -mllvm adce -mllvm loops -mllvm loop-simplify -mllvm lcssa -mllvm simplify-libcalls And get: clang (LLVM option parsing): Unknown command line argument 'adce'. Try: 'clang (LLVM option parsing) -help' clang (LLVM option parsing): Unknown command line argument 'loops'. Try: 'clang (LLVM option parsing) -help' clang (LLVM option parsing): Unknown command line argument 'loop-simplify'. Try: 'clang (LLVM option parsing) -help' clang (LLVM option parsing): Unknown command line argument 'lcssa'. Try: 'clang (LLVM option parsing) -help' clang (LLVM option parsing): Unknown command line argument 'simplify-libcalls'. Try: 'clang (LLVM option parsing) -help'> David > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151202/7f8a6f0a/attachment.html>
Bill Seurer via llvm-dev
2015-Dec-02 18:42 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On 12/02/15 11:56, Phil Tomson via llvm-dev wrote:> 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.Using opt is the way to go. For your Makefile issue write your own "clang" script that is ahead of the real clang. Have it run clang/opt/llc for you and then you can easily change the optimization phases for opt. -- -Bill Seurer
serge guelton via llvm-dev
2015-Dec-02 19:09 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On Wed, Dec 02, 2015 at 12:42:44PM -0600, Bill Seurer via llvm-dev wrote:> On 12/02/15 11:56, Phil Tomson via llvm-dev wrote: > >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. > > Using opt is the way to go. > > For your Makefile issue write your own "clang" script that is ahead of the > real clang. Have it run clang/opt/llc for you and then you can easily > change the optimization phases for opt.If you're planning to call your own passes, you can also register them for clang use, as described in the tutorial we gave at LLVM DEV 2015. See for instance: https://github.com/quarkslab/llvm-dev-meeting-tutorial-2015/blob/master/MBA/MBA.cpp#L157