This is the mail archive of the
mailing list for the GCC project.
Re: PATCH: Profile driven specialization of indirect/virtual calls
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Tomas Bily" <tbily at suse dot cz>
- Cc: gcc-patches at gcc dot gnu dot org, tomby at ucw dot cz, hubicka at ucw dot cz
- Date: Wed, 13 Dec 2006 11:11:20 +0100
- Subject: Re: PATCH: Profile driven specialization of indirect/virtual calls
- References: <20061213015540.GA19328@atrey.karlin.mff.cuni.cz>
On 12/13/06, Tomas Bily <email@example.com> wrote:
I am slightly modified patch
http://gcc.gnu.org/ml/gcc-patches/2005-10/msg01563.html 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
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
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
Bootstrapped and regtested on x86_64-unknown-linux-gnu, i686-linux.
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