[Patch, libfortran] Reduce inlining
Janne Blomqvist
blomqvist.janne@gmail.com
Thu Nov 10 17:28:00 GMT 2011
Hi,
the inlining heuristics are nowadays decent. In particular, at -O2 the
compiler does the obvious inlinings:
- If the function body is very small (for some measure of small, see
-finline-small-functions)
- static functions called once (-finline-functions-called-once)
Where GCC may need help is for function called with constant
arguments, and the inlining would allow the deletion of untaken
branches.
Otherwise, in lieu of profiling data suggesting otherwise, keeping the
code size smaller by avoiding inlining is probably the smart thing to
do.
The attached patch does this for libgfortran, that is, removes the
inline attribute for static functions.
The patch reduces the size of the following object files as follows:
Before:
text data bss dec hex filename
781 0 0 781 30d
../../trunk/objdir-git/x86_64-unknown-linux-gnu/libgfortran/cpu_time.o
text data bss dec hex filename
679 0 0 679 2a7
../../trunk/objdir-git/x86_64-unknown-linux-gnu/libgfortran/system_clock.o
After:
text data bss dec hex filename
660 0 0 660 294
../../trunk/objdir-git/x86_64-unknown-linux-gnu/libgfortran/cpu_time.o
text data bss dec hex filename
631 0 0 631 277
../../trunk/objdir-git/x86_64-unknown-linux-gnu/libgfortran/system_clock.o
For the other affected object files there is no change, suggesting
that while the inline attributes did no harm, they did no good either.
A system_clock benchmark program showed no change due to the
un-inlining of gf_gettime_mono. For CPU_TIME, that results in a proper
syscall (as opposed to SYSTEM_CLOCK/clock_gettime which is available
as a VDSO on my system) so the overhead of that would overshadow
whatever differences inlining might make, so I didn't test that.
There was also an inline function (memset4) which was copy-pasted both
in transfer.c and write.c; I moved it to io.h after first verifying
that removing the inline attribute still caused the compiler to inline
it.
Committed as obvious to trunk.
2011-11-10 Janne Blomqvist <jb@gcc.gnu.org>
* intrinsics/cpu_time.c (__cpu_time_1): Don't force inlining.
* intrinsics/random.c (rnumber_4): Remove inline attribute.
(rnumber_8, rnumber_10, rnumber_16): Likewise.
* intrinsics/system_clock.c (gf_gettime_mono): Likewise.
* intrinsics/time_1.h (ATTRIBUTE_ALWAYS_INLINE): Remove macro.
(gf_cputime): Add inline attribute for MingW version.
* io/format.c (format_hash): Remove inline attribute.
* io/io.h (memset4): Inline function from transfer.c and write.c
moved here.
* io/transfer.c (min_off): Remove inline attribute.
(memset4): Move to io.h.
* io/write.c (memset4): Likewise.
(memcpy4): Remove inline attribute.
* io/write_float.def (calculate_exp): Likewise.
--
Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline.diff
Type: text/x-patch
Size: 5452 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111110/70171b0f/attachment.bin>
More information about the Fortran
mailing list