[libc-commits] [libc] [libc] Remove recursion in get_object_files_for_test to improve build time. (PR #72351)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 14 22:22:25 PST 2023


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/72351

None

>From 47db6e878056a7feca333446d597473cee6da1af Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 15 Nov 2023 01:19:14 -0500
Subject: [PATCH] [libc] Remove recursion in get_object_files_for_test to
 improve build time.

---
 libc/cmake/modules/LLVMLibCTestRules.cmake | 84 ++++++++++++----------
 1 file changed, 48 insertions(+), 36 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index f7ca6a2e7021141..7484daaa22db4d4 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -15,48 +15,60 @@
 function(get_object_files_for_test result skipped_entrypoints_list)
   set(object_files "")
   set(skipped_list "")
-  foreach(dep IN LISTS ARGN)
-    if (NOT TARGET ${dep})
-      # Skip any tests whose dependencies have not been defined.
-      list(APPEND skipped_list ${dep})
-      continue()
-    endif()
-    get_target_property(dep_type ${dep} "TARGET_TYPE")
-    if(NOT dep_type)
-      # Target for which TARGET_TYPE property is not set do not
-      # provide any object files.
-      continue()
-    endif()
+  set(checked_list "")
+  set(unchecked_list "${ARGN}")
+  list(REMOVE_DUPLICATES unchecked_list)
+  list(LENGTH unchecked_list length)
 
-    if(${dep_type} STREQUAL ${OBJECT_LIBRARY_TARGET_TYPE})
-      get_target_property(dep_object_files ${dep} "OBJECT_FILES")
-      if(dep_object_files)
-        list(APPEND object_files ${dep_object_files})
-      endif()
-    elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE})
-      get_target_property(is_skipped ${dep} "SKIPPED")
-      if(is_skipped)
+  while(length)
+    set(indirect_list "")
+
+    foreach(dep IN LISTS unchecked_list)
+      if (NOT TARGET ${dep})
+        # Skip any tests whose dependencies have not been defined.
         list(APPEND skipped_list ${dep})
         continue()
       endif()
-      get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
-      if(object_file_raw)
-        list(APPEND object_files ${object_file_raw})
+      get_target_property(dep_type ${dep} "TARGET_TYPE")
+      if(NOT dep_type)
+        # Target for which TARGET_TYPE property is not set do not
+        # provide any object files.
+        continue()
       endif()
-    elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_VENDOR_TARGET_TYPE})
-      # We skip tests for all externally implemented entrypoints.
-      list(APPEND skipped_list ${dep})
-      continue()
-    endif()
 
-    get_target_property(indirect_deps ${dep} "DEPS")
-    get_object_files_for_test(
-        indirect_objfiles indirect_skipped_list ${indirect_deps})
-    list(APPEND object_files ${indirect_objfiles})
-    if(indirect_skipped_list)
-      list(APPEND skipped_list ${indirect_skipped_list})
-    endif()
-  endforeach(dep)
+      if(${dep_type} STREQUAL ${OBJECT_LIBRARY_TARGET_TYPE})
+        get_target_property(dep_object_files ${dep} "OBJECT_FILES")
+        if(dep_object_files)
+          list(APPEND object_files ${dep_object_files})
+        endif()
+      elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE})
+        get_target_property(is_skipped ${dep} "SKIPPED")
+        if(is_skipped)
+          list(APPEND skipped_list ${dep})
+          continue()
+        endif()
+        get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
+        if(object_file_raw)
+          list(APPEND object_files ${object_file_raw})
+        endif()
+      elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_VENDOR_TARGET_TYPE})
+        # We skip tests for all externally implemented entrypoints.
+        list(APPEND skipped_list ${dep})
+        continue()
+      endif()
+
+      get_target_property(indirect_deps ${dep} "DEPS")
+      list(APPEND indirect_list "${indirect_deps}")
+    endforeach(dep)
+
+    # Only add new indirect dependencies to check.
+    list(APPEND checked_list "${unchecked_list}")
+    list(REMOVE_DUPLICATES indirect_list)
+    list(REMOVE_ITEM indirect_list checked_list)
+    set(unchecked_list "${indirect_list}")
+    list(LENGTH unchecked_list length)
+  endwhile()
+
   list(REMOVE_DUPLICATES object_files)
   set(${result} ${object_files} PARENT_SCOPE)
   list(REMOVE_DUPLICATES skipped_list)



More information about the libc-commits mailing list