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]

Re: PATCH: Profile driven specialization of indirect/virtual calls

On 12/13/06, Tomas Bily <> wrote:

 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. OK?

It would be nice to have some testcase for C and C++, at least for successful instrumentation. Bonus points if you can test for a successful transformation with -fprofile-use.


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