Hi devels, there are two issues concerning invoking optimizations: 1. this document: http://llvm.cs.uiuc.edu/docs/GettingStarted.html is very nice, it would be good though to add in a section An Example Using the LLVM Tool Chain examples on optimization step. 2. If i am not wrong there is no tool, which integrates all steps: llvmgcc->opt->llc into something like llcc (and llvmg++->opt->llc into something like ll++), where options -O1, -O2, -O3 are available. For example, `llcc -O3 ackerman.c' should make similar (but better!) things as `gcc -O3 ackerman.c' does. Anyway, it would be good to have a starting point for those who'd like to try "fully LLVM-optimized" C/C++ code. Indeed, the tool "opt" has quite big set of options... best regards, --- Valery A.Khamenya
On Sat, 1 May 2004, [koi8-r] "Valery A.Khamenya[koi8-r] " wrote:> there are two issues concerning invoking optimizations: > > 1. > this document: > http://llvm.cs.uiuc.edu/docs/GettingStarted.html > is very nice, it would be good though to add in a section > > An Example Using the LLVM Tool Chain > > examples on optimization step.That's an interesting idea. LLVM currently enables the maximal optimizations by default, you can only disable options. For example, you can use -Wl,-disable-inlining to disable the link-time inliner, or -Wl,-disable-opt to disable all link-time optimizations. Unfortunately we don't have a centralized place that lists all of the optimizations that can be disabled (this should be added to the command guide), but you can see them by using 'gccas --help' or 'gccld --help'. To disable a gccas option, use -Wa,-disable-foo, for gccld, use -Wl,-disable-foo on the llvmgcc command line. Additionally, you can use opt to run individual optimizations, of which there are a lot. :) I added the following patch to the GSG. If you have a better suggestion, please let me know: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040426/014073.html> 2. > If i am not wrong there is no tool, which integrates all > steps: > > llvmgcc->opt->llc into something like llcc > (and llvmg++->opt->llc into something like ll++), > where options -O1, -O2, -O3 are available. For example, > `llcc -O3 ackerman.c' should make similar (but better!) > things as `gcc -O3 ackerman.c' does.You should be able to do this with the gccld -native or -native-cbe options: For example: $ llvmgcc ackerman.c -o ackerman -Wl,-native-cbe ... compiles to a native 'ackerman' executable, using the C backend. These are link-time options, so you can compile any way you normally would, for example by using 'llvmgcc -c x.c -o x.o', as long as the flag gets passed in when the program is linked. If you use the -native option, it uses LLC, though it doesn't turn on Alkis's nice register allocator. If you want to enable the linearscan allocator with the -native option, you currently have to hack llvm/tools/gccld/GenerateCode.cpp:GenerateAssembly to pass in the '-regalloc=linearscan' option. When this allocator is completely stable, we will enable it by default.> Anyway, it would be good to have a starting point for those who'd like > to try "fully LLVM-optimized" C/C++ code. Indeed, the tool "opt" has > quite big set of options...Yup, it looks like opt has 75 optimizer passes available in it right now. :) If you start playing with them, make sure to avoid the "experimental optimizations", which are not likely to work well: http://llvm.cs.uiuc.edu/docs/ReleaseNotes.html#experimental LLVM really needs an optimizer guide that lists the various optimizations, the high-level overview of what they do, the algorithms used, useful-to-know-about interactions between passes (e.g. a pass that leaves around a lot of unpropagates constants), and when they are likely to be useful (most of this information is available in the comments at the top of the file for the optimization). This has been on my TODO list for about 2.5 years now, but I have a *very* long TODO list. :) Here are some examples of the header comments: http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=1.5&content-type=text/x-cvsweb-markup http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=1.16&content-type=text/x-cvsweb-markup http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/LICM.cpp?rev=1.59&content-type=text/x-cvsweb-markup http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/Reassociate.cpp?rev=1.30&content-type=text/x-cvsweb-markup http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=1.13&content-type=text/x-cvsweb-markup -Chris -- http://llvm.cs.uiuc.edu/ http://www.nondot.org/~sabre/Projects/
Chris Lattner wrote:> On Sat, 1 May 2004, [koi8-r] "Valery A.Khamenya[koi8-r] " wrote: > > >>there are two issues concerning invoking optimizations: >> >>1. >>this document: >> http://llvm.cs.uiuc.edu/docs/GettingStarted.html >>is very nice, it would be good though to add in a section >> >> An Example Using the LLVM Tool Chain >> >>examples on optimization step. > > > That's an interesting idea. LLVM currently enables the maximal > optimizations by default, you can only disable options. For example, you > can use -Wl,-disable-inlining to disable the link-time inliner, or > -Wl,-disable-opt to disable all link-time optimizations. Unfortunately we > don't have a centralized place that lists all of the optimizations that > can be disabled (this should be added to the command guide), but you can > see them by using 'gccas --help' or 'gccld --help'. To disable a gccas > option, use -Wa,-disable-foo, for gccld, use -Wl,-disable-foo on the > llvmgcc command line. > > Additionally, you can use opt to run individual optimizations, of which > there are a lot. :) > > I added the following patch to the GSG. If you have a better suggestion, > please let me know: > http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040426/014073.html > > >>2. >>If i am not wrong there is no tool, which integrates all >>steps: >> >>llvmgcc->opt->llc into something like llcc >>(and llvmg++->opt->llc into something like ll++), >>where options -O1, -O2, -O3 are available. For example, >>`llcc -O3 ackerman.c' should make similar (but better!) >>things as `gcc -O3 ackerman.c' does. > > > You should be able to do this with the gccld -native or -native-cbe > options:Just to clarify, because I think it can be easily overlooked: The gccas and gccld programs are not just assemblers/linkers; they are also optimizers too. gccas runs optimizations after assembling the file, and gccld runs interprocedural optimizations at link time. This is why you don't need to use the opt program when using llvm-gcc and llvm-g++; gccld and gccas run the optimizations for you. Contrast this to llvm-as and llvm-link: they do not do any optimization (that I am aware of). They only assemble and link LLVM code. -- John T.> > For example: > $ llvmgcc ackerman.c -o ackerman -Wl,-native-cbe > > ... compiles to a native 'ackerman' executable, using the C backend. These > are link-time options, so you can compile any way you normally would, for > example by using 'llvmgcc -c x.c -o x.o', as long as the flag gets passed > in when the program is linked. > > If you use the -native option, it uses LLC, though it doesn't turn on > Alkis's nice register allocator. If you want to enable the linearscan > allocator with the -native option, you currently have to hack > llvm/tools/gccld/GenerateCode.cpp:GenerateAssembly to pass in the > '-regalloc=linearscan' option. When this allocator is completely stable, > we will enable it by default. > > >>Anyway, it would be good to have a starting point for those who'd like >>to try "fully LLVM-optimized" C/C++ code. Indeed, the tool "opt" has >>quite big set of options... > > > Yup, it looks like opt has 75 optimizer passes available in it right now. > :) If you start playing with them, make sure to avoid the "experimental > optimizations", which are not likely to work well: > http://llvm.cs.uiuc.edu/docs/ReleaseNotes.html#experimental > > LLVM really needs an optimizer guide that lists the various > optimizations, the high-level overview of what they do, the algorithms > used, useful-to-know-about interactions between passes (e.g. a pass that > leaves around a lot of unpropagates constants), and when they are likely > to be useful (most of this information is available in the comments at > the top of the file for the optimization). This has been on my TODO list > for about 2.5 years now, but I have a *very* long TODO list. :) > > Here are some examples of the header comments: > http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=1.5&content-type=text/x-cvsweb-markup > http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=1.16&content-type=text/x-cvsweb-markup > http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/LICM.cpp?rev=1.59&content-type=text/x-cvsweb-markup > http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/Reassociate.cpp?rev=1.30&content-type=text/x-cvsweb-markup > http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=1.13&content-type=text/x-cvsweb-markup > > -Chris >-- ********************************************************************* * John T. Criswell Email: criswell at uiuc.edu * * Research Programmer * * University of Illinois at Urbana-Champaign * * * * "It's today!" said Piglet. "My favorite day," said Pooh. * *********************************************************************
hi all, well, i have set up proper command line parameters for for C-Shootout tests to get reasonable running time for benchmarking. I have compared "gcc -O3" and "llvmgcc -Wl,-native-cbe" here goes output (which shows that llvm is already better for test with intensive function calls): time -p ./gcc_ackermann 11 user 2.36 time -p ./llvm_ackermann 11 user 1.07 ---- time -p ./gcc_ary3 300000 user 2.86 time -p ./llvm_ary3 300000 user 3.19 ---- time -p ./gcc_fib2 39 user 2.32 time -p ./llvm_fib2 39 user 1.61 ---- time -p ./gcc_hash 1000000 user 2.26 time -p ./llvm_hash 1000000 user 2.30 ---- time -p ./gcc_heapsort 2000000 user 2.57 time -p ./llvm_heapsort 2000000 user 3.26 ---- time -p ./gcc_lists 500000 user 2.70 time -p ./llvm_lists 500000 user 3.27 ---- time -p ./gcc_matrix 500000 user 2.61 time -p ./llvm_matrix 500000 user 4.17 ---- time -p ./gcc_methcall 90000000 user 2.83 time -p ./llvm_methcall 90000000 user 2.89 ---- time -p ./gcc_nestedloop 33 user 2.40 time -p ./llvm_nestedloop 33 user 3.66 ---- time -p ./gcc_objinst 10000000 user 2.25 time -p ./llvm_objinst 10000000 user 2.12 ---- time -p ./gcc_random 60000000 user 2.42 time -p ./llvm_random 60000000 user 2.42 ---- time -p ./gcc_sieve 25000 user 2.41 time -p ./llvm_sieve 25000 user 4.36 ---- time -p ./gcc_strcat 50000000 user 2.77 time -p ./llvm_strcat 50000000 user 3.98
> For example: > $ llvmgcc ackerman.c -o ackerman -Wl,-native-cbeBTW, Chris, what should be then an analogy of "gcc -O3 -S foo.c" in LLVM framework? The invocation of $ llvmgcc -S ackerman.c -o ackerman -Wl,-native-cbe does not produce native assebler output as one might expect. -- Valery