[compiler-rt] [compiler-rt] Improve lit test discovery speed on Darwin (PR #195193)

Andrew Haberlandt via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 15:54:01 PDT 2026


https://github.com/ndrewh created https://github.com/llvm/llvm-project/pull/195193

compiler-rt lit test discovery takes quite a while on Darwin (i.e. the time from when you launch llvm-lit to when the first test runs). This improves a couple of operations that take up the most time:

- We are asking clang for its resource directory many times. Adds a cache (global to each invocation of `llvm-lit` for `get_path_from_clang`.
- `log show` can be quite slow. Let's only check it for ASAN, because that's the only suite that needs to know if it works.

rdar://175893448

>From 63b793d9e33fd527d7bf40c2f912f9a564e5438b Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Thu, 30 Apr 2026 15:49:04 -0700
Subject: [PATCH] [Darwin] [compiler-rt] Improve lit test discovery speed on
 Darwin

- We are asking clang for its resource directory many times. Adds a cache for that.
- `log show` can be a bit slow. Let's only do it for ASAN, because that's the only suite that needs to know if it works.

rdar://175893448
---
 compiler-rt/test/asan/lit.cfg.py   | 20 +++++++++++++++++++
 compiler-rt/test/lit.common.cfg.py | 32 ++++++++++++------------------
 2 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py
index 0194c720d003b..11bbccae0dbaf 100644
--- a/compiler-rt/test/asan/lit.cfg.py
+++ b/compiler-rt/test/asan/lit.cfg.py
@@ -4,6 +4,7 @@
 import platform
 import re
 import shlex
+import subprocess
 
 import lit.formats
 
@@ -334,3 +335,22 @@ def build_invocation(compile_flags, with_lto=False):
 
 if config.target_os == "NetBSD":
     config.substitutions.insert(0, ("%run", config.netbsd_noaslr_prefix))
+
+if config.target_os == "Darwin":
+    if lit.util.which("log"):
+        # Querying the log can only done by a privileged user so
+        # so check if we can query the log.
+        exit_code = -1
+        with open("/dev/null", "r") as f:
+            # Run a `log show` command the should finish fairly quickly and produce very little output.
+            exit_code = subprocess.call(
+                ["log", "show", "--last", "1m", "--predicate", "1 == 0"],
+                stdout=f,
+                stderr=f,
+            )
+        if exit_code == 0:
+            config.available_features.add("darwin_log_cmd")
+        else:
+            lit_config.warning("log command found but cannot queried")
+    else:
+        lit_config.warning("log command not found. Some tests will be skipped.")
diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index fef8f7ab297cc..9d81e2295a508 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -13,14 +13,23 @@
 import lit.formats
 import lit.util
 
-
 def get_path_from_clang(args, allow_failure):
+    clang_path_cache = getattr(lit_config, "_clang_path_cache", None)
+
+    if clang_path_cache is None:
+        clang_path_cache = {}
+        setattr(lit_config, "_clang_path_cache", clang_path_cache)
+
     clang_cmd = [
         config.clang.strip(),
         f"--target={config.target_triple}",
         *args,
     ]
-    path = None
+
+    path = clang_path_cache.get(tuple(clang_cmd))
+    if path is not None:
+        return path, clang_cmd
+
     try:
         result = subprocess.run(
             clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True
@@ -32,6 +41,8 @@ def get_path_from_clang(args, allow_failure):
             lit_config.warning(msg)
         else:
             lit_config.fatal(msg)
+
+    clang_path_cache[tuple(clang_cmd)] = path
     return path, clang_cmd
 
 
@@ -952,23 +963,6 @@ def is_windows_lto_supported():
     # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
     config.default_sanitizer_opts += ["abort_on_error=0"]
     config.default_sanitizer_opts += ["log_to_syslog=0"]
-    if lit.util.which("log"):
-        # Querying the log can only done by a privileged user so
-        # so check if we can query the log.
-        exit_code = -1
-        with open("/dev/null", "r") as f:
-            # Run a `log show` command the should finish fairly quickly and produce very little output.
-            exit_code = subprocess.call(
-                ["log", "show", "--last", "1m", "--predicate", "1 == 0"],
-                stdout=f,
-                stderr=f,
-            )
-        if exit_code == 0:
-            config.available_features.add("darwin_log_cmd")
-        else:
-            lit_config.warning("log command found but cannot queried")
-    else:
-        lit_config.warning("log command not found. Some tests will be skipped.")
 elif config.android:
     config.default_sanitizer_opts += ["abort_on_error=0"]
 



More information about the llvm-commits mailing list