Phil Tomson via llvm-dev
2015-Dec-02 19:00 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On Wed, Dec 2, 2015 at 10:39 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:> On 2 Dec 2015, at 18:30, Phil Tomson <phil.a.tomson at gmail.com> wrote: > > > >> 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' > > Sorry, I wasn’t thinking. These are options provided by opt, not by LLVM > libraries. Clang has made an explicit design decision not to expose the > optimisation pipeline details to consumers (because it’s far from stable > and there is no desire to maintain backwards compatibility for things that > are implementation details and because it’s very hard for someone to use > correctly). Your best bet if you *really* want this is probably to wrap > clang in a shell script that does something along the lines of clang -c > -emit-llvm && opt -whatever | llc, with appropriate handling / replacing of > the last -o argument to clang. >I have a feeling this would get rather tricky given that there are several libraries linked in to the final executable as well. It would have to look something like: clang -c file.c -emit-llvm > opt -... > llc ... > as > ld (libs to link in) Someone above mentioned modifying PassManagerBuilder and rebuilding clang - I'd guess there's a list of optimization passes performed somewhere that PassManagerBuilder references, but I haven't been in the optimization pass area of LLVM much yet. Any pointers on that approach? Phil> > David > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151202/7ade0e60/attachment.html>
Mehdi Amini via llvm-dev
2015-Dec-02 19:05 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
> On Dec 2, 2015, at 11:00 AM, Phil Tomson via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > > On Wed, Dec 2, 2015 at 10:39 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk <mailto:David.Chisnall at cl.cam.ac.uk>> wrote: > On 2 Dec 2015, at 18:30, Phil Tomson <phil.a.tomson at gmail.com <mailto:phil.a.tomson at gmail.com>> wrote: > > > >> 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' > > Sorry, I wasn’t thinking. These are options provided by opt, not by LLVM libraries. Clang has made an explicit design decision not to expose the optimisation pipeline details to consumers (because it’s far from stable and there is no desire to maintain backwards compatibility for things that are implementation details and because it’s very hard for someone to use correctly). Your best bet if you *really* want this is probably to wrap clang in a shell script that does something along the lines of clang -c -emit-llvm && opt -whatever | llc, with appropriate handling / replacing of the last -o argument to clang. > > I have a feeling this would get rather tricky given that there are several libraries linked in to the final executable as well. It would have to look something like: > > clang -c file.c -emit-llvm > opt -... > llc ... > as > ld (libs to link in) > > Someone above mentioned modifying PassManagerBuilder and rebuilding clang - I'd guess there's a list of optimization passes performed somewhere that PassManagerBuilder references, but I haven't been in the optimization pass area of LLVM much yet. Any pointers on that approach?Fairly trivial, have a look at http://llvm.org/docs/doxygen/html/PassManagerBuilder_8cpp_source.html#l00186 and http://llvm.org/docs/doxygen/html/PassManagerBuilder_8cpp_source.html#l00165 If could can see how “OptLevel” impacts what is done. — Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151202/89540cc3/attachment.html>
David Chisnall via llvm-dev
2015-Dec-02 19:06 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On 2 Dec 2015, at 19:00, Phil Tomson <phil.a.tomson at gmail.com> wrote:> > I have a feeling this would get rather tricky given that there are several libraries linked in to the final executable as well. It would have to look something like: > > clang -c file.c -emit-llvm > opt -... > llc ... > as > ld (libs to link in)You don’t need as (llc can emit .o files). Hopefully, your build system has different CC / CXX / LD values, so the final link is separate too.> Someone above mentioned modifying PassManagerBuilder and rebuilding clang - I'd guess there's a list of optimization passes performed somewhere that PassManagerBuilder references, but I haven't been in the optimization pass area of LLVM much yet. Any pointers on that approach?You can take a look in BackendUtil.cpp for how the passes are constructed for clang. Note that it is quite complex and depends a lot on your language options... David
Phil Tomson via llvm-dev
2015-Dec-04 18:18 UTC
[llvm-dev] Is there a way to pass Optimization passes to clang?
On Wed, Dec 2, 2015 at 11:06 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:> On 2 Dec 2015, at 19:00, Phil Tomson <phil.a.tomson at gmail.com> wrote: > > > > I have a feeling this would get rather tricky given that there are > several libraries linked in to the final executable as well. It would have > to look something like: > > > > clang -c file.c -emit-llvm > opt -... > llc ... > as > ld (libs to link > in) > > You don’t need as (llc can emit .o files).How do you get llc to emit a .o file (I seem to only be able to get it to output a .s file)?> Hopefully, your build system has different CC / CXX / LD values, so the > final link is separate too. >> > > Someone above mentioned modifying PassManagerBuilder and rebuilding > clang - I'd guess there's a list of optimization passes performed somewhere > that PassManagerBuilder references, but I haven't been in the optimization > pass area of LLVM much yet. Any pointers on that approach? > > You can take a look in BackendUtil.cpp for how the passes are constructed > for clang. Note that it is quite complex and depends a lot on your > language options... > > David > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151204/a79db2b4/attachment.html>