From cTuning.org
Current revision (19:42, 20 November 2009) (view source) |
|||
| (33 intermediate revisions not shown.) | |||
| Line 1: | Line 1: | ||
'''Google Summer of Code 2009: fine-grain optimizations.''' | '''Google Summer of Code 2009: fine-grain optimizations.''' | ||
| - | Yuanjie Huang (ICT, China) | + | [[User:Huangyuanjie | 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. | 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. | ||
* [http://socghop.appspot.com/org/home/google/gsoc2009/gcc GSOC'09 project description] | * [http://socghop.appspot.com/org/home/google/gsoc2009/gcc GSOC'09 project description] | ||
| - | |||
* [http://groups.google.com/group/ctuning-discussions cTuning development mailing list] | * [http://groups.google.com/group/ctuning-discussions cTuning development mailing list] | ||
| + | * SVN repository hosted on SourceForge.net® <pre style="display:inline;padding:0;border:0;background-color:#FFF">http://gcc-ici.svn.sourceforge.net/viewvc/gcc-ici/branches/</pre> | ||
| + | <!-- as Geeknet requires their logo to be displayed, I took the laziest solution: remove text link --> | ||
| - | |||
| - | + | == ICI Fine-Grain Tuning Overview == | |
| - | + | ||
| - | [[Image:ICI-adapt-record.gif|thumb|Compilation recording information to XML]] | + | [[Image:ICI-adapt-record-2.gif|thumb|Compilation recording information to XML]] |
| - | [[Image:ICI-adapt-reuse.gif|thumb|Compilation reusing information from XML]] | + | [[Image:ICI-adapt-reuse-2.gif|thumb|Compilation reusing information from XML]] |
| + | |||
| + | === Key Concepts === | ||
| + | |||
| + | This fine grain tuning project is an extension to ICI-2.0, and follows [[CTools:ICI:Concept | the concepts of ICI]]. | ||
| + | |||
| + | === Work Flow === | ||
| + | |||
| + | GCC fine-grain tuning projects brings two modes to GCC: '''record''' mode and the '''reuse''' mode. | ||
| + | |||
| + | In the record mode, information on compilation is recorded. Currently XML files are generated to log passes executed on each function, and parameters for several ICI-enabled passes, which describe the characteristic of the program being compiled and the internal decision making process of GCC. | ||
| + | |||
| + | Then the recorded information could be modified by machine learning algorithms or iterative seach engine, and loaded while compiling the program again in '''reuse''' mode. Thus internal heuristics are overridden, and GCC yields differently optimized code. | ||
| + | |||
| + | The work flow of ICI fine-grain tuning project on GCC 4.4 is illustrated in the two figures on the right. | ||
| + | |||
| + | === Future Work === | ||
| + | |||
| + | * Provide a flexible yet easy-to-use mechanism to represent the compilation work flow and ICI control, and remove EP_SILENT type from [[#ICI_Parameter_with_Type | ICI fine-grain tuning parameter types]]. | ||
| + | * Enable fine grain tuning in more GCC optimization passes. | ||
| + | * Develop a tool to translate function specific optimization options into pass and optimizations parameters. | ||
<br style="clear: both" /> | <br style="clear: both" /> | ||
== ICI Events == | == ICI Events == | ||
| - | |||
| + | [[Image:ICI-adapt-events-1.gif|thumb|Compilation recording information to XML]] | ||
| + | |||
| + | ICI events are used to stop normal compilation flow of GCC and execute callback function from ICI plugin. ICI Events for fine-grain tuning are shown in the figure on the right. | ||
| + | <!-- TODO: update figure to show function specific optimization options tuning event --> | ||
| + | |||
| + | <br style="clear: both" /> | ||
| + | {| border="1" cellspacing="0" cellpadding="3" style="text-align:left; width:100%;" | ||
| + | |+ ''''New ICI Events for Fine-Grain Tuning'''' | ||
| + | ! Name !! Triggered in !! Description | ||
| + | |- | ||
| + | ! colspan="3" style="background-color:silver;" | Passes Record/Substitution Events | ||
| + | |- | ||
| + | ! "all_ipa_passes_start" | ||
| + | | <tt>cgraphunit.c</tt> | ||
| + | | This event is raised before executing GCC's IPA optimization passes. Currently unused. | ||
| + | |- | ||
| + | ! "all_ipa_passes_execution" | ||
| + | | <tt>cgraphunit.c</tt> | ||
| + | | This event is raised just before executing GCC's IPA optimization passes. If this event's callback is successfully executed, and <tt>ici_ipa_passes_substitution_status</t> parameter, i.e. <tt>substitute_status</tt> ICI event parameter is set to non-zero value, GCC's default IPA passes will ''not'' be executed. | ||
| + | |- | ||
| + | ! "all_ipa_passes_end" | ||
| + | | <tt>cgraphunit.c</tt> | ||
| + | | 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" | ||
| + | | <tt>passes.c</tt> | ||
| + | | 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" | ||
| + | | <tt>passes.c</tt> | ||
| + | | 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" | ||
| + | | <tt>tree-optimize.c</tt> | ||
| + | | This event is raised before executing GCC's optimization passes on function being compiled. Currently unused. | ||
| + | |- | ||
| + | ! "all_passes_execution" | ||
| + | | <tt>tree-optimize.c</tt> | ||
| + | | This event is raised just before executing GCC's optimization passes on function being compiled. If this event's callback is successfully executed, and <tt>ici_passes_substitution_status</tt> parameter, i.e. <tt>substitute_status</tt> ICI event parameter is set to non-zero value, GCC's default passes will ''not'' be executed. | ||
| + | |- | ||
| + | ! "all_passes_end" | ||
| + | | <tt>tree-optimize.c</tt> | ||
| + | | 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" | ||
| + | | <tt>passes.c</tt> | ||
| + | | 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" | ||
| + | | <tt>passes.c</tt> | ||
| + | | This event is raised after the gate status is determined. <br />'''Warning:''' since functions generated by IPCP optimization would cause problems, pass execution event will not be raised if <tt>current_function_decl</tt> is set and <tt>DECL_ARTIFICIAL (current_function_decl)</tt> is non-zero. | ||
| + | |- | ||
| + | ! colspan="3" style="background-color:silver;" | Function Specific Optimizations Tuning Events | ||
| + | |- | ||
| + | ! "function_spec_loader" | ||
| + | | <tt>cgraphunit.c</tt> | ||
| + | | Special Event in <tt>ici_load_function_specific_optimizations</tt> function, this event is raised for every function in call graph. | ||
| + | |- | ||
| + | ! colspan="3" style="background-color:silver;" | Optimization Parameter Tuning Events | ||
| + | |- | ||
| + | ! "graphite_parameter_handler" | ||
| + | | <tt>graphite.c</tt> | ||
| + | | This event is raised for when some event parameter should be recorded or loaded from plugin. | ||
| + | |- | ||
| + | ! "unroll_parameter_handler" | ||
| + | | <tt>loop-unroll.c</tt> | ||
| + | | This event is raised for when some event parameter should be recorded or loaded from plugin. | ||
| + | |- | ||
| + | ! colspan="3" style="background-color:silver;" | Extra info | ||
| + | |- | ||
| + | ! "exmaple_event" | ||
| + | | <tt>source.c</tt> | ||
| + | | none | ||
| + | |} | ||
== ICI Features == | == ICI Features == | ||
=== New Features === | === New Features === | ||
ICI features added to the framework for fine-grain tuning are documented here. | ICI features added to the framework for fine-grain tuning are documented here. | ||
| - | {| border="1" cellspacing="0" cellpadding="3" style="text-align:left;" | + | {| border="1" cellspacing="0" cellpadding="3" style="text-align:left; width:100%;" |
! Feature name !! Type of contents !! Description | ! Feature name !! Type of contents !! Description | ||
|- | |- | ||
| Line 34: | Line 126: | ||
|} | |} | ||
| - | === Known Issue | + | === Known Issue of ICI 2.0 Features === |
| - | + | * "function_filename" can be empty for functions generated by IPCP optimization. | |
| - | * "function_filename" can be empty for functions generated by IPCP optimization | + | * "function_name" returns NULL pointer when compiling fortran functions. |
== ICI Parameters == | == 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. | 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 <tt>gcc/highlev-plugin-internal.h</tt> and <tt>gcc/highlev-plugin.h</tt>: | The parameter type is defined in <tt>gcc/highlev-plugin-internal.h</tt> and <tt>gcc/highlev-plugin.h</tt>: | ||
| Line 65: | Line 158: | ||
}; | }; | ||
</pre> | </pre> | ||
| + | |||
| + | === ICI Parameter Handling APIs === | ||
| + | |||
| + | See ICI API sector below: | ||
| + | [[#register_event_parameter:_register_a_new_ICI_parameter|register_event_parameter]] | ||
| + | [[#get_event_parameter_type:_get_the_type_of_an_ICI_event_parameter|get_event_parameter_type]] | ||
== ICI API == | == ICI API == | ||
| - | + | === Parameter Management === | |
| - | === ''register_event_parameter'': register a new ICI parameter === | + | ==== ''register_event_parameter'': register a new ICI parameter ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 104: | Line 203: | ||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#get_event_parameter_type:_get_the_type_of_an_ICI_event_parameter|get_event_parameter_type]] |
|} | |} | ||
| - | === ''get_event_parameter_type'': get the type of an ICI event parameter === | + | ==== ''get_event_parameter_type'': get the type of an ICI event parameter ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 145: | Line 244: | ||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#register_event_parameter:_register_a_new_ICI_parameter|register_event_parameter]] |
|} | |} | ||
| + | === Pass Management === | ||
<!-- pass managing --> | <!-- pass managing --> | ||
| - | + | ==== ''run_pass'': run a pass ==== | |
| - | === ''run_pass'': run a pass === | + | |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 176: | Line 275: | ||
| valign="top" | '''''Description''''' | | valign="top" | '''''Description''''' | ||
| - | Execute the pass registered with <tt>name</tt> prior to calling this function on current function. '''Warning:''' IPA passes ''should not'' be execute with this function, use <tt>[[ | + | Execute the pass registered with <tt>name</tt> prior to calling this function on current function. '''Warning:''' IPA passes ''should not'' be execute with this function, use <tt>[[#run_ipa_pass:_run_an_IPA_pass|run_ipa_pass]]</tt>instead. |
'''''Prerequisites''''' | '''''Prerequisites''''' | ||
| Line 183: | Line 282: | ||
'''''Outputs''''' | '''''Outputs''''' | ||
| - | |||
| - | |||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#run_ipa_pass:_run_an_IPA_pass|run_ipa_pass]] |
|} | |} | ||
| - | === ''run_ipa_pass'': run an IPA pass === | + | ==== ''run_ipa_pass'': run an IPA pass ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 224: | Line 321: | ||
'''''Outputs''''' | '''''Outputs''''' | ||
| - | |||
| - | |||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#run_pass:_run_a_pass|run_pass]] |
|} | |} | ||
| Line 235: | Line 330: | ||
<!-- batch pass execution --> | <!-- batch pass execution --> | ||
| - | === ''initialize_ici_pass_list'': initialize a list of passes for ICI batch execution === | + | ==== ''initialize_ici_pass_list'': initialize a list of passes for ICI batch execution ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 263: | Line 358: | ||
'''''Prerequisites''''' | '''''Prerequisites''''' | ||
| - | |||
| - | |||
'''''Outputs''''' | '''''Outputs''''' | ||
| - | |||
| - | |||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#insert_ici_pass_list:_insert_a_pass_into_ICI_pass_list|insert_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list:_execute_an_ICI_pass_list_on_current_function|run_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list_ipa_summary:_generate_IPA_summaries_for_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_ipa_summary]], |
| - | [[ | + | [[#run_ici_pass_list_per_function:_execute_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_per_function]], |
| + | [[#delete_ici_pass_list:_delete_an_ICI_pass_list|delete_ici_pass_list]] | ||
|} | |} | ||
| - | === ''insert_ici_pass_list'': insert a pass into ICI pass list === | + | ==== ''insert_ici_pass_list'': insert a pass into ICI pass list ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 285: | Line 377: | ||
{| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | {| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | ||
!Prototype | !Prototype | ||
| - | |<tt>void insert_ici_pass_list (void *list, int | + | |<tt>void insert_ici_pass_list (void *list, int cursor, const char *name)</tt> |
|- | |- | ||
!API level | !API level | ||
| Line 297: | Line 389: | ||
|- | |- | ||
!Inputs | !Inputs | ||
| - | | ''list:'' a pointer to ICI pass list (an array of <tt>opt_pass</tt> pointers).<br />''cursor:'' | + | | ''list:'' a pointer to ICI pass list (an array of <tt>opt_pass</tt> pointers).<br />''cursor:'' an integer indicating the slot to insert pass into.<br />''name:'' the name of the pass to be inserted. |
|- | |- | ||
!Return value | !Return value | ||
| Line 304: | Line 396: | ||
| valign="top" | '''''Description''''' | | valign="top" | '''''Description''''' | ||
| - | Insert a pass named <tt>name</tt> into ICI pass list <tt>list</tt> at position specified by <tt>cursor</tt> | + | Insert a pass named <tt>name</tt> into ICI pass list <tt>list</tt> at position specified by <tt>cursor</tt>. |
'''''Prerequisites''''' | '''''Prerequisites''''' | ||
| Line 317: | Line 409: | ||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#initialize_ici_pass_list:_initialize_a_list_of_passes_for_ICI_batch_execution|initialize_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list:_execute_an_ICI_pass_list_on_current_function|run_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list_ipa_summary:_generate_IPA_summaries_for_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_ipa_summary]], |
| - | [[ | + | [[#run_ici_pass_list_per_function:_execute_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_per_function]], |
| + | [[#delete_ici_pass_list:_delete_an_ICI_pass_list|delete_ici_pass_list]] | ||
|} | |} | ||
| - | === ''run_ici_pass_list'': execute an ICI pass list on current function === | + | ==== ''run_ici_pass_list'': execute an ICI pass list on current function ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 330: | Line 423: | ||
{| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | {| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | ||
!Prototype | !Prototype | ||
| - | |<tt>void | + | |<tt>void run_ici_pass_list (void *list)</tt> |
|- | |- | ||
!API level | !API level | ||
| Line 357: | Line 450: | ||
'''''Outputs''''' | '''''Outputs''''' | ||
| - | none | + | '''''See also''''' |
| + | |||
| + | [[#initialize_ici_pass_list:_initialize_a_list_of_passes_for_ICI_batch_execution|initialize_ici_pass_list]], | ||
| + | [[#insert_ici_pass_list:_insert_a_pass_into_ICI_pass_list|insert_ici_pass_list]], | ||
| + | [[#run_ici_pass_list_ipa_summary:_generate_IPA_summaries_for_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_ipa_summary]], | ||
| + | [[#run_ici_pass_list_per_function:_execute_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_per_function]], | ||
| + | [[#delete_ici_pass_list:_delete_an_ICI_pass_list|delete_ici_pass_list]] | ||
| + | |||
| + | |} | ||
| + | |||
| + | ==== ''run_ici_pass_list_ipa_summary'': generate IPA summaries for an ICI pass list on current cgraph ==== | ||
| + | |||
| + | {| cellpadding="5" | ||
| + | | style="vertical-align:top" | | ||
| + | {| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | ||
| + | !Prototype | ||
| + | |<tt>void run_ici_pass_list_ipa_summary (void *list)</tt> | ||
| + | |- | ||
| + | !API level | ||
| + | | FICI0 | ||
| + | |- | ||
| + | !Declared in | ||
| + | | ''pass-manager.h'' | ||
| + | |- | ||
| + | ! Implemented in | ||
| + | | ''pass-manager.c'' | ||
| + | |- | ||
| + | !Inputs | ||
| + | | ''list:'' a pointer to ICI pass list (an array of <tt>opt_pass</tt> pointers) of IPA passes. | ||
| + | |- | ||
| + | !Return value | ||
| + | | none | ||
| + | |} | ||
| + | | valign="top" | '''''Description''''' | ||
| + | |||
| + | Generate summaries for all IPA passes in ICI pass list <tt>list</tt>. | ||
| + | |||
| + | '''''Prerequisites''''' | ||
| + | |||
| + | List is not empty and current function is specified in GCC. | ||
| + | |||
| + | '''''Outputs''''' | ||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#initialize_ici_pass_list:_initialize_a_list_of_passes_for_ICI_batch_execution|initialize_ici_pass_list]], |
| - | [[ | + | [[#insert_ici_pass_list:_insert_a_pass_into_ICI_pass_list|insert_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list:_execute_an_ICI_pass_list_on_current_function|run_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list_per_function:_execute_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_per_function]], |
| + | [[#delete_ici_pass_list:_delete_an_ICI_pass_list|delete_ici_pass_list]] | ||
|} | |} | ||
| - | === ''run_ici_pass_list_per_function'': execute an ICI pass list on current | + | ==== ''run_ici_pass_list_per_function'': execute an ICI pass list on current cgraph ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 374: | Line 509: | ||
{| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | {| border="1" cellspacing="0" cellpadding="3" align="left" style="text-align:left" width="400px" | ||
!Prototype | !Prototype | ||
| - | |<tt>void | + | |<tt>void run_ici_pass_list_per_function (void *list)</tt> |
|- | |- | ||
!API level | !API level | ||
| Line 400: | Line 535: | ||
'''''Outputs''''' | '''''Outputs''''' | ||
| - | |||
| - | |||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#initialize_ici_pass_list:_initialize_a_list_of_passes_for_ICI_batch_execution|initialize_ici_pass_list]], |
| - | [[ | + | [[#insert_ici_pass_list:_insert_a_pass_into_ICI_pass_list|insert_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list:_execute_an_ICI_pass_list_on_current_function|run_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list_ipa_summary:_generate_IPA_summaries_for_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_ipa_summary]], |
| + | [[#delete_ici_pass_list:_delete_an_ICI_pass_list|delete_ici_pass_list]] | ||
|} | |} | ||
| - | === ''delete_ici_pass_list'': delete an ICI pass list === | + | ==== ''delete_ici_pass_list'': delete an ICI pass list ==== |
{| cellpadding="5" | {| cellpadding="5" | ||
| Line 444: | Line 578: | ||
'''''Outputs''''' | '''''Outputs''''' | ||
| - | |||
| - | |||
'''''See also''''' | '''''See also''''' | ||
| - | [[ | + | [[#initialize_ici_pass_list:_initialize_a_list_of_passes_for_ICI_batch_execution|initialize_ici_pass_list]], |
| - | [[ | + | [[#insert_ici_pass_list:_insert_a_pass_into_ICI_pass_list|insert_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list:_execute_an_ICI_pass_list_on_current_function|run_ici_pass_list]], |
| - | [[ | + | [[#run_ici_pass_list_ipa_summary:_generate_IPA_summaries_for_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_ipa_summary]], |
| + | [[#run_ici_pass_list_per_function:_execute_an_ICI_pass_list_on_current_cgraph|run_ici_pass_list_per_function]] | ||
|} | |} | ||
| - | |||
== Adapt Plugin == | == Adapt Plugin == | ||
| - | |||
| - | |||
Adapt plugin provides support for GCC pass sequence record/substitution, function-specific optimization tuning, function clone and instrumentation. | 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. | Plugins developed for fine-grain tuning are documented here. These plugins are developed to work with ICI-2.0 interface. | ||
| - | === | + | The behavior of the plugin is controled via '''ICI_ADAPT_CONTROL''' environment variable. When this variable is set to 1, information on compilation will be recorded into XML files; while this variable is set to 2, adapt plugin will reuse information from XML and tune GCC compilation workflow via ICI. |
| + | |||
| + | |||
| + | === Install and Usage === | ||
Adapt plugin is depends on [http://http://www.minixml.org Mini-XML library], which provides XML reading and writing ability. | Adapt plugin is depends on [http://http://www.minixml.org Mini-XML library], which provides XML reading and writing ability. | ||
| + | Different functionalities in adapt plugin can be enabled with in different compilation macros: | ||
| + | |||
| + | * '''SUPPORT_PASSES''' : pass recording and substitution | ||
| + | * '''SUPPORT_PARAMETERS''' : parameter tuning, need SUPPORT_PASSES | ||
| + | * '''SUPPORT_CLONE''' : clone and instrumentation, need SUPPORT_PASSES | ||
| + | * '''SUPPORT_FUNCTION_SPEC''' : set function specific optimizations with XML. | ||
| + | |||
| + | To compile with all these functions, set CC_SHARED parameter in Makefile like this: | ||
| + | <pre> | ||
| + | CC_SHARED=gcc -ansi -fPIC -D SUPPORT_PASSES -D SUPPORT_PARAMETERS -D SUPPORT_CLONE -D SUPPORT_FUNCTION_SPEC | ||
| + | </pre> | ||
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. | 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, <tt>ICI_PLUGIN</tt> environment variable should be set to the path to the plugin library (.so), and gcc should be called with with either <tt>-fici</tt> flag or <tt>ICI_USE</tt> environment parameter. | To use adapt plugin with ICI, <tt>ICI_PLUGIN</tt> environment variable should be set to the path to the plugin library (.so), and gcc should be called with with either <tt>-fici</tt> flag or <tt>ICI_USE</tt> environment parameter. | ||
| - | |||
| + | === Pass Recoding and Substitution === | ||
| + | |||
| + | Adapt plugin can be used to record or substite pass during compilation with information from XML files. | ||
| + | |||
| + | ==== Description ==== | ||
| + | Currently, there are two kinds of passes in GCC - ''IPA passes'', which is executed on call graph, and ''GIMPLE passes''. which is executed on one function. Those IPA passes are recorded per main input file, while those GIMPLE passes are recorded per pair of file in which the funtion is defined and the function name. Early local optimizations passes are special cases: they are of GIMPLE type, but since they are executed in IPA stage, they are currently stored to or read from XML file for IPA passes, included in ''gimple_pass_list'' tag inside ''ipa_pass_list'' tag. | ||
| + | |||
| + | ==== XML file location ==== | ||
| + | The name of XML file storing pass execution information is formated as: | ||
| + | |||
| + | <tt>gcc_compilation_flow@'''file_name'''@'''function_name'''</tt>@.xml | ||
| + | |||
| + | The <tt>file_name</tt> above is an escaped string of the pass to the source file (main input file for IPA passes or function define location file for GIMPLE passes). The escape rule is: | ||
| + | * The escaped file name consists two parts in sequence: ''prefix'' and ''substituted file name'' | ||
| + | * ''substituted file name'' is generated by substituting all directory separators with underscores. | ||
| + | * If there is no directory separator in the file name, the ''prefix'' is an underscore. | ||
| + | * If there is directory separator in the file name, the ''prefix'' starts with character '1' followed by three characters indicating the number of occurance in HEX, and then the offset(s) of separator(s) each represented in 3 character HEX. For example, prefix "1002011013" means there are two escaped separators in the following string, in position 17 and 19 with the first character in substituted file name referred as position 0. | ||
| + | |||
| + | An environment variable named '''ICI_ADAPT_XMLDIR''' can be used to specify a dir to save or find XML files. If this variable is not set or empty, current working directory will be used. | ||
| + | |||
| + | ==== Adapt XML DTD ==== | ||
| + | |||
| + | Here's XML file structure used in Adapt plugin, defined in DTD syntax ('''Draft'''): | ||
| + | <pre> | ||
| + | <!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 CDATA #REQUIRED> | ||
| + | <!ATTLIST function function_filename CDATA #REQUIRED> | ||
| + | <!ATTLIST function function_start_line CDATA #IMPLIED> | ||
| + | <!ATTLIST function function_end_line CDATA #IMPLIED> | ||
| + | |||
| + | <!ELEMENT optimizaton_options (#PCDATA)> | ||
| + | |||
| + | <!ELEMENT ipa_pass_list (pass*, gimple_pass_list?, pass*))> | ||
| + | <!ELEMENT gimple_pass_list (pass*)> | ||
| + | |||
| + | <!ELEMENT pass (parameter*, loop*)> | ||
| + | <!ATTLIST pass pass_name CDATA #REQUIRED> | ||
| + | <!ATTLIST pass pass_type (GIMPLE | RTL | SIMPLE_IPA | IPA) #IMPLIED> | ||
| + | |||
| + | <!ELEMENT loop (parameter*)> | ||
| + | <!ATTLIST loop loop_id CDATA #REQUIRED> | ||
| + | |||
| + | <!ELEMENT parameter (#PCDATA)> | ||
| + | <!ATTLIST parameter param_name CDATA #REQUIRED> | ||
| + | <!ATTLIST parameter param_type (void | char | unsigned_char | int | unsigned_int | long | unsigned_long) #REQUIRED> | ||
| + | </pre> | ||
| + | |||
| + | In order to support [[CTools:ICI:Projects:GSOC09:Function_cloning_and_program_instrumentation | function clone and instrumentation]] the DTD above shoule be extended like this: | ||
| + | <pre> | ||
| + | <!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)?, clones?, clone_name_extension?, adaptation_function?, add_function_call_before_func?, add_function_call_after_func?, options_clone?)> | ||
| + | <!ATTLIST function function_name CDATA #REQUIRED> | ||
| + | <!ATTLIST function function_filename CDATA #REQUIRED> | ||
| + | <!ATTLIST function function_start_line CDATA #IMPLIED> | ||
| + | <!ATTLIST function function_end_line CDATA #IMPLIED> | ||
| + | |||
| + | <!ELEMENT optimizaton_options (#PCDATA)> | ||
| + | |||
| + | <!ELEMENT ipa_pass_list (pass*, gimple_pass_list?, pass*))> | ||
| + | <!ELEMENT gimple_pass_list (pass*)> | ||
| + | |||
| + | <!ELEMENT pass (parameter*, loop*)> | ||
| + | <!ATTLIST pass pass_name CDATA #REQUIRED> | ||
| + | <!ATTLIST pass pass_type (GIMPLE | RTL | SIMPLE_IPA | IPA) #IMPLIED> | ||
| + | |||
| + | <!ELEMENT loop (parameter*)> | ||
| + | <!ATTLIST loop loop_id CDATA #REQUIRED> | ||
| + | |||
| + | <!ELEMENT parameter (#PCDATA)> | ||
| + | <!ATTLIST parameter param_name CDATA #REQUIRED> | ||
| + | <!ATTLIST parameter param_type (void | char | unsigned_char | int | unsigned_int | long | unsigned_long) #REQUIRED> | ||
| + | |||
| + | <!ELEMENT clones (#PCDATA)> | ||
| + | <!ELEMENT clone_name_extension (#PCDATA)> | ||
| + | <!ELEMENT adaptation_function (#PCDATA)> | ||
| + | <!ELEMENT add_function_call_before_func (#PCDATA)> | ||
| + | <!ELEMENT add_function_call_after_func (#PCDATA)> | ||
| + | <!ELEMENT options_clone (#PCDATA)> | ||
| + | </pre> | ||
| + | |||
| + | '''XML TODOs''': | ||
| + | |||
| + | * Provide script to verify XML file. | ||
| + | |||
| + | * Re-design the XML vocabulary to express clone concept more clearly. | ||
| + | |||
| + | |||
| + | === Fine-Grain Parameter Tuning === | ||
| + | Parameters for passes with ICI can be recorded and tuned with adapt plugin. | ||
| + | |||
| + | ==== Description ==== | ||
| + | During the first compilation, parameters are saved into correponding pass node in XML files. If it is a loop level optimization, parameters of different loops are saved in different loop nodes identified by loop id. During the second compilation, ICI event handlers will alter the parameters as specified in the XML files. | ||
| + | |||
| + | A conventon is employed to keep parameters that only provides information on currently compilation status unalterable: '''parameters whose name starts with an underscore ('_') will not be changed by ICI plugin.''' | ||
| + | |||
| + | ==== ICI enabled passes ==== | ||
| + | Currently 2 passes can tuned with ICI: | ||
| + | * '''loop-unroll:''' performs ''loop unroll'' and ''loop peeling'' | ||
| + | * '''graphite:''' performs ''loop interchange'', ''loop strip mine'' and ''loop blocking'' on SCOPs | ||
| + | |||
| + | ==== 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 [[#Adapt_XML_DTD | 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 Tuning === | ||
| + | |||
| + | Adapt plugin makes it possible to set function specific optimizations with XML files. | ||
| + | |||
| + | ==== Description ==== | ||
| + | GCC allows different command line optimization options to be set for each function, and this plugin functionnality is analog to command line settings. Through adapt plugin, optimizations options can be given in the same format as command line arguments, and is represented in a plain character string tagged <tt>optimization_options</tt> in <tt>function</tt> tag. | ||
| + | |||
| + | ==== XML format ==== | ||
| + | The XML scheme is also the same as [[#Adapt_XML_DTD | pass management XML file]].However, because this function can work without pass recording/substitution enabled, you may provide an XML file in different scheme as long as there is one <tt>optimization_options</tt> tag in the XML tree. | ||
| + | |||
| + | ==== Known issues ==== | ||
none | none | ||
| + | |||
| + | |||
| + | === Function Clone and Instrumentation === | ||
| + | |||
| + | The [[CTools:ICI:Projects:GSOC09:Function_cloning_and_program_instrumentation | function clone and instrumentation functionality]] is implemented in another project by Liang Peng from ICT, China. | ||
| + | |||
| + | |||
| + | == Scripts == | ||
| + | A set of scripts have been writen to automate the installation and compilation process. These scripts could be used with both fine-grain tuning project and [[CTools:ICI:Projects:GSOC09:Function_cloning_and_program_instrumentation|function cloning and program instrumentation project]], please refer to [[CTools:ICI:Projects:GSOC09:Scripts|this page]] for usage information. | ||
Current revision
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.
- GSOC'09 project description
- cTuning development mailing list
- SVN repository hosted on SourceForge.net®
http://gcc-ici.svn.sourceforge.net/viewvc/gcc-ici/branches/
ICI Fine-Grain Tuning Overview
Key Concepts
This fine grain tuning project is an extension to ICI-2.0, and follows the concepts of ICI.
Work Flow
GCC fine-grain tuning projects brings two modes to GCC: record mode and the reuse mode.
In the record mode, information on compilation is recorded. Currently XML files are generated to log passes executed on each function, and parameters for several ICI-enabled passes, which describe the characteristic of the program being compiled and the internal decision making process of GCC.
Then the recorded information could be modified by machine learning algorithms or iterative seach engine, and loaded while compiling the program again in reuse mode. Thus internal heuristics are overridden, and GCC yields differently optimized code.
The work flow of ICI fine-grain tuning project on GCC 4.4 is illustrated in the two figures on the right.
Future Work
- Provide a flexible yet easy-to-use mechanism to represent the compilation work flow and ICI control, and remove EP_SILENT type from ICI fine-grain tuning parameter types.
- Enable fine grain tuning in more GCC optimization passes.
- Develop a tool to translate function specific optimization options into pass and optimizations parameters.
ICI Events
ICI events are used to stop normal compilation flow of GCC and execute callback function from ICI plugin. ICI Events for fine-grain tuning are shown in the figure on the right.
| 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. |
| 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. |
| 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. |
| 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.
- "function_name" returns NULL pointer when compiling fortran functions.
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 */
};
ICI Parameter Handling APIs
See ICI API sector below: register_event_parameter get_event_parameter_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 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 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 Outputs See also insert_ici_pass_list, run_ici_pass_list, run_ici_pass_list_ipa_summary, 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. 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_ipa_summary, 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 See also initialize_ici_pass_list, insert_ici_pass_list, run_ici_pass_list_ipa_summary, run_ici_pass_list_per_function, delete_ici_pass_list |
run_ici_pass_list_ipa_summary: generate IPA summaries for an ICI pass list on current cgraph
| Description
Generate summaries for all IPA passes in ICI pass list list. Prerequisites List is not empty and current function is specified in GCC. Outputs See also initialize_ici_pass_list, insert_ici_pass_list, run_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 cgraph
| Description
Execute an ICI pass list list on call graph functions one by one in 'top order'. Prerequisites List is not empty. Outputs See also initialize_ici_pass_list, insert_ici_pass_list, run_ici_pass_list, run_ici_pass_list_ipa_summary, 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 See also initialize_ici_pass_list, insert_ici_pass_list, run_ici_pass_list, run_ici_pass_list_ipa_summary, run_ici_pass_list_per_function |
Adapt Plugin
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.
The behavior of the plugin is controled via ICI_ADAPT_CONTROL environment variable. When this variable is set to 1, information on compilation will be recorded into XML files; while this variable is set to 2, adapt plugin will reuse information from XML and tune GCC compilation workflow via ICI.
Install and Usage
Adapt plugin is depends on Mini-XML library, which provides XML reading and writing ability.
Different functionalities in adapt plugin can be enabled with in different compilation macros:
- SUPPORT_PASSES : pass recording and substitution
- SUPPORT_PARAMETERS : parameter tuning, need SUPPORT_PASSES
- SUPPORT_CLONE : clone and instrumentation, need SUPPORT_PASSES
- SUPPORT_FUNCTION_SPEC : set function specific optimizations with XML.
To compile with all these functions, set CC_SHARED parameter in Makefile like this:
CC_SHARED=gcc -ansi -fPIC -D SUPPORT_PASSES -D SUPPORT_PARAMETERS -D SUPPORT_CLONE -D SUPPORT_FUNCTION_SPEC
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 and Substitution
Adapt plugin can be used to record or substite pass during compilation with information from XML files.
Description
Currently, there are two kinds of passes in GCC - IPA passes, which is executed on call graph, and GIMPLE passes. which is executed on one function. Those IPA passes are recorded per main input file, while those GIMPLE passes are recorded per pair of file in which the funtion is defined and the function name. Early local optimizations passes are special cases: they are of GIMPLE type, but since they are executed in IPA stage, they are currently stored to or read from XML file for IPA passes, included in gimple_pass_list tag inside ipa_pass_list tag.
XML file location
The name of XML file storing pass execution information is formated as:
gcc_compilation_flow@file_name@function_name@.xml
The file_name above is an escaped string of the pass to the source file (main input file for IPA passes or function define location file for GIMPLE passes). The escape rule is:
- The escaped file name consists two parts in sequence: prefix and substituted file name
- substituted file name is generated by substituting all directory separators with underscores.
- If there is no directory separator in the file name, the prefix is an underscore.
- If there is directory separator in the file name, the prefix starts with character '1' followed by three characters indicating the number of occurance in HEX, and then the offset(s) of separator(s) each represented in 3 character HEX. For example, prefix "1002011013" means there are two escaped separators in the following string, in position 17 and 19 with the first character in substituted file name referred as position 0.
An environment variable named ICI_ADAPT_XMLDIR can be used to specify a dir to save or find XML files. If this variable is not set or empty, current working directory will be used.
Adapt XML DTD
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 CDATA #REQUIRED> <!ATTLIST function function_filename CDATA #REQUIRED> <!ATTLIST function function_start_line CDATA #IMPLIED> <!ATTLIST function function_end_line CDATA #IMPLIED> <!ELEMENT optimizaton_options (#PCDATA)> <!ELEMENT ipa_pass_list (pass*, gimple_pass_list?, pass*))> <!ELEMENT gimple_pass_list (pass*)> <!ELEMENT pass (parameter*, loop*)> <!ATTLIST pass pass_name CDATA #REQUIRED> <!ATTLIST pass pass_type (GIMPLE | RTL | SIMPLE_IPA | IPA) #IMPLIED> <!ELEMENT loop (parameter*)> <!ATTLIST loop loop_id CDATA #REQUIRED> <!ELEMENT parameter (#PCDATA)> <!ATTLIST parameter param_name CDATA #REQUIRED> <!ATTLIST parameter param_type (void | char | unsigned_char | int | unsigned_int | long | unsigned_long) #REQUIRED>
In order to support function clone and instrumentation the DTD above shoule be extended like this:
<!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)?, clones?, clone_name_extension?, adaptation_function?, add_function_call_before_func?, add_function_call_after_func?, options_clone?)> <!ATTLIST function function_name CDATA #REQUIRED> <!ATTLIST function function_filename CDATA #REQUIRED> <!ATTLIST function function_start_line CDATA #IMPLIED> <!ATTLIST function function_end_line CDATA #IMPLIED> <!ELEMENT optimizaton_options (#PCDATA)> <!ELEMENT ipa_pass_list (pass*, gimple_pass_list?, pass*))> <!ELEMENT gimple_pass_list (pass*)> <!ELEMENT pass (parameter*, loop*)> <!ATTLIST pass pass_name CDATA #REQUIRED> <!ATTLIST pass pass_type (GIMPLE | RTL | SIMPLE_IPA | IPA) #IMPLIED> <!ELEMENT loop (parameter*)> <!ATTLIST loop loop_id CDATA #REQUIRED> <!ELEMENT parameter (#PCDATA)> <!ATTLIST parameter param_name CDATA #REQUIRED> <!ATTLIST parameter param_type (void | char | unsigned_char | int | unsigned_int | long | unsigned_long) #REQUIRED> <!ELEMENT clones (#PCDATA)> <!ELEMENT clone_name_extension (#PCDATA)> <!ELEMENT adaptation_function (#PCDATA)> <!ELEMENT add_function_call_before_func (#PCDATA)> <!ELEMENT add_function_call_after_func (#PCDATA)> <!ELEMENT options_clone (#PCDATA)>
XML TODOs:
- Provide script to verify XML file.
- Re-design the XML vocabulary to express clone concept more clearly.
Fine-Grain Parameter Tuning
Parameters for passes with ICI can be recorded and tuned with adapt plugin.
Description
During the first compilation, parameters are saved into correponding pass node in XML files. If it is a loop level optimization, parameters of different loops are saved in different loop nodes identified by loop id. During the second compilation, ICI event handlers will alter the parameters as specified in the XML files.
A conventon is employed to keep parameters that only provides information on currently compilation status unalterable: parameters whose name starts with an underscore ('_') will not be changed by ICI plugin.
ICI enabled passes
Currently 2 passes can tuned with ICI:
- loop-unroll: performs loop unroll and loop peeling
- graphite: performs loop interchange, loop strip mine and loop blocking on SCOPs
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 Tuning
Adapt plugin makes it possible to set function specific optimizations with XML files.
Description
GCC allows different command line optimization options to be set for each function, and this plugin functionnality is analog to command line settings. Through adapt plugin, optimizations options can be given in the same format as command line arguments, and is represented in a plain character string tagged optimization_options in function tag.
XML format
The XML scheme is also the same as pass management XML file.However, because this function can work without pass recording/substitution enabled, you may provide an XML file in different scheme as long as there is one optimization_options tag in the XML tree.
Known issues
none
Function Clone and Instrumentation
The function clone and instrumentation functionality is implemented in another project by Liang Peng from ICT, China.
Scripts
A set of scripts have been writen to automate the installation and compilation process. These scripts could be used with both fine-grain tuning project and function cloning and program instrumentation project, please refer to this page for usage information.


