From patchwork Thu May 14 12:30:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rini X-Patchwork-Id: 245809 List-Id: U-Boot discussion From: trini at konsulko.com (Tom Rini) Date: Thu, 14 May 2020 08:30:07 -0400 Subject: [PATCH 08/10] compiler_types.h: Re-introduce CONFIG_OPTIMIZE_INLINING for U-Boot In-Reply-To: <20200514123009.5721-1-trini@konsulko.com> References: <20200514123009.5721-1-trini@konsulko.com> Message-ID: <20200514123009.5721-8-trini@konsulko.com> In the Linux kernel, support for forcing inline functions to be made inline, rather than allowing the compiler to make its own choice has been removed. With respect to performance, modern GCC (and Clang) do a good job at deciding when to, or not to, inline code and there are no run-time requirements in Linux anymore. There is one downside to this, which is final binary size. On average in U-Boot removing this support grows SPL by almost 1 kilobyte. But there are cases where it shrinks the binary by making better inline choices than we had forced. Start by re-introducing CONFIG_OPTIMIZE_INLINING as a global which essentially reverts 889b3c1245de ("compiler: remove CONFIG_OPTIMIZE_INLINING entirely") from Linux. Cc: Masahiro Yamada Signed-off-by: Tom Rini --- Kconfig | 9 +++++++++ include/linux/compiler_types.h | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Kconfig b/Kconfig index 37cc9445180f..b582db24f5d0 100644 --- a/Kconfig +++ b/Kconfig @@ -64,6 +64,15 @@ config CC_OPTIMIZE_FOR_SIZE This option is enabled by default for U-Boot. +config OPTIMIZE_INLINING + bool "Allow compiler to uninline functions marked 'inline'" + default n + help + This option determines if U-Boot forces gcc to inline the functions + developers have marked 'inline'. Doing so takes away freedom from gcc to + do what it thinks is best, which is desirable in some cases for size + reasons. + config CC_COVERAGE bool "Enable code coverage analysis" depends on SANDBOX diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index e970f97a7fcb..72393a8c1a6c 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -129,13 +129,22 @@ struct ftrace_likely_data { #define __compiler_offsetof(a, b) __builtin_offsetof(a, b) /* + * Force always-inline if the user requests it so via the .config. * Prefer gnu_inline, so that extern inline functions do not emit an * externally visible function. This makes extern inline behave as per gnu89 * semantics rather than c99. This prevents multiple symbol definition errors * of extern inline functions at link time. * A lot of inline functions can cause havoc with function tracing. + * Do not use __always_inline here, since currently it expands to inline again + * (which would break users of __always_inline). */ -#define inline inline __gnu_inline __inline_maybe_unused notrace +#if !defined(CONFIG_OPTIMIZE_INLINING) +#define inline inline __attribute__((__always_inline__)) __gnu_inline \ + __inline_maybe_unused notrace +#else +#define inline inline __gnu_inline \ + __inline_maybe_unused notrace +#endif /* * gcc provides both __inline__ and __inline as alternate spellings of