[llvm] [LLVM] Add support to define lit test suites with a smaller set of dependencies (PR #155929)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 28 14:57:55 PDT 2025


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/155929

None

>From af61d5f16154ae9a56305e3bf888ff337b5fdff4 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 25 Aug 2025 19:16:35 -0700
Subject: [PATCH] Trim test deps

---
 llvm/cmake/modules/AddLLVM.cmake | 94 ++++++++++++++++++++++++++------
 llvm/test/CMakeLists.txt         | 33 +++++++++++
 2 files changed, 109 insertions(+), 18 deletions(-)

diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 835750e2d2a13..5a3866039816f 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2192,13 +2192,39 @@ endfunction()
 
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
-    cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER;BINARY_DIR" "PARAMS;DEPENDS;ARGS" ${ARGN})
+    cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER;BINARY_DIR"
+                          "PARAMS;DEPENDS;ARGS;EXCLUDE_DIR;INCLUDE_DIR" ${ARGN})
 
     if (NOT ARG_FOLDER)
       get_subproject_title(subproject_title)
       set(ARG_FOLDER "${subproject_title}/Tests/LIT Testsuites")
     endif()
 
+    # Create a list of excluded paths. If not empty, any directory that begins
+    # with one of the excluded paths will excluded, others will be included.
+    set(excluded_dirs "")
+    if (ARG_EXCLUDE_DIR)
+      foreach(path ${ARG_EXCLUDE_DIR})
+        list(APPEND excluded_dirs ${path})
+      endforeach()
+    endif()
+
+    # Create a list of included paths. If not empty, any directory that begins
+    # with any of the included paths will included, others will be excluded.
+    # If both included and excluded lists are empty, all directories will be
+    # included.
+    set(included_dirs "")
+    if (ARG_INCLUDE_DIR)
+      foreach(path ${ARG_INCLUDE_DIR})
+        list(APPEND included_dirs ${path})
+      endforeach()
+    endif()
+
+    if (excluded_dirs AND included_dirs)
+      message(FATAL_ERROR, "Cannot specify both include and exclude directories")
+    endif()
+
+
     # Search recursively for test directories by assuming anything not
     # in a directory called Inputs contains tests.
     file(GLOB_RECURSE to_process LIST_DIRECTORIES true ${directory}/*)
@@ -2214,24 +2240,56 @@ function(add_lit_testsuites project directory)
 
       # Create a check- target for the directory.
       string(REPLACE "${directory}/" "" name_slash ${lit_suite})
-      if (name_slash)
-        set(filter ${name_slash})
-        string(REPLACE "/" "-" name_slash ${name_slash})
-        string(REPLACE "\\" "-" name_dashes ${name_slash})
-        string(TOLOWER "${project}-${name_dashes}" name_var)
-        set(lit_args ${lit_suite})
-        if (ARG_BINARY_DIR)
-          set(lit_args ${ARG_BINARY_DIR} --filter=${filter})
-        endif()
-        add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}"
-          ${lit_args}
-          ${EXCLUDE_FROM_CHECK_ALL}
-          PARAMS ${ARG_PARAMS}
-          DEPENDS ${ARG_DEPENDS}
-          ARGS ${ARG_ARGS}
-        )
-        set_target_properties(check-${name_var} PROPERTIES FOLDER ${ARG_FOLDER})
+      if (NOT name_slash)
+        continue()
       endif()
+
+      # Determine whether to skip this directory.
+      if (excluded_dirs)
+        # Include by default, unless in the exclude list.
+        set(is_skipped false)
+        foreach (excluded_dir ${excluded_dirs})
+          string(FIND "${name_slash}" "${excluded_dir}" exclude_index)
+          if (exclude_index EQUAL 0)
+            set(is_skipped true)
+            break()
+          endif()
+        endforeach()
+      elseif(included_dirs)
+        # Exclude by default, unless in the include list.
+        set(is_skipped true)
+        foreach (included_dir ${included_dirs})
+          string(FIND "${name_slash}" "${included_dir}" include_index)
+          if (include_index EQUAL 0)
+            set(is_skipped false)
+            break()
+          endif()
+        endforeach()
+      else()
+        # Neither include nor exclude list specified. Include
+        set(is_skipped false)
+      endif()
+
+      if (is_skipped)
+        continue()
+      endif()
+
+      set(filter ${name_slash})
+      string(REPLACE "/" "-" name_slash ${name_slash})
+      string(REPLACE "\\" "-" name_dashes ${name_slash})
+      string(TOLOWER "${project}-${name_dashes}" name_var)
+      set(lit_args ${lit_suite})
+      if (ARG_BINARY_DIR)
+        set(lit_args ${ARG_BINARY_DIR} --filter=${filter})
+      endif()
+      add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}"
+        ${lit_args}
+        ${EXCLUDE_FROM_CHECK_ALL}
+        PARAMS ${ARG_PARAMS}
+        DEPENDS ${ARG_DEPENDS}
+        ARGS ${ARG_ARGS}
+      )
+      set_target_properties(check-${name_var} PROPERTIES FOLDER ${ARG_FOLDER})
     endforeach()
   endif()
 endfunction()
diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt
index f6333d68a8ea5..ab299cc4d53a0 100644
--- a/llvm/test/CMakeLists.txt
+++ b/llvm/test/CMakeLists.txt
@@ -259,10 +259,43 @@ add_lit_testsuite(check-llvm "Running the LLVM regression tests"
   )
 set_target_properties(check-llvm PROPERTIES FOLDER "LLVM/Tests")
 
+# Note, exclude TableGen and FileCheck directories as we define handle
+# them with a reduced set of dependencies below.
 add_lit_testsuites(LLVM ${CMAKE_CURRENT_SOURCE_DIR}
   ${exclude_from_check_all}
   DEPENDS ${LLVM_TEST_DEPENDS}
   FOLDER "Tests/Subdirectories"
+  EXCLUDE_DIR TableGen
+  EXCLUDE_DIR FileCheck
+  )
+
+# Subset of dependencies for TableGen lit test.
+set(LLVM_TEST_TABLEGEN_DEPENDS
+    FileCheck
+    count
+    llvm-config
+    llvm-tblgen
+    not
+  )
+
+add_lit_testsuites(LLVM ${CMAKE_CURRENT_SOURCE_DIR}
+  ${exclude_from_check_all}
+  DEPENDS ${LLVM_TEST_TABLEGEN_DEPENDS}
+  FOLDER "Tests/Subdirectories"
+  INCLUDE_DIR TableGen
+  )
+
+# Subset of dependencies for FileCheck lit test.
+set(LLVM_TEST_FILECHECK_DEPENDS
+    FileCheck
+    not
+  )
+
+add_lit_testsuites(LLVM ${CMAKE_CURRENT_SOURCE_DIR}
+  ${exclude_from_check_all}
+  DEPENDS ${LLVM_TEST_FILECHECK_DEPENDS}
+  FOLDER "Tests/Subdirectories"
+  INCLUDE_DIR FileCheck
   )
 
 # Setup an alias for 'check-all'.



More information about the llvm-commits mailing list