From cTuning.org

(Difference between revisions)
Jump to: navigation, search
Line 59: Line 59:
* Call back function: '''load_clone_config ()'''    Defined in ICI plugin '''adapt.c'''
* Call back function: '''load_clone_config ()'''    Defined in ICI plugin '''adapt.c'''
-
** It gets the current main input filename first using '''get_feature ("main_input_filename")''', then read information from corresponding xml file into datastruct '''cloneinfo''' using [http://http://www.minixml.org Mini-XML library].
+
:: It gets the current main input filename first using '''get_feature ("main_input_filename")''', then read information from corresponding xml file into datastruct '''cloneinfo''' using [http://http://www.minixml.org Mini-XML library].
* ICI event parameter: '''clone_info'''  A pointer to datastruct cloneinfo
* ICI event parameter: '''clone_info'''  A pointer to datastruct cloneinfo
Line 80: Line 80:
'''SIMPLE_IPA_PASS "generic_cloning"'''
'''SIMPLE_IPA_PASS "generic_cloning"'''
-
This pass performs generic function cloning. It has the ability to create any number of clones for a given function on demand, and aply different fine-grain optimizations for a given clone, also provide mechanism to select different clones at run-time based on optimization scenarios. It can be triggered by GCC option -fapi-clone-function and ICI adaptation framework. The information come from xml files through ICI.
+
This pass performs generic function cloning. It has the ability to create any number of clones for a given function on demand, and aply different fine-grain optimizations for a given clone, also provide mechanism to select different clones at run-time based on optimization scenarios.  
 +
 
 +
It can be triggered by GCC option -fapi-clone-function and ICI adaptation framework. The information come from xml files through ICI.
'''Primary functions'''
'''Primary functions'''
-
exec_clone_functions (void)
+
*exec_clone_functions (void)
 +
:: This is the execute function for gimple_opt_pass pass_clone_functions. It calls event "load_instr_config" to load information needed by cloning, and clone functions that is in the clone list using cgraph_function_versioning, and insert selection mechanism at last.
-
add_call_to_clones (struct cgraph_node *orig, int nid)
+
*add_call_to_clones (struct cgraph_node *orig, int nid)
 +
:: This function insert selection mechanism, which includes call to clones, call to adaptation function, and build switch statement.
get_arguments (tree tree_list)
get_arguments (tree tree_list)
 +
:: This function get the arguments of original function into tree argv.
parse_arguments (char *text, unsigned int *argc)
parse_arguments (char *text, unsigned int *argc)
 +
:: This function parse a option string, and return the number of argument and vector of argument.
 +
 +
For example parse "-O3 -fici -fapi-clone-functions", to int argc=3, char **argv={"-O3","-fici","-fapi-clone-functions"}
find_clone_options (char *funcname, int *nid)
find_clone_options (char *funcname, int *nid)

Revision as of 07:40, 12 August 2009

Google Summer of Code 2009: Generic function cloning.

Liang Peng (ICT, China)

Based on Run-time Function Adaptation for Statically-Compiled Programs based on function multiversioning and FunctionSpecificOpt, we enabled generic function cloning with low-overhead program behavior monitoring routines. It will enable fine-grain self-tuning binaries and libraries and will increase performance and portability of the static code which is particularly important for rapidly evolving hardware and virtual enviroments.


Contents

Key data structures

Information from xml files for function cloning and instrumentation through ICI plugin.

Defined in both gcc/highlev-plugin-internal.h and gcc/highlev-plugin.h:

typedef struct {
  /* number of function to clone.  */
  int numofclonefun;                           
  /* function name list.  */
  char **clone_function_list;                        
  /* corresponding filename of function.  */
  char **function_filename_list;                   
  /* corresponding number of clones.  */
  int *clones;                                                 
  /* corresponding function name extension for clone.  */
  char **clone_extension;                             
  /* corresponding adaptation function name for current function .  */
  char **adaptation_function;                      
  /* option list for clone .  */
  char **clone_option;                                 
  /* corresponding external libraries.  */
  char *external_libraries;                          
} cloneinfo ;
typedef struct {
  /* number of function to instrument.  */
  int numofinstrfun;
  /* function name list.  */
  char **instrument_function_list;
  /* corresponding filename of function.  */
  char **function_filename_list;
  /* name of function instrument at the begin of function.  */
  char **timer1;
  /* name of function instrument at the end of function.  */
  char **timer2;
  /* flag list whether function is cloned.  */
  char *cloned;
} instrinfo ;

New ICI event

ICI event "load_clone_config"

This event is called at the very beginning of function cloning pass.

  • Call back function: load_clone_config () Defined in ICI plugin adapt.c
It gets the current main input filename first using get_feature ("main_input_filename"), then read information from corresponding xml file into datastruct cloneinfo using Mini-XML library.
  • ICI event parameter: clone_info A pointer to datastruct cloneinfo


ICI event “load_instr_config”

This event is called at the very beginning of function instrumentation pass.

  • Call back function : load_instr_config () Defined in ICI plugin adapt.c
It gets the current main input filename first using get_feature ("main_input_filename"), then read information from corresponding xml file into datastruct instrinfo using Mini-XML library.
  • ICI event parameter: clone_info A pointer to datastruct instrinfo


Function cloning

Description

SIMPLE_IPA_PASS "generic_cloning"

This pass performs generic function cloning. It has the ability to create any number of clones for a given function on demand, and aply different fine-grain optimizations for a given clone, also provide mechanism to select different clones at run-time based on optimization scenarios.

It can be triggered by GCC option -fapi-clone-function and ICI adaptation framework. The information come from xml files through ICI.

Primary functions

  • exec_clone_functions (void)
This is the execute function for gimple_opt_pass pass_clone_functions. It calls event "load_instr_config" to load information needed by cloning, and clone functions that is in the clone list using cgraph_function_versioning, and insert selection mechanism at last.
  • add_call_to_clones (struct cgraph_node *orig, int nid)
This function insert selection mechanism, which includes call to clones, call to adaptation function, and build switch statement.

get_arguments (tree tree_list)

This function get the arguments of original function into tree argv.

parse_arguments (char *text, unsigned int *argc)

This function parse a option string, and return the number of argument and vector of argument.

For example parse "-O3 -fici -fapi-clone-functions", to int argc=3, char **argv={"-O3","-fici","-fapi-clone-functions"}

find_clone_options (char *funcname, int *nid)

is_in_clone_list (const char *func_name, const char *file_name, int *nid)

freecloneinfo (cloneinfo cdi)

is_it_clonable (struct cgraph_node *cg_func)

is_it_main (struct cgraph_node *cg_func)

Work flow

Instrumentation

Description

SIMPLE_IPA_PASS "Instrumentation"

This pass performs function instrumentation. Currently, it has only ability to add function calls and selection mechanism to choose clones based on the external library monitoring routines. We also have the ability to link external libraries transparently withou Makefile modifications. This pass also can be triggered by GCC option fapi-instrument-functions and ICI adaptation framework. The information come from xml files through ICI.

Primary functions

exec_instrument_functions (void)

add_timer_begin (struct cgraph_node *cg_func, char *funname, int cloned)

add_timer_end (struct cgraph_node *cg_func, char *funname)

freeinstrinfo (instrinfo idi)

is_in_instrument_list (const char *func_name, const char *file_name, int *nid)

is_it_instrumentable (struct cgraph_node *cg_func)

Work flow

ICI Adaptation

Work flow

Three steps compilation:

Scripts

adaptutil.py

Linking external library

Locations of visitors to this page