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

Simon Tatham via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 5 04:00:38 PST 2026


https://github.com/statham-arm created https://github.com/llvm/llvm-project/pull/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.

>From a3aea535529ca7ac6e090f62a7453075adb7bbb8 Mon Sep 17 00:00:00 2001
From: Simon Tatham <simon.tatham at arm.com>
Date: Thu, 29 Jan 2026 14:21:23 +0000
Subject: [PATCH] [compiler-rt][ARM] cmake properties for complicated builtin
 sources

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.
---
 compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 12 ++++++++----
 compiler-rt/test/builtins/CMakeLists.txt        |  5 ++++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index cbd18d26c0b93..a09a870ed8384 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -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)
diff --git a/compiler-rt/test/builtins/CMakeLists.txt b/compiler-rt/test/builtins/CMakeLists.txt
index 1d4e69602ee9f..9c7f404242f22 100644
--- a/compiler-rt/test/builtins/CMakeLists.txt
+++ b/compiler-rt/test/builtins/CMakeLists.txt
@@ -123,7 +123,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)



More information about the llvm-branch-commits mailing list