This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] C++ space optimization: de-cloning con/de/structors
- From: Stuart Hastings <stuart at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 6 Aug 2002 11:41:49 -0700
- Subject: [PATCH] C++ space optimization: de-cloning con/de/structors
Hello,
This is a C++ space optimization.
GCC3 currently "clones" a set of constructors (and destructors) with
varying parameter lists from an original constructor (destructor)
that contains all the functionality of each clone. If all of your
constructors and destructors are trivial functions, this is probably a
good idea. However, we have many internal projects that show severe
code bloat (compared with GCC2) due to this feature.
This patch essentially un-does the cloning operation. The original
function gets renamed to something that can be un-mangled, and the
clones become trivial wrappers around calls to the original function.
The "sibling call" optimization then strips away the stackframe from
the clones, leaving thunks that perturb their arguments and jump.
Internal projects we've measured typically shrink by 6% on disk with
this change.
Operation is controlled by a flag, -fno-clone-structors, and defaults
OFF in this patch. This should arguably be tied to -Os. This
optimization defaults ON inside Apple.
There is a related patch coming soon that recognizes these thunk-esque
clones and omits the EH info for them, saving more space.
Sometimes the cloned con/de/structors have the same parameter list as
the original function, and in these cases it would be ideal to reduce
the clone to another label on the original function. However, Mach-O
targets won't support this. I believe ELF will, but the
implementation isn't finished (see "maybe_alias_body()").
Compatibility
The original GCC3 "in-charge," "not-in-charge" etc. entry points are
retained; they become wrappers for the "unified" con/de/structor. As
long as the unified constructor keeps the same linkage (global,
coalesced, whatever) as the clones, this patch is link-compatible with
existing object decks.
Adds one new kind of constructor and one new kind of destructor to the
name mangling. Code invoking the con/de/structors sees no difference.
GDB and c++filt are known to successfully demangle the new
con/de/structors with the libiberty patch included.
Testing
Bootstrapped on Linux-x86 and Mac OS X (PPC). Passes C++ testsuite
with no
new failures. Compiled OS X.
stuart hastings
Apple Computer
* gcc/gcc/c-common.c Add flag_clone_structors.
* gcc/gcc/c-common.h Same.
* gcc/gcc/cp/decl2.c Same.
* gcc//cp/mangle.c (write_special_name_constructor,
write_special_name_destructor) Mangle unified,
"old-style" constructors and destructors.
* gcc/cp/optimize.c (maybe_alias_body, maybe_thunk_body) New.
(maybe_clone_body) One pass becomes two passes.
* gcc/include/demangle.h Add 'unified' constructor and destructor
enums.
* gcc/libiberty/cp-demangle.c (demangle_ctor_dtor_name)
Demangle unified constructors and destructors.
Attachment:
patch.decloner.patchonly
Description: Binary data