Merging identical functions in GCC
Joe Buck
Joe.Buck@synopsys.COM
Mon Sep 18 23:26:00 GMT 2006
On Mon, Sep 18, 2006 at 12:09:36PM -0700, Mark Mitchell wrote:
> Mike Stump wrote:
> >On Sep 15, 2006, at 2:32 PM, Ross Ridge wrote:
> >>Also, I don't think it's safe if you merge only functions in COMDAT
> >>sections.
> >
> >Sure it is, one just needs to merge them as:
> >
> >variant1: nop
> >variant2: nop
> >variant3: nop
> > [ ... ]
> >
> >this way important inequalities still work.
>
> Yes, that will work. But, in practice, people will also want the mode
> where you do not insert the nops, and just accept that some functions
> compare equal when they shouldn't. So, we should have a switch for that
> mode too.
It certainly is true that if we generate one set of routines for
vector<int>, vector<long>, and vector<T*> for all T, a program that
uses them all could have a lot of nops.
But there's another possibility: we can implement the variants as
inline functions that call the common implementation. If the address
of the function is not taken in a given file, we can make a direct call.
If the address is taken, we need an "outlined" copy of the function.
These out-of-line copies can be handled in the usual linkonce/COMDAT
way, so that they resolve to one copy.
So it seems that just having address-taking block inlining suffices.
More information about the Gcc
mailing list