GCC: Difference between revisions
→Useful flags: mention 10.1's -fanalyzer |
|||
| (11 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
==Useful flags== | |||
* <tt>-fmax-errors=n</tt> print a maximum of n errors, 0 (the default) being unbounded | |||
* <tt>-E</tt> to generate preprocessor output, <tt>-s</tt> to generate assembly output | |||
* <tt>-fanalyzer</tt> (since 10.1) to do rich static analysis [https://clearlinux.org/blogs-news/major-improvements-gcc-101 ClearLinux blog] | |||
==Optimization== | |||
* Use '''-Q -Ox --help=optimizers''' to determine which optimization flags are enabled for a given -Ox setting (or read the info pages). | |||
* [[Compiler Design|Dataflow analysis]] is only performed at -O2 or above, and thus at least this level of optimization is necessary for use-of-uninitialized-variable warnings and such. | |||
==Extensions to [[C]]== | ==Extensions to [[C]]== | ||
Extensions to the [[C]] language are documented at the [http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions online gcc docs], and in the Info pages distributed with gcc. | Extensions to the [[C]] language are documented at the [http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions online gcc docs], and in the Info pages distributed with gcc. | ||
| Line 12: | Line 20: | ||
* <tt>aligned</tt> - takes a single parameter, the minimum number of bytes at which to align the function. <tt>-falign-functions</tt> will override this, if larger. | * <tt>aligned</tt> - takes a single parameter, the minimum number of bytes at which to align the function. <tt>-falign-functions</tt> will override this, if larger. | ||
* <tt>malloc</tt> - indicates that any value returned does not [[Compiler Design|alias]] any other currently-valid pointers | * <tt>malloc</tt> - indicates that any value returned does not [[Compiler Design|alias]] any other currently-valid pointers | ||
* <tt>alloc_size</tt> - takes one or two parameters and indicates that the function will return a pointer to an allocated chunk of memory having either the size provided by a single argument, or the product of two arguments. This is necessary for | * <tt>alloc_size</tt> - takes one or two parameters and indicates that the function will return a pointer to an allocated chunk of memory having either the size provided by a single argument, or the product of two arguments. This is necessary for <tt>__builtin_object_size</tt>'s correct functioning. | ||
* <tt>pure</tt> (2.96) - indicates that the function has no side-effects save its return value, which is based only on calls to other <tt>pure</tt> functions, the function's own parameters and/or non-volatile global memory. | * <tt>pure</tt> (2.96) - indicates that the function has no side-effects save its return value, which is based only on calls to other <tt>pure</tt> functions, the function's own parameters and/or non-volatile global memory. | ||
* <tt>const</tt> (2.5) - stronger than <tt>pure</tt>, a <tt>pure</tt> function which does not dereference any pointer parameters, use global memory or call non-<tt>const</tt> functions. | * <tt>const</tt> (2.5) - stronger than <tt>pure</tt>, a <tt>pure</tt> function which does not dereference any pointer parameters, use global memory or call non-<tt>const</tt> functions. | ||
| Line 23: | Line 31: | ||
===Inline Assembly=== | ===Inline Assembly=== | ||
* There's no need to use inline assembly for [[SIMD]]; use [http://gcc.gnu.org/onlinedocs/gcc/Target-Builtins.html#Target-Builtins Target-Specific Builtins] and [http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html#Vector-Extensions Vector Extensions] | * There's no need to use inline assembly for [[SIMD]]; use [http://gcc.gnu.org/onlinedocs/gcc/Target-Builtins.html#Target-Builtins Target-Specific Builtins] and [http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html#Vector-Extensions Vector Extensions], or [http://gcc.gnu.org/projects/tree-ssa/vectorization.html autovectorization] if applicable. | ||
* Functions only referenced by inline assembly might not have code generated for them; use of the <tt>used</tt> [[GCC#Function_Attributes|function attribute]] will force generation. | * Functions only referenced by inline assembly might not have code generated for them; use of the <tt>used</tt> [[GCC#Function_Attributes|function attribute]] will force generation. | ||
* The [http://sourceware.org/binutils/docs/as/index.html GNU assembler] (gas) is used for assembly and syntax | * The [http://sourceware.org/binutils/docs/as/index.html GNU assembler] (gas) is used for assembly and syntax. | ||
* Statements can be arbitrarily reordered by default, or anchored with the <tt>volatile</tt> qualifier | |||
* outputs, inputs and clobbers are expressed in a colon-delimited list of comma-delimited lists of the form [''asmsymbol''] "''constraints''" (''c symbol'') | |||
** operand constraints are properties of the assembly code, not the values | |||
** without "=" or "+" constraint modifier, operands are assumed to be read-only | |||
** compiler verifies that all outputs are lvalues. types of operands are '''not''' checked. | |||
** "cc" logical register ought be listed as a clobber if the conditional code register is changed | |||
** "memory" must be listed as clobbered if memory is touched in an unpredictable fashion | |||
* constraint modifiers: | |||
** "=": operand is write-only (previous value needn't be preserved until write) | |||
** "+": operand is read-write (can't be arbitrarily used) | |||
** "&": operand is clobbered early (prior to use of all inputs), and thus can't be placed atop an input operand's | |||
==Intermediate Representations== | ==Intermediate Representations== | ||
* [http://gcc.gnu.org/onlinedocs/gccint/ | * [http://gcc.gnu.org/onlinedocs/gccint/RTL.html RTL]: The Register Transfer Language, GCC's older IR (still used for late optimization passes) | ||
* [http://gcc.gnu.org/onlinedocs/gccint/GENERIC.html#GENERIC GENERIC]: A loose IR to which frontends must now compile | * [http://gcc.gnu.org/onlinedocs/gccint/GENERIC.html#GENERIC GENERIC]: A loose IR to which frontends must now compile | ||
* [http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html#GIMPLE GIMPLE]: A restricted subset of GENERIC, on which most optimizations are performed | * [http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html#GIMPLE GIMPLE]: A restricted subset of GENERIC, on which most optimizations are performed | ||
| Line 39: | Line 58: | ||
* "[http://www.cs.lth.se/home/Jonas_Skeppstedt/kongstad.pdf An Implementation of Global Value Numbering in the GNU Compiler Collection, with Performance Measurements]" (Kongstad 2004) | * "[http://www.cs.lth.se/home/Jonas_Skeppstedt/kongstad.pdf An Implementation of Global Value Numbering in the GNU Compiler Collection, with Performance Measurements]" (Kongstad 2004) | ||
* [http://gcc.gnu.org/onlinedocs/gccint/ GNU Compiler Collection Internals] | * [http://gcc.gnu.org/onlinedocs/gccint/ GNU Compiler Collection Internals] | ||
* [[Core]] files | |||
* [[Questions]] | |||