[PATCH v2 4/4] kbuild: Add config to assert profile accuracy for aggressive optimization

From: xur

Date: Tue Oct 14 2025 - 15:12:06 EST


From: Rong Xu <xur@xxxxxxxxxx>

Adds a build config to AutoFDO to assert that the generated profile
accurately represents the intended workload. This enables Clang to
perform more aggressive optimizations.

Signed-off-by: Rong Xu <xur@xxxxxxxxxx>
---
arch/Kconfig | 11 +++++++++++
scripts/Makefile.autofdo | 3 +++
2 files changed, 14 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index ebe08b9186adc..6fdc676cb0fe4 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -886,6 +886,17 @@ config AUTOFDO_CLANG

If unsure, say N.

+config AUTOFDO_PROFILE_ACCURATE
+ bool "Assert AutoFDO profile is accurate (EXPERIMENTAL)"
+ depends on AUTOFDO_CLANG
+ help
+ This option asserts that the AutoFDO profile (specified
+ in CLANG_AUTOFDO_PROFILE) is collected from a representative
+ workload, allowing the Clang compiler to perform more
+ aggressive optimizations.
+
+ If unsure, say N.
+
config ARCH_SUPPORTS_PROPELLER_CLANG
bool

diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo
index 5bcfcef273745..36abeae2accdc 100644
--- a/scripts/Makefile.autofdo
+++ b/scripts/Makefile.autofdo
@@ -11,6 +11,9 @@ endif
ifdef CLANG_AUTOFDO_PROFILE
CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections
CFLAGS_AUTOFDO_CLANG += -fsplit-machine-functions
+ifdef CONFIG_AUTOFDO_PROFILE_ACCURATE
+ CFLAGS_AUTOFDO_CLANG += -fprofile-sample-accurate
+endif
endif

ifdef CONFIG_LTO_CLANG_THIN
--
2.51.0.788.g6d19910ace-goog