]> git.ipfire.org Git - thirdparty/gcc.git/commit
bpf: liberate R9 for general register allocation
authorJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 10 Aug 2023 19:17:53 +0000 (21:17 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Fri, 11 Aug 2023 18:34:57 +0000 (20:34 +0200)
commitf93a612fc4567652b75ffc916d31a446378e6613
treee7d1e2e5bb61b7c12f1ac72b6ed45d8078d412a7
parent6103df1e4fae5192c507484b1d32f00c42c70b54
bpf: liberate R9 for general register allocation

We were reserving one of the hard registers in BPF in order to
implement dynamic stack allocation: alloca and VLAs. However, there is
kernel code that has inline assembly that requires all the non-fixed
registers to be available for register allocation.

This patch:

1. Liberates r9 that is now available for register allocation.

2. Adds a check to GCC so it errors out if the user tries to do
   dynamic stack allocation.  A couple of tests are added for this.

3. Changes xbpf so it no longer saves and restores callee-saved
   registers.  A couple of tests for this have been removed.

4. Adds bpf-*-* to the list of targets that do not support alloca in
   target-support.exp.

Tested in host x86_64-linux-gnu and target bpf-unknown-none.

gcc/ChangeLog

* config/bpf/bpf.md (allocate_stack): Define.
* config/bpf/bpf.h (FIRST_PSEUDO_REGISTER): Make room for fake
stack pointer register.
(FIXED_REGISTERS): Adjust accordingly.
(CALL_USED_REGISTERS): Likewise.
(REG_CLASS_CONTENTS): Likewise.
(REGISTER_NAMES): Likewise.
* config/bpf/bpf.cc (bpf_compute_frame_layout): Do not reserve
space for callee-saved registers.
(bpf_expand_prologue): Do not save callee-saved registers in xbpf.
(bpf_expand_epilogue): Do not restore callee-saved registers in
xbpf.

gcc/testsuite/ChangeLog

* lib/target-supports.exp (check_effective_target_alloca): BPF
target does not support alloca.
* gcc.target/bpf/diag-alloca-1.c: New test.
* gcc.target/bpf/diag-alloca-2.c: Likewise.
* gcc.target/bpf/xbpf-callee-saved-regs-1.c: Remove test.
* gcc.target/bpf/xbpf-callee-saved-regs-2.c: Likewise.
* gcc.target/bpf/regs-availability-1.c: Likewise.
gcc/config/bpf/bpf.cc
gcc/config/bpf/bpf.h
gcc/config/bpf/bpf.md
gcc/testsuite/gcc.target/bpf/diag-alloca-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/bpf/diag-alloca-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/bpf/regs-availability-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/bpf/xbpf-callee-saved-regs-1.c [deleted file]
gcc/testsuite/gcc.target/bpf/xbpf-callee-saved-regs-2.c [deleted file]
gcc/testsuite/lib/target-supports.exp