[compiler-rt][ARM] cmake properties for complicated builtin sources (#179919)

In the builtins library, most functions have a portable C implementation
(e.g. `mulsf3.c`), and platforms might provide an optimized assembler
implementation (e.g. `arm/mulsf3.S`). The cmake script automatically
excludes the C source file corresponding to each assembly source file it
includes. Additionally, each source file name is automatically
translated into a flag that lit tests can query, with a name like
`librt_has_mulsf3`, to indicate that a function is available to be
tested.

In future commits I plan to introduce cases where a single .S file
provides more than one function (so that they can share code easily),
and therefore, must supersede more than one existing source file.

I've introduced the `crt_supersedes` cmake property, which you can set
on a .S file to name a list of .c files that it should supersede. Also,
the `crt_provides` property can be set on any source file to indicate a
list of functions it makes available for testing, in addition to the one
implied by its name.
This commit is contained in:
Simon Tatham 2026-03-23 16:01:12 +00:00 committed by GitHub
parent b2edc0a3f8
commit 44df4116c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 5 deletions

View File

@ -450,10 +450,14 @@ function(filter_builtin_sources inout_var name)
# and ensure that it is removed from the file list.
get_filename_component(_name ${_file} NAME)
string(REGEX REPLACE "\\.S$" ".c" _cname "${_name}")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_cname}")
message(STATUS "For ${name} builtins preferring ${_file} to ${_cname}")
list(REMOVE_ITEM intermediate ${_cname})
endif()
get_property(_cnames SOURCE ${_file} PROPERTY crt_supersedes)
set(_cnames ${_cname} ${_cnames})
foreach(_cname ${_cnames})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_cname}")
message(STATUS "For ${name} builtins preferring ${_file} to ${_cname}")
list(REMOVE_ITEM intermediate ${_cname})
endif()
endforeach()
endif()
endforeach()
set(${inout_var} ${intermediate} PARENT_SCOPE)

View File

@ -57,6 +57,19 @@ if (COMPILER_RT_STANDALONE_BUILD)
ON)
endif()
function(set_special_properties source_file)
cmake_parse_arguments(ARG "" "" "SUPERSEDES;PROVIDES" ${ARGN})
if(ARG_SUPERSEDES)
set_property(SOURCE ${source_file}
PROPERTY crt_supersedes "${ARG_SUPERSEDES}")
endif()
if(ARG_PROVIDES AND NOT COMPILER_RT_BUILTINS_STANDALONE_BUILD)
set_property(SOURCE ${source_file}
DIRECTORY ${COMPILER_RT_SOURCE_DIR}
PROPERTY crt_provides "${ARG_PROVIDES}")
endif()
endfunction()
include(builtin-config-ix)
include(CMakeDependentOption)
include(CMakePushCheckState)

View File

@ -143,7 +143,10 @@ foreach(arch ${BUILTIN_TEST_ARCH})
# "hexagon/udivsi3.S" => "udivsi3"
# "udivsi3.c" => "udivsi3"
get_filename_component(FILE_NAME_FILTERED "${file_name}" NAME_WE)
list(APPEND BUILTINS_LIT_SOURCE_FEATURES "librt_has_${FILE_NAME_FILTERED}")
get_property(_also_provided SOURCE "${COMPILER_RT_SOURCE_DIR}/lib/builtins/${file_name}" DIRECTORY ${COMPILER_RT_SOURCE_DIR} PROPERTY crt_provides)
foreach(_function "${FILE_NAME_FILTERED}" ${_also_provided})
list(APPEND BUILTINS_LIT_SOURCE_FEATURES "librt_has_${_function}")
endforeach()
endforeach()
string(TOUPPER ${arch} ARCH_UPPER_CASE)