From cTuning.org
| Line 546: | Line 546: | ||
==== XML file structure ==== | ==== XML file structure ==== | ||
| - | Here's XML file structure used in Adapt plugin, defined in DTD syntax: | + | Here's XML file structure used in Adapt plugin, defined in DTD syntax ('''Draft'''): |
<pre> | <pre> | ||
<!ELEMENT ici (plugin, compiler, function)> | <!ELEMENT ici (plugin, compiler, function)> | ||
| Line 579: | Line 579: | ||
=== Fine-grain parameter tuning === | === Fine-grain parameter tuning === | ||
| + | ==== XML format ==== | ||
Parameters and other information for fine grain tuning is saved in the same XML files as parameter tuning, the structure of XML file is disribed with [[CTools:ICI:Projects:GSOC09:Fine_grain_tuning#XML_file_structure|DTD in pass recording/substitution sector]]. | Parameters and other information for fine grain tuning is saved in the same XML files as parameter tuning, the structure of XML file is disribed with [[CTools:ICI:Projects:GSOC09:Fine_grain_tuning#XML_file_structure|DTD in pass recording/substitution sector]]. | ||
| + | |||
| + | ==== Known issues ==== | ||
| + | * During loop-unroll optimization, wrong optimization heuristics might be applied to loops as a result of different loop id (<tt>loop->num</tt>) across compilations. | ||
| + | |||
| + | |||
| + | === Function specific optimization options === | ||
| + | |||
| + | Adapt plugin makes it possible to set function specific optimizations with XML files. The optimizations options is given in the same format as command line arguments, and represented in a plain character string tagged <tt><optimization_options></tt> in <tt><function></tt> tag. | ||
| + | |||
| + | ==== Known issues ==== | ||
| + | Function specific optimization options tuning is still experimental and cannot handle the following situation: | ||
| + | |||
| + | * If the command line optimization for the whole program is based on <tt>-O0</tt> or <tt>-O1</tt>, but a function is specified to be compiled with <tt>-O2</tt> or <tt>-O3</tt>, compilation will fail. | ||
Revision as of 12:51, 11 August 2009
Google Summer of Code 2009: fine-grain optimizations.
Yuanjie Huang (ICT, China)
This project aims to provide fine-grain optimization selection and tuning abilities in GCC, and thus enable GCC to tune default optimization heuristic of the compiler or fine optimizations for a given program on a given architecture entirely automatically using statistical and machine learning techniques from the MILEPOST project.
ICI Fine-grain tuning work flow
Coming soon...
ICI Events
ICI events added to the framework for fine-grain tuning are documented here.
| Name | Triggered in | Description |
|---|---|---|
| Passes Record/Substitution Events | ||
| "all_ipa_passes_start" | cgraphunit.c | This event is raised before executing GCC's IPA optimization passes. Currently unused. |
| "all_ipa_passes_execution" | cgraphunit.c | This event is raised just before executing GCC's IPA optimization passes. If this event's callback is successfully executed, and ici_ipa_passes_substitution_status</t> parameter, i.e. <tt>substitute_status ICI event parameter is set to non-zero value, GCC's default IPA passes will not be executed. |
| "all_ipa_passes_end" | cgraphunit.c | This event is raised just after executing GCC's IPA optimization passes. Currently used to instruct adapt plugin to stream recorded information into XML file. |
| "early_gimple_passes_start" | passes.c | This event is raised just before execute the first early local optimization pass, i.e. GIMPLE pass, in IPA passes. Currently used to send a recording heuristic to adapt plugin. |
| "early_gimple_passes_end" | passes.c | This event is raised just after execute the last early local optimization pass, i.e. GIMPLE pass, in IPA passes. Currently used to send a recording heuristic to adapt plugin. |
| "all_passes_start" | tree-optimize.c | This event is raised before executing GCC's optimization passes on function being compiled. Currently unused. |
| "all_passes_execution" | tree-optimize.c | This event is raised just before executing GCC's optimization passes on function being compiled. If this event's callback is successfully executed, and ici_passes_substitution_status parameter, i.e. substitute_status ICI event parameter is set to non-zero value, GCC's default passes will not be executed. |
| "all_passes_end" | tree-optimize.c | This event is raised just after executing GCC's optimization passes on function being compiled. Currently used to instruct adapt plugin to stream recorded information into XML file. |
| "avoid_gate" | passes.c | This event is raised after the GCC's default gate status is set and before the execution of a pass. Thus the gate status can be overridden by the plugin when handling this event. |
| "pass_execution" | passes.c | This event is raised after the gate status is determined. Warning: since functions generated by IPCP optimization would cause problems, pass execution event will not be raised if current_function_decl is set and DECL_ARTIFICIAL (current_function_decl) is non-zero. |
| Optimization Parameter Tuning Events | ||
| "graphite_parameter_handler" | graphite.c | This event is raised for when some event parameter should be recorded or loaded from plugin. |
| "unroll_parameter_handler" | loop-unroll.c | This event is raised for when some event parameter should be recorded or loaded from plugin. |
| Function Specific Optimizations Tuning Events | ||
| "function_spec_loader" | cgraphunit.c | Special Event in ici_load_function_specific_optimizations function, this event is raised for every function in call graph. |
| Extra info | ||
| "exmaple_event" | source.c | none |
ICI Features
New Features
ICI features added to the framework for fine-grain tuning are documented here.
| Feature name | Type of contents | Description |
|---|---|---|
| "main_input_filename" | array of strings, i.e., char ** | Name of the file which serves as the main input file of compiler . |
Known Issue of ICI 2.0 Features
- "function_filename" can be empty for functions generated by IPCP optimization (cp pass).
ICI Parameters
ICI Parameter with Type
ICI parameters now come with a type which should be declared when registering parameters in ICI, currently only a few basic C types are supported: void, char, unsigned char, int, unsigned int, long and unsigned long. A special type named EP_SILENT is introduced to pass parameters that is only used to pass status information to plugin; it's actually int, and is planned to be replaced by a elegant solution. The parameter type is defined in gcc/highlev-plugin-internal.h and gcc/highlev-plugin.h:
/* Datatype of event parameter pointer */
typedef enum
{
EP_SILENT,
EP_VOID,
EP_CHAR,
EP_UNSIGNED_CHAR,
EP_INT;
EP_UNSIGNED_INT,
EP_LONG,
EP_UNSIGNED_LONG
} event_parameter_type;
The representation of parameters is defined in file gcc/events.c:
/* Parameter structure. */
struct event_parameter
{
const char *name; /* Name for the parameter */
const void *value; /* Pointer to data */
event_parameter_type type; /* Type enumeration of value */
};
TODOs of ICI parameter
- Implement ICI control information with ICI features, and remove EP_SILENT type.
ICI API
Parameter Management
register_event_parameter: register a new ICI parameter
| Description
Define a new ICI parameter named name, with a pointer value to some data of type. Trigger an internal compiler error (failed assertion) if name is invalid. Prerequisites name can be neither NULL nor an empty string. <type> is a valid type defined in event_parameter_type. Outputs See also |
get_event_parameter_type: get the type of an ICI event parameter
| Description
Get the type of an event parameter. Trigger an internal compiler error if no parameters were registered prior to calling this function. Prerequisites Parameter hash table must have been initialized prior to calling this function. Outputs Informational message if parameters hash table does not exists. See also |
Pass Management
run_pass: run a pass
| Description
Execute the pass registered with name prior to calling this function on current function. Warning: IPA passes should not be execute with this function, use run_ipa_passinstead. Prerequisites A pass of the specified name has been registered prior to calling this function. Outputs none See also |
run_ipa_pass: run an IPA pass
| Description
Execute the IPA pass registered with name prior to calling this function on current function. Prerequisites An IPA pass of the specified name has been registered prior to calling this function. Outputs none See also |
initialize_ici_pass_list: initialize a list of passes for ICI batch execution
| Description
Initialize a list of NULL pointers of pass type. Prerequisites none Outputs none See also insert_ici_pass_list, run_ici_pass_list, run_ici_pass_list_per_function, delete_ici_pass_list |
insert_ici_pass_list: insert a pass into ICI pass list
| Description
Insert a pass named name into ICI pass list list at position specified by cursor, and then increase cursor by 1. Prerequisites An pass named name has been registered prior to calling this function. Outputs Informational message if the slot specified by cursor is not empty prior to calling this function. See also initialize_ici_pass_list, run_ici_pass_list, run_ici_pass_list_per_function, delete_ici_pass_list |
run_ici_pass_list: execute an ICI pass list on current function
| Description
Execute an ICI pass list list on function being compiled. Prerequisites List is not empty and current function is specified in GCC. Outputs none See also initialize_ici_pass_list, insert_ici_pass_list, run_ici_pass_list_per_function, delete_ici_pass_list |
run_ici_pass_list_per_function: execute an ICI pass list on current call graph
| Description
Execute an ICI pass list list on call graph functions one by one in 'top order'. Prerequisites List is not empty. Outputs none See also initialize_ici_pass_list, insert_ici_pass_list, run_ici_pass_list, delete_ici_pass_list |
delete_ici_pass_list: delete an ICI pass list
| Description
Delete an ICI pass list list. Prerequisites List is not empty. Outputs none See also initialize_ici_pass_list, insert_ici_pass_list, run_ici_pass_list, run_ici_pass_list_per_function |
Adapt Plugin
Description
Adapt plugin provides support for GCC pass sequence record/substitution, function-specific optimization tuning, function clone and instrumentation. Plugins developed for fine-grain tuning are documented here. These plugins are developed to work with ICI-2.0 interface.
HOWTO
Adapt plugin is depends on Mini-XML library, which provides XML reading and writing ability.
This plugin behaves differently depending on the ICI_ADAPT_CONTROL environmental variable, which can be either set to 1 to record information of current compilation into XML files or to 2 to reuse passes from XML files to perform passes substitution, function clone and other functionalities.
To use adapt plugin with ICI, ICI_PLUGIN environment variable should be set to the path to the plugin library (.so), and gcc should be called with with either -fici flag or ICI_USE environment parameter.
Pass recoding/substitution
Adapt plugin can be used to record or substite pass during compilation with information from XML files.
XML file structure
Here's XML file structure used in Adapt plugin, defined in DTD syntax (Draft):
<!ELEMENT ici (plugin, compiler, function)> <!ELEMENT plugin (plugin_name, plugin_version)> <!ELEMENT plugin_name (#PCDATA)> <!ELEMENT plugin_version (#PCDATA)> <!ELEMENT compiler (compiler_version)> <!ELEMENT compiler_version (#PCDATA)> <!ELEMENT function (optimizaton_options, (ipa_pass_list|gimple_pass_list)?)> <!ATTLIST function function_name #REQUIRED> <!ATTLIST function function_filename #REQUIRED> <!ATTLIST function function_start_line #IMPLIED> <!ATTLIST function function_end_line #IMPLIED> <!ELEMENT optimizaton_options (#PCDATA)> <!ELEMENT ipa_pass_list (pass*)> <!ELEMENT gimple_pass_list (pass*)> <!ELEMENT pass (parameter*, loop*)> <!ATTLIST pass pass_name #REQUIRED> <!ELEMENT loop (parameter*)> <!ATTLIST loop loop_id #REQUIRED> <!ELEMENT parameter (#PCDATA)>
Fine-grain parameter tuning
XML format
Parameters and other information for fine grain tuning is saved in the same XML files as parameter tuning, the structure of XML file is disribed with DTD in pass recording/substitution sector.
Known issues
- During loop-unroll optimization, wrong optimization heuristics might be applied to loops as a result of different loop id (loop->num) across compilations.
Function specific optimization options
Adapt plugin makes it possible to set function specific optimizations with XML files. The optimizations options is given in the same format as command line arguments, and represented in a plain character string tagged <optimization_options> in <function> tag.
Known issues
Function specific optimization options tuning is still experimental and cannot handle the following situation:
- If the command line optimization for the whole program is based on -O0 or -O1, but a function is specified to be compiled with -O2 or -O3, compilation will fail.

