Function Level Control of Optimizations
- GCC currently supports a wide range of optimizations, not all of which are beneficial all of the time. This project intends to allow the selection of individual optimizations to be chosen on a per-function basis in the source file being compiled. This will allow specific optimizations to be enabled where they are needed but not where they cause a degredation in performance. It is intended that this new feature will be used in conjunction with a simulator like
http://sourceware.org/sid/ which can allow profiling on a per-function basis, together with a meta-optimizer like http://www.coyotegulch.com/products/acovea/ which will allow the determination of the best optimizations to be used for each function.
Personnel
- D. Brolley
- N. Clifton
Delivery Date
- Near future.
Benefits
- Better control over optimizations which should lead to improved performance of generated code.
Dependencies
- None.
Modifications Required
- A new function attribute is needed that can either specify the optimizations to be enabled directly, or else point to an external file where the optimizations are recorded. A syntax will be needed for this file so that it can contain differentiated optimizations for individual functions. Tweaking of GCC's switch recording flags may also be needed.
Note
This feature is implemented in branches/apple-local-200502-branch using #pragma. Search for "APPLE LOCAL <blah> optimization pragma" string in source code.
- This feature is also implemented (but not documented) in the mainline code as a side effect of the *#pragma GCC diagnostic*. Status Report, 19 April 2006:
We now have a patch that implements the attribute and allows extra switches to not only be obtained from the attribute's text, but also read in from a file via the presence of a *@<file>* switch in the text. Work still to be done before submission includes:
- Parse the function attribute at function compilation time not function parse time.
- Add new switches to allow the current state of all switches to be pushed and popped.
- Add a new switch to automatically get extra per-function optimization switches from a file, obliviating the need for the function attribute. Create a syntax specification for this file.
- Integrate the patch with the #pragmas so that both approaches work and, where possible, share the same code.
- Status Report, 4 May 2006:
- The patch now parsers the new options at function compile time. The need for switches to push and pop the current state of the optimizations has been eliminated as the code now completely restores the optimization state at the end of compilation of any particular function. This also been tested to work with nested functions. The patch has been shown not to interfere with the code for *#pragma GCC diagnostic*, although its functionality is different. The patch applies per-function optimizations that are evaluated at function compile time, whereas the pragma (can be used to) applies global optimizations that are evaluated at source code parse time.
Support for a new switch *--per-function-extra-switches-from=<file>* has been added to the patch. This switch loads per-function optimizations from a named file. A very simple syntax allows multiple options to be specified for multiple functions. Regular expressions are not supported in this file however. The advantage of this switch is that the source code file for the function(s) to be further optimized does not have to be modified. Apart from more testing, nothing remains to be done to this patch. When the GCC mainline sources are re-opned for new features it will be submitted.
A spin-off patch was developed as part of this project which adds another new switch to the compiler: *--print-optimizers*. This switch tells the compiler to display a list of optimization options that it supports, and to show which are currently enabled. This will allow a tool like acovea to automatically discover the range of options that it ought to be considering. The patch is archived here http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00157.html, but will not be officially submitted until the mainline GCC sources are re-opened for new features.
The --print-optimizers patch has been resubmitted now that the gcc mainline sources are out of stage 3: http://gcc.gnu.org/ml/gcc-patches/2006-11/msg01866.html. It appears that the patch will be rejected however, in favour of putting the print-optimizers functionality into the --help switch.
- The patch now parsers the new options at function compile time. The need for switches to push and pop the current state of the optimizations has been eliminated as the code now completely restores the optimization state at the end of compilation of any particular function. This also been tested to work with nested functions. The patch has been shown not to interfere with the code for *#pragma GCC diagnostic*, although its functionality is different. The patch applies per-function optimizations that are evaluated at function compile time, whereas the pragma (can be used to) applies global optimizations that are evaluated at source code parse time.
- Status Report, 4 May 2006: