From: Andi Kleen <andi@firstfloor.org>
To: mmarek@suse.com
Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] Kbuild: Enable interprocedural register allocation for gcc 5
Date: Mon, 30 Nov 2015 22:00:43 -0800 [thread overview]
Message-ID: <1448949643-6059-1-git-send-email-andi@firstfloor.org> (raw)
From: Andi Kleen <ak@linux.intel.com>
gcc 5 has a new -fipa-ra option that enables limited interprocedural
register allocation. When it generates a function it remembers
what registers it clobbered. Later when the function is called
it only saves registers that are actually clobbered by the function.
This only really works when caller and callee are in the same compilation unit
(except with LTO)
In principle this violates the ABI which specifies which registers
are saved and which are clobbered on a call. However there shouldn't
be anything else relying on this: while we have multiple subsystems
that patch binaries (like ftrace, kprobes) they all cannot know
which registers are used as arguments, so always need to save/restore
all registers.
Similarly gdb and other debuggers cannot rely on the ABI either.
It has some risk that it breaks something obscure, but so far I haven't
seen or found anything.
On my system with gcc 5.2 it saves about 40k in binary size
text data bss dec hex filename
9583446 2178288 1675264 13436998 cd0846 vmlinux-base
9542180 2178096 1675264 13395540 cc6654 vmlinux-ipara -0.4%
pretty much all in missing spill code. So it's not a dramatic win,
but still a nice improvement.
Open: for now I enabled it for all architectures, although it's
only tested on x86-64. It may be safer to move it to be x86
specific or guard with an CONFIG option, until more testing can be done.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
Makefile | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Makefile b/Makefile
index 2ffdf9d..c95320f 100644
--- a/Makefile
+++ b/Makefile
@@ -626,6 +626,12 @@ KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
$(call cc-option,-fno-partial-inlining)
endif
+# Ask gcc to use interprocedural register allocation when possible.
+# This allows it to violate the callee-saved register ABI and avoid
+# generating register spills in the caller when it knows the function does
+# not clobber these registers
+KBUILD_CFLAGS += $(call cc-option,-fipa-ra,)
+
ifneq ($(CONFIG_FRAME_WARN),0)
KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
endif
--
2.6.3
next reply other threads:[~2015-12-01 6:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-01 6:00 Andi Kleen [this message]
2015-12-01 6:00 ` [PATCH] Kbuild: Enable interprocedural register allocation for gcc 5 Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448949643-6059-1-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox