_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
On Apr 10, 2017, at 5:21 PM, Craig Topper via llvm-dev <llvm...@lists.llvm.org> wrote:clang -O0 does not disable all optimization passes modify the IR.; In fact it causes most functions to get tagged with noinline to prevent inlinining
What you really need to do isclang -O3 -c emit-llvm -o source.bc -vFind the -cc1 command line from that output. Execute that command with --disable-llvm-passes. leave the -O3 and everything else.
clang -O0 adds a "optnone" attribute to each function that causes most
optimization passes to skip that function. Avoid with "-Xclang
-disable-O0-optnone".
Michael
Author: Mehdi Amini <joke...@gmail.com>
Date: Mon May 29 05:38:20 2017 +0000
IRGen: Add optnone attribute on function during O0
Amongst other, this will help LTO to correctly handle/honor files
compiled with O0, helping debugging failures.
It also seems in line with how we handle other options, like how
-fnoinline adds the appropriate attribute as well.
Differential Revision: https://reviews.llvm.org/D28404
What I am trying is to compile a program with different sets of optimization flags.If there is no fine-grained control over clang optimization flags, it would be impossible to achieve what I intend.
@Sean, here is my summary of several tools.Format: (ID,tool, input->output, timing, customization, questions)1. llc, 1 bc -> 1 obj, back-end compile-time (code generation and machine-dependent optimizations), Difficult to customize pipeline, N/A2. LLD: all bc files and obj files -> 1 binary (passing -flto to clang for *.bc file generation), back-end link-time optimizations and code generations and machine-dependent optimizations, Easy to customize pipeline w/ -lto-newpm-passes, what is the connection between -lto-newpm-passes and -lto-newpm-aa-pipeline and how to use -lto-newpm-passes to customize pipeline?
3. gold: mixed obj files and bc files -> 1 binary (passing -flto to clang for *.bc file generation), back-end link-time optimization w/ LLVMgold.so and code generation and machine-dependent optimizations, unaware of whether it is customizable by means of command line options, can we consider LLD a more customizable gold from perspective of pipeline customization?
4. opt, 1 bc file -> 1 file at a time, middle-end machine-independent (may be others?), Easy to customize pipeline by means of command line options, N/A5. llvm-link, many *bc file -> 1 bc file, link-time (unknown whether there is any optimization) and Unknown why it exists, unknown how to do customization, N/A
With above understandings, there are several ways to fine-grained tune clang/llvm optimization pipeline:1. clang (c/c++ to bc translation, with minimal front-end optimizations, w/ -emit-llvm -O1 -Xclang -disable-llvm-passes), --> opt (w/ customizable middle-end optimizations for each bc file independently) --> gold (un-customizable back-end link-time optimization and code generation)2. clang (c/c++ to bc translation, with minimal front-end optimizations, w/ -flto) -->opt ( same as 1) --> lld (w/ -lto-newpm-passes for link-time optimization pipeline customization, how?)3. clang (c/c++ to *bc translation and optimization, customizable by mean of clang command-line options, maybe including both front-end optimization and middle-end optimizations). W/O explicitly specifying opt optimization pipeline, there may still be middle-end optimizations happening; also w/o explicitly specifying linker, it may use GNU ld / GNU gold / lld as the linker and with whichever's default link-time optimization pipeline.So, it seems to me that 2 is the most customizable pipeline, with customizable middle-end and back-end pipeline independently,
On Jan 7, 2018 8:46 PM, "toddy wang" <wenwan...@gmail.com> wrote:@Sean, here is my summary of several tools.Format: (ID,tool, input->output, timing, customization, questions)1. llc, 1 bc -> 1 obj, back-end compile-time (code generation and machine-dependent optimizations), Difficult to customize pipeline, N/A2. LLD: all bc files and obj files -> 1 binary (passing -flto to clang for *.bc file generation), back-end link-time optimizations and code generations and machine-dependent optimizations, Easy to customize pipeline w/ -lto-newpm-passes, what is the connection between -lto-newpm-passes and -lto-newpm-aa-pipeline and how to use -lto-newpm-passes to customize pipeline?You just specify the list of passes to run, as you would to opt -passes-lto-newpm-aa-pipeline has the same function as opt's -aa-pipeline option.
3. gold: mixed obj files and bc files -> 1 binary (passing -flto to clang for *.bc file generation), back-end link-time optimization w/ LLVMgold.so and code generation and machine-dependent optimizations, unaware of whether it is customizable by means of command line options, can we consider LLD a more customizable gold from perspective of pipeline customization?Gold and LLD are very similar for this purpose, and LLD has some extra goodies like -lto-newpm-passes
4. opt, 1 bc file -> 1 file at a time, middle-end machine-independent (may be others?), Easy to customize pipeline by means of command line options, N/A5. llvm-link, many *bc file -> 1 bc file, link-time (unknown whether there is any optimization) and Unknown why it exists, unknown how to do customization, N/Allvm-link doesn't perform optimizations.
With above understandings, there are several ways to fine-grained tune clang/llvm optimization pipeline:1. clang (c/c++ to bc translation, with minimal front-end optimizations, w/ -emit-llvm -O1 -Xclang -disable-llvm-passes), --> opt (w/ customizable middle-end optimizations for each bc file independently) --> gold (un-customizable back-end link-time optimization and code generation)2. clang (c/c++ to bc translation, with minimal front-end optimizations, w/ -flto) -->opt ( same as 1) --> lld (w/ -lto-newpm-passes for link-time optimization pipeline customization, how?)3. clang (c/c++ to *bc translation and optimization, customizable by mean of clang command-line options, maybe including both front-end optimization and middle-end optimizations). W/O explicitly specifying opt optimization pipeline, there may still be middle-end optimizations happening; also w/o explicitly specifying linker, it may use GNU ld / GNU gold / lld as the linker and with whichever's default link-time optimization pipeline.So, it seems to me that 2 is the most customizable pipeline, with customizable middle-end and back-end pipeline independently,The thing customized by -lto-newpm-passes is actually a middle-end pipeline run during link time optimization. The backend is not very customizable.Also, note that with a clang patch like the one I linked, you don't need opt because you can directly tell clang what fine-grained set of passes to run in the middle end.
One approach I have used in the past is to compile with -flto -O0 -disable-O0-optnone and then do all optimizations at link time. This can simplify things because you only need to re-run the link command (it still takes a long time, but with sufficient ram (and compiling without debug info) you should be able to run multiple different pass pipelines in parallel).
If your only goal is to test middle-end pass pipelines (e.g. synergies of different passes) then that can be a good approach. However, keep in mind that this is really just a small part of the larger design problem of getting the best code with the best compile time. In practice, profile feedback (and making good use of it), together with accurate cost modeling (especially in the middle end for optimizations like inlining and loop unrolling), together with appropriate link-time cross-module optimization tend to matter just as much (or more) than a particularly intelligently chosen sequence of passes.
-mllvm <value> Additional arguments to forward to LLVM's option processingThis is dumped by clang. I am not sure what I am supposed to put as value in order to tune unrolling/inlining threshold.
Hi Medhi,It seems -mllvm does not work as expected. Anything wrong?[twang15@c92 temp]$ clang++ -O3 -mllvm -deadargelim LULESH.ccclang (LLVM option parsing): Unknown command line argument '-deadargelim'. Try: 'clang (LLVM option parsing) -help'clang (LLVM option parsing): Did you mean '-regalloc'?[twang15@c92 temp]$ clang++ -O3 -mllvm deadargelim LULESH.ccclang (LLVM option parsing): Unknown command line argument 'deadargelim'. Try: 'clang (LLVM option parsing) -help'
2018-01-08 8:41 GMT-08:00 toddy wang <wenwan...@gmail.com>:Hi Medhi,It seems -mllvm does not work as expected. Anything wrong?[twang15@c92 temp]$ clang++ -O3 -mllvm -deadargelim LULESH.ccclang (LLVM option parsing): Unknown command line argument '-deadargelim'. Try: 'clang (LLVM option parsing) -help'clang (LLVM option parsing): Did you mean '-regalloc'?[twang15@c92 temp]$ clang++ -O3 -mllvm deadargelim LULESH.ccclang (LLVM option parsing): Unknown command line argument 'deadargelim'. Try: 'clang (LLVM option parsing) -help'You can't schedule passes this way, only set parameters like -unroll-threshold=<uint> etc.
On Mon, Jan 8, 2018 at 11:53 AM, Mehdi AMINI <joke...@gmail.com> wrote:2018-01-08 8:41 GMT-08:00 toddy wang <wenwan...@gmail.com>:Hi Medhi,It seems -mllvm does not work as expected. Anything wrong?[twang15@c92 temp]$ clang++ -O3 -mllvm -deadargelim LULESH.ccclang (LLVM option parsing): Unknown command line argument '-deadargelim'. Try: 'clang (LLVM option parsing) -help'clang (LLVM option parsing): Did you mean '-regalloc'?[twang15@c92 temp]$ clang++ -O3 -mllvm deadargelim LULESH.ccclang (LLVM option parsing): Unknown command line argument 'deadargelim'. Try: 'clang (LLVM option parsing) -help'You can't schedule passes this way, only set parameters like -unroll-threshold=<uint> etc.Where can I find options like -unroll-threshold=<uint>? I cannot find it in either opt -help or clang -help.
Thanks, Craig.So, clang -Xclang -disable-llvm-passes actually disables all the LLVM passed populated by clang so that there is no middle-end optimization on bc files.clang -O2 LULESH.c //clang is the driver, invoking cc1, cc1as, ld//options can be passed through to cc1 directly.//maybe have different names, e.g. -fvectorize in clang driver and -vectorize-loops in clang -cc1//options are dumped by clang -help and clang --help-hiddenclang -cc1 // c/c++ frontend is also referred as clang// this is the c/c++ frontend(preprocessor + Lexer + parser) and middle-end ( LLVM-IR optimizer + IR-assembly generator)//controlled by -Xclang <options>, Xclang options dumped by clang -cc1 -help//mllvm Options like -unroll-max count are controlled by -mllvm <options>.//mllvm Options can be dumped by clang -v -help -mllvm and clang -v --help-hidden//Question: are all mllvm options for middle-end while Xclang options are for front-end?