qemu/accel
Richard Henderson 6b8b622e87 cputlb: Make store_helper less fragile to compiler optimizations
This has no functional change.

The current function structure is:

    inline QEMU_ALWAYSINLINE
    store_memop() {
        switch () {
            ...
        default:
            qemu_build_not_reached();
        }
    }
    inline QEMU_ALWAYSINLINE
    store_helper() {
        ...
        if (span_two_pages_or_io) {
            ...
            helper_ret_stb_mmu();
        }
        store_memop();
    }
    helper_ret_stb_mmu() {
        store_helper();
    }

Whereas GCC will generate an error at compile-time when an always_inline
function is not inlined, Clang does not.  Nor does Clang prioritize the
inlining of always_inline functions.  Both of these are arguably bugs.

Both `store_memop` and `store_helper` need to be inlined and allow
constant propogations to eliminate the `qemu_build_not_reached` call.

However, if the compiler instead chooses to inline helper_ret_stb_mmu
into store_helper, then store_helper is now self-recursive and the
compiler is no longer able to propagate the constant in the same way.

This does not produce at current QEMU head, but was reproducible
at v4.2.0 with `clang-10 -O2 -fexperimental-new-pass-manager`.

The inline recursion problem can be fixed solely by marking
helper_ret_stb_mmu as noinline, so the compiler does not make an
incorrect decision about which functions to inline.

In addition, extract store_helper_unaligned as a noinline subroutine
that can be shared by all of the helpers.  This saves about 6k code
size in an optimized x86_64 build.

Reported-by: Shu-Chun Weng <scw@google.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2020-09-03 13:13:58 -07:00
..
kvm meson: accel 2020-08-21 06:30:36 -04:00
stubs meson: accel 2020-08-21 06:30:36 -04:00
tcg cputlb: Make store_helper less fragile to compiler optimizations 2020-09-03 13:13:58 -07:00
xen meson: accel 2020-08-21 06:30:36 -04:00
accel.c accel: Introduce the current_accel() wrapper 2020-01-24 20:59:11 +01:00
Kconfig accel/Kconfig: Add the TCG selector 2020-07-10 18:02:21 -04:00
meson.build meson: accel 2020-08-21 06:30:36 -04:00
qtest.c qtest: Don't compile qtest accel on non-POSIX systems 2019-05-02 16:56:33 +02:00