Check out my first novel, midnight's simulacra!

GCC: Difference between revisions

From dankwiki
Line 12: Line 12:
* <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 the <tt>__builtin_object_size</tt>'s correct functioning.
* <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.

Revision as of 08:04, 4 October 2009

Extensions to C

Extensions to the C language are documented at the online gcc docs, and in the Info pages distributed with gcc.

__builtin_ functions

  • __builtin_expect(expr,expectedp) - Instruct gcc that expr is or is not likely to be true (0 for unlikely), affecting generation of conditional code (normally, gcc assumes that if conditionals are taken in most/all cases).

Attributes

Attributes are preceded by the keyword __attribute__ and in some cases followed by a parenthesized argument list; the attribute name and any argument list are both then enclosed within double parentheses. All are non-standard extensions.

Function Attributes

  • See the gcc documentation at http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
  • aligned - takes a single parameter, the minimum number of bytes at which to align the function. -falign-functions will override this, if larger.
  • malloc - indicates that any value returned does not alias any other currently-valid pointers
  • alloc_size - 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 __builtin_object_size's correct functioning.
  • pure (2.96) - indicates that the function has no side-effects save its return value, which is based only on calls to other pure functions, the function's own parameters and/or non-volatile global memory.
  • const (2.5) - stronger than pure, a pure function which does not dereference any pointer parameters, use global memory or call non-const functions.
  • warn_unused_result - warn if the return value is not used, for instance in a wrapper to open(2) or malloc(3)
  • cold (4.3) - indicates the code does not lie on any hotpaths, resulting in optimization for size, location within the .text section, and automatic application of __builtin_expect((x),0) to conditionals on a calling path. Disabled by -fprofile-use.
  • hot (4.3) - opposite of cold.
  • nothrow (3.3) - marks the function as never throwing an exception, for optimization purposes.
  • noreturn (2.5) - marks the function as never normally returning (longjmp(3) and exceptions may still be used).
  • unused - a function is (possibly) unused. Calls may still be made to it, but -Wunused-functions warnings will not be generated.

Inline Assembly

Intermediate Representations

  • RTL: The Register Transfer Language, GCC's older IR (still used for late optimization passes)
  • GENERIC: A loose IR to which frontends must now compile
  • GIMPLE: A restricted subset of GENERIC, on which most optimizations are performed
  • Graphite: GIMPLE as Polyhedra, an optimization framework making use of polyhedral methods (especially for autovectorization)

See also