[libc-commits] [libc] [libc][cmake] Cache compile options from config and arch to speed up configuration. (PR #225438)
via libc-commits
libc-commits at lists.llvm.org
Mon Oct 12 20:13:37 PDT 2026
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/225438
>From bdf9ed2645a732cda597a25a80217708504e2f2a Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 15 Sep 2026 17:38:11 +0000
Subject: [PATCH] [libc][cmake] Precompute common compile options to speed up
configuration
Precompute the invariant compile options from config, arch, and compiler
settings once when `LLVMLibCCompileOptionRules.cmake` and
`LLVMLibCTestRules.cmake` are included, rather than recomputing them for
every entrypoint object and test target (4,500+ times per configure). Also
add an early return in `_get_compile_options_from_flags` when no flags are
supplied.
---
.../modules/LLVMLibCCompileOptionRules.cmake | 21 +++++---
libc/cmake/modules/LLVMLibCTestRules.cmake | 52 +++++++++++++++----
2 files changed, 58 insertions(+), 15 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 95f398e10855f..98aab039a6362 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -36,6 +36,11 @@ function(libc_set_definition output_var)
endfunction()
function(_get_compile_options_from_flags output_var)
+ if(NOT ARGN)
+ set(${output_var} "" PARENT_SCOPE)
+ return()
+ endif()
+
set(compile_options "")
if(LIBC_CPU_FEATURES MATCHES "FMA")
@@ -207,6 +212,7 @@ function(_get_compile_options_from_config output_var)
set(${output_var} ${config_options} PARENT_SCOPE)
endfunction()
+_get_compile_options_from_config(LIBC_COMPILE_OPTIONS_FROM_CONFIG)
function(_get_compile_options_from_arch output_var)
# Set options that are not found in src/__support/macros/properties/architectures.h
@@ -226,13 +232,10 @@ function(_get_compile_options_from_arch output_var)
set(${output_var} ${config_options} PARENT_SCOPE)
endfunction()
+_get_compile_options_from_arch(LIBC_COMPILE_OPTIONS_FROM_ARCH)
-function(_get_common_compile_options output_var flags)
- _get_compile_options_from_flags(compile_flags ${flags})
- _get_compile_options_from_config(config_flags)
- _get_compile_options_from_arch(arch_flags)
-
- set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${compile_flags} ${config_flags} ${arch_flags})
+function(_get_common_compile_options_impl output_var)
+ set(compile_options ${LIBC_COMPILE_OPTIONS_FROM_CONFIG} ${LIBC_COMPILE_OPTIONS_FROM_ARCH})
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
if(LLVM_LIBC_FULL_BUILD)
@@ -357,3 +360,9 @@ function(_get_common_compile_options output_var flags)
endif()
set(${output_var} ${compile_options} PARENT_SCOPE)
endfunction()
+_get_common_compile_options_impl(LIBC_COMMON_COMPILE_OPTIONS)
+
+function(_get_common_compile_options output_var flags)
+ _get_compile_options_from_flags(compile_flags ${flags})
+ set(${output_var} ${LIBC_COMPILE_OPTIONS_DEFAULT} ${compile_flags} ${LIBC_COMMON_COMPILE_OPTIONS} PARENT_SCOPE)
+endfunction()
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index cde5519d0a315..24e6985b85644 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -4,10 +4,9 @@ else()
set(LIBC_TEST_SUBPROCESS_TESTS 0)
endif()
-function(_get_common_test_compile_options output_var c_test flags)
- _get_compile_options_from_flags(compile_flags ${flags})
- _get_compile_options_from_config(config_flags)
- _get_compile_options_from_arch(arch_flags)
+function(_get_common_test_compile_options_impl output_var c_test)
+ set(config_flags ${LIBC_COMPILE_OPTIONS_FROM_CONFIG})
+ set(arch_flags ${LIBC_COMPILE_OPTIONS_FROM_ARCH})
# Death test executor is only available in Linux for now.
if(NOT ${LIBC_TARGET_OS} STREQUAL "linux")
@@ -19,9 +18,6 @@ function(_get_common_test_compile_options output_var c_test flags)
endif()
set(compile_options
- ${LIBC_COMPILE_OPTIONS_DEFAULT}
- ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
- ${compile_flags}
${config_flags}
${arch_flags})
libc_add_definition(compile_options
@@ -109,9 +105,30 @@ function(_get_common_test_compile_options output_var c_test flags)
endif()
set(${output_var} ${compile_options} PARENT_SCOPE)
endfunction()
+_get_common_test_compile_options_impl(LIBC_COMMON_TEST_COMPILE_OPTIONS_CPP FALSE)
+_get_common_test_compile_options_impl(LIBC_COMMON_TEST_COMPILE_OPTIONS_C TRUE)
-function(_get_hermetic_test_compile_options output_var c_test flags)
- _get_common_test_compile_options(compile_options "${c_test}" "${flags}")
+function(_get_common_test_compile_options output_var c_test flags)
+ _get_compile_options_from_flags(compile_flags ${flags})
+ if(c_test)
+ set(common_test_opts ${LIBC_COMMON_TEST_COMPILE_OPTIONS_C})
+ else()
+ set(common_test_opts ${LIBC_COMMON_TEST_COMPILE_OPTIONS_CPP})
+ endif()
+ set(${output_var}
+ ${LIBC_COMPILE_OPTIONS_DEFAULT}
+ ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
+ ${compile_flags}
+ ${common_test_opts}
+ PARENT_SCOPE)
+endfunction()
+
+function(_get_hermetic_test_compile_options_impl output_var c_test)
+ if(c_test)
+ set(compile_options ${LIBC_COMMON_TEST_COMPILE_OPTIONS_C})
+ else()
+ set(compile_options ${LIBC_COMMON_TEST_COMPILE_OPTIONS_CPP})
+ endif()
# null check tests are death tests, remove from hermetic tests for now.
if(LIBC_ADD_NULL_CHECKS)
@@ -135,6 +152,23 @@ function(_get_hermetic_test_compile_options output_var c_test flags)
set(${output_var} ${compile_options} PARENT_SCOPE)
endfunction()
+_get_hermetic_test_compile_options_impl(LIBC_HERMETIC_TEST_COMPILE_OPTIONS_CPP FALSE)
+_get_hermetic_test_compile_options_impl(LIBC_HERMETIC_TEST_COMPILE_OPTIONS_C TRUE)
+
+function(_get_hermetic_test_compile_options output_var c_test flags)
+ _get_compile_options_from_flags(compile_flags ${flags})
+ if(c_test)
+ set(hermetic_test_opts ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS_C})
+ else()
+ set(hermetic_test_opts ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS_CPP})
+ endif()
+ set(${output_var}
+ ${LIBC_COMPILE_OPTIONS_DEFAULT}
+ ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
+ ${compile_flags}
+ ${hermetic_test_opts}
+ PARENT_SCOPE)
+endfunction()
# This is a helper function and not a build rule. It is to be used by the
# various test rules to generate the full list of object files
More information about the libc-commits
mailing list