This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Profile driven specialization of indirect/virtual calls


 I am slightly modified patch and updated to


  A) Lets have an indirect call p (...) where p is pointer to function (type of
  "sometype (*p) (args)"). In some programs there could be p nearly constant. 

  B) Lets have an virtual call p->somemethod (...) where p is instance of class
  with virtual method "somemethod". In some programs there could be p nearly
  constant class.

  Determine most common function call in A) and most common class in B). Use
  this information to improve code effectivity (espetialy info for inliner).


 Use actual gcc tree-profiling capability to measure most common func/class.

 1) Assign unique id to every finction/method:

  To structure cgraph_node was added attribute "pid" which is computed in
  function cgraph_finalize_function.

 2) STAGE generating profile:
  to every object file add two static variables:

  static void (*__gcov_indirect_call_callee) ();
  static gcov_type* __gcov_indirect_call_counters;

  before each virtual or indirect call add code:

  __gcov_indirect_call_counters = get_relevant_counter_ptr (); 
  __gcov_indirect_call_callee = (void *) indirect call argument;

  At the begining every called function or method (method uniquily determine
  class) add code:

  if (__gcov_indirect_call_callee == my_address)
     __gcov_one_value_profile (__gcov_indirect_call_counters, my pid);

 3) STAGE using profile:

  For every checked indirect/virtual call determine if most common pid of
  function/class method has probability more than 50%. If yes modify code of
  this call to:

  if (actual_callee_addres == addres_of_most_common_function/method)
    do direct call
    old call

Bootstrapped and regtested on x86_64-unknown-linux-gnu, i686-linux.


Changelog entry:

2006-12-12  Tomas Bily  <>

	* cgraphunit.c (cgraph_finalize_function): Updating of pid

	* tree-profile.c: 
	(tree_init_ic_make_global_vars): New function
	(tree_init_edge_profiler): call of tree_init_ic_make_global_vars
	(tree_gen_ic_profiler): New function
	(tree_gen_ic_func_profiler): New function
	(tree_profiling): Added calling of tree_gen_ic_func_profiler
	(tree_profile_hooks): Added hook for indirec/virtual calls

	* value-prof.c (tree_find_values_to_profile): New case for
	indirect calls
	(tree_values_to_profile): Call for determining indirect/virtual 
	(tree_indirect_call_to_profile): New function
	(tree_ic_transform): New function 
	(tree_ic): New function
	(find_func_by_pid): New function
	(init_pid_map): New function
	(tree_value_profile_transformations): Added check for
	indirect/virtual call transformation

	* value-prof.h (enum hist_type): New counter type for
	indirect/virtual calls
	(profile_hooks): Added new hook for profiling indirect/virtual 

	* profile.c (instrument_values): New case for indirect/virtual
	call added

	* gcov-io.h (GCOV_LAST_VALUE_COUNTER): Changed to 6
	(GCOV_COUNTER_V_INDIR): New counter type
	(GCOV_COUNTER_NAMES): New name of counter "indirect" added 
	(GCOV_MERGE_FUNCTIONS): New merge function for indirect/virtual
	call added

	* cgraph.c: Definition of cgraph_max_pid
	(cgraph_create_node): Default init of pid attribute

	* cgraph.h: Declaration of cgraph_max_pid
	(struct cgraph_node): Added pid attribute 
	* libgcov.c (__gcov_indirect_call_profiler): New function

Attachment: indirect-call.patch
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]