Skip to contentSkip to conversation

Kbuild: Enable interprocedural register allocation for gcc 5

PATCH New Andi Kleen 1 participant 1 message Dec 1, 2015

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Kbuild: Enable interprocedural register allocation for gcc 5

From: Andi Kleen <[email protected]>

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.

---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +6 -0
index 2ffdf9d..c95320f 100644
@@ -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
Signature · 1 line
2.6.3