[llvm] [CI][Github] Enable CIR CI build and test (PR #147430)

Andy Kaylor via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 09:51:13 PDT 2025


https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/147430

>From 233b53a39fd88c22ede4eb36a3581268251d9089 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Mon, 7 Jul 2025 16:35:41 -0700
Subject: [PATCH 1/5] [Github] Enable CIR CI build and test

This change modifies CI scripts to add a pseudo-project for CIR and
detect when CIR-specific files are modified. It also enables building
clang with CIR enabled whenever both the clang and mlir projects are
being built and enables CIR testing when the mlir project is modified.

Building and testing CIR is only enabled on Linux at this time, as CIR
doesn't properly support Windows or MacOS yet.
---
 .ci/compute_projects.py         | 28 ++++++++++++++++++++++++++--
 .ci/monolithic-linux.sh         |  2 ++
 .github/workflows/premerge.yaml |  2 +-
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/.ci/compute_projects.py b/.ci/compute_projects.py
index c3cf714ce6c10..25e8bf8eaf981 100644
--- a/.ci/compute_projects.py
+++ b/.ci/compute_projects.py
@@ -19,6 +19,7 @@
 PROJECT_DEPENDENCIES = {
     "llvm": set(),
     "clang": {"llvm"},
+    "CIR": {"clang", "mlir"},
     "bolt": {"clang", "lld", "llvm"},
     "clang-tools-extra": {"clang", "llvm"},
     "compiler-rt": {"clang", "lld"},
@@ -50,11 +51,15 @@
     "lld": {"bolt", "cross-project-tests"},
     # TODO(issues/132795): LLDB should be enabled on clang changes.
     "clang": {"clang-tools-extra", "cross-project-tests"},
-    "mlir": {"flang"},
+    "mlir": {
+        "CIR",
+        "flang",
+    },
     # Test everything if ci scripts are changed.
     ".ci": {
         "llvm",
         "clang",
+        "CIR",
         "lld",
         "lldb",
         "bolt",
@@ -128,6 +133,7 @@
     "lldb": "check-lldb",
     "llvm": "check-llvm",
     "clang": "check-clang",
+    "CIR": "check-clang-cir",
     "bolt": "check-bolt",
     "lld": "check-lld",
     "flang": "check-flang",
@@ -192,7 +198,12 @@ def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set
 def _compute_projects_to_build(
     projects_to_test: Set[str], runtimes: Set[str]
 ) -> Set[str]:
-    return _add_dependencies(projects_to_test, runtimes)
+    projects_with_deps = _add_dependencies(projects_to_test, runtimes)
+    # CIR is used as a pseudo-project in this script. We detect modifications
+    # to clang's CIR-specific subdirectories and add CIR as a modified project
+    # if a file in these directories is modified, but we need to remove it
+    # explicitly here.
+    return projects_with_deps - {"CIR"}
 
 
 def _compute_project_check_targets(projects_to_test: Set[str]) -> Set[str]:
@@ -247,6 +258,14 @@ def _get_modified_projects(modified_files: list[str]) -> Set[str]:
         # capacity.
         if len(path_parts) > 3 and path_parts[:3] == ("llvm", "utils", "gn"):
             continue
+        # If the file is in the clang/lib/CIR directory, add the CIR project.
+        if (len(path_parts) > 3 and
+               (path_parts[:3] == ("clang", "lib", "CIR") or
+                path_parts[:3] == ("clang", "test", "CIR") or
+                path_parts[:4] == ("clang", "include", "clang", "CIR"))):
+            modified_projects.add("clang")
+            modified_projects.add("CIR")
+            continue
         modified_projects.add(pathlib.Path(modified_file).parts[0])
     return modified_projects
 
@@ -267,6 +286,10 @@ def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
     runtimes_check_targets_needs_reconfig = _compute_project_check_targets(
         runtimes_to_test_needs_reconfig
     )
+
+    # Check if both clang and mlir are in projects_to_build to enable CIR
+    enable_cir = "ON" if "clang" in projects_to_build and "mlir" in projects_to_build else "OFF"
+
     # We use a semicolon to separate the projects/runtimes as they get passed
     # to the CMake invocation and thus we need to use the CMake list separator
     # (;). We use spaces to separate the check targets as they end up getting
@@ -279,6 +302,7 @@ def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
         "runtimes_check_targets_needs_reconfig": " ".join(
             sorted(runtimes_check_targets_needs_reconfig)
         ),
+        "enable_cir": enable_cir,
     }
 
 
diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 8d1faab13986c..0d35becdd8c8f 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -53,6 +53,7 @@ targets="${2}"
 runtimes="${3}"
 runtime_targets="${4}"
 runtime_targets_needs_reconfig="${5}"
+enable_cir="${6}"
 
 lit_args="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml --use-unique-output-file-name --timeout=1200 --time-tests"
 
@@ -72,6 +73,7 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
       -G Ninja \
       -D CMAKE_PREFIX_PATH="${HOME}/.local" \
       -D CMAKE_BUILD_TYPE=Release \
+      -D CLANG_ENABLE_CIR=${enable_cir} \
       -D LLVM_ENABLE_ASSERTIONS=ON \
       -D LLVM_BUILD_EXAMPLES=ON \
       -D COMPILER_RT_BUILD_LIBFUZZER=OFF \
diff --git a/.github/workflows/premerge.yaml b/.github/workflows/premerge.yaml
index 4435a3e905768..6ccc9f607ccf7 100644
--- a/.github/workflows/premerge.yaml
+++ b/.github/workflows/premerge.yaml
@@ -61,7 +61,7 @@ jobs:
           export CC=/opt/llvm/bin/clang
           export CXX=/opt/llvm/bin/clang++
 
-          ./.ci/monolithic-linux.sh "${projects_to_build}" "${project_check_targets}" "${runtimes_to_build}" "${runtimes_check_targets}" "${runtimes_check_targets_needs_reconfig}"
+          ./.ci/monolithic-linux.sh "${projects_to_build}" "${project_check_targets}" "${runtimes_to_build}" "${runtimes_check_targets}" "${runtimes_check_targets_needs_reconfig}" "${enable_cir}"
       - name: Upload Artifacts
         uses: actions/upload-artifact at 65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
         with:

>From cbb524b017c15dced7aabda1d9c6db5174eb3c53 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Mon, 7 Jul 2025 17:09:22 -0700
Subject: [PATCH 2/5] Fix formatting

---
 .ci/compute_projects.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/.ci/compute_projects.py b/.ci/compute_projects.py
index 25e8bf8eaf981..0d07f90e2cac1 100644
--- a/.ci/compute_projects.py
+++ b/.ci/compute_projects.py
@@ -259,10 +259,11 @@ def _get_modified_projects(modified_files: list[str]) -> Set[str]:
         if len(path_parts) > 3 and path_parts[:3] == ("llvm", "utils", "gn"):
             continue
         # If the file is in the clang/lib/CIR directory, add the CIR project.
-        if (len(path_parts) > 3 and
-               (path_parts[:3] == ("clang", "lib", "CIR") or
-                path_parts[:3] == ("clang", "test", "CIR") or
-                path_parts[:4] == ("clang", "include", "clang", "CIR"))):
+        if len(path_parts) > 3 and (
+            path_parts[:3] == ("clang", "lib", "CIR") or
+            path_parts[:3] == ("clang", "test", "CIR") or
+            path_parts[:4] == ("clang", "include", "clang", "CIR")
+        ):
             modified_projects.add("clang")
             modified_projects.add("CIR")
             continue
@@ -288,7 +289,9 @@ def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
     )
 
     # Check if both clang and mlir are in projects_to_build to enable CIR
-    enable_cir = "ON" if "clang" in projects_to_build and "mlir" in projects_to_build else "OFF"
+    enable_cir = (
+        "ON" if "clang" in projects_to_build and "mlir" in projects_to_build else "OFF"
+    )
 
     # We use a semicolon to separate the projects/runtimes as they get passed
     # to the CMake invocation and thus we need to use the CMake list separator

>From ac5415748fa3f02cb651df6828c83fbd99517aa7 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Mon, 7 Jul 2025 17:13:54 -0700
Subject: [PATCH 3/5] Fix formatting again

---
 .ci/compute_projects.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.ci/compute_projects.py b/.ci/compute_projects.py
index 0d07f90e2cac1..865f9aa100ae7 100644
--- a/.ci/compute_projects.py
+++ b/.ci/compute_projects.py
@@ -260,9 +260,9 @@ def _get_modified_projects(modified_files: list[str]) -> Set[str]:
             continue
         # If the file is in the clang/lib/CIR directory, add the CIR project.
         if len(path_parts) > 3 and (
-            path_parts[:3] == ("clang", "lib", "CIR") or
-            path_parts[:3] == ("clang", "test", "CIR") or
-            path_parts[:4] == ("clang", "include", "clang", "CIR")
+            path_parts[:3] == ("clang", "lib", "CIR")
+            or path_parts[:3] == ("clang", "test", "CIR")
+            or path_parts[:4] == ("clang", "include", "clang", "CIR")
         ):
             modified_projects.add("clang")
             modified_projects.add("CIR")

>From 5f6bda7980371f14c4f0527b6fa19c2b61daad95 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Tue, 8 Jul 2025 09:28:33 -0700
Subject: [PATCH 4/5] Update compute_projects_test.py

---
 .ci/compute_projects_test.py | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/.ci/compute_projects_test.py b/.ci/compute_projects_test.py
index 6299931e1ec34..3f7ed33d340b8 100644
--- a/.ci/compute_projects_test.py
+++ b/.ci/compute_projects_test.py
@@ -104,6 +104,10 @@ def test_clang(self):
             env_variables["runtimes_check_targets_needs_reconfig"],
             "check-cxx check-cxxabi check-unwind",
         )
+        self.assertEqual(
+            env_variables["enable_cir"],
+            "OFF",
+        )
 
     def test_clang_windows(self):
         env_variables = compute_projects.get_env_variables(
@@ -126,6 +130,32 @@ def test_clang_windows(self):
             env_variables["runtimes_check_targets_needs_reconfig"],
             "check-cxx check-cxxabi check-unwind",
         )
+        self.assertEqual(env_variables["enable_cir"], "OFF")
+
+    def test_cir(self):
+        env_variables = compute_projects.get_env_variables(
+            ["clang/lib/CIR/CMakeLists.txt"], "Linux"
+        )
+        self.assertEqual(
+            env_variables["projects_to_build"],
+            "clang;clang-tools-extra;lld;llvm;mlir",
+        )
+        self.assertEqual(
+            env_variables["project_check_targets"],
+            "check-clang check-clang-cir check-clang-tools",
+        )
+        self.assertEqual(
+            env_variables["runtimes_to_build"], "compiler-rt;libcxx;libcxxabi;libunwind"
+        )
+        self.assertEqual(
+            env_variables["runtimes_check_targets"],
+            "check-compiler-rt",
+        )
+        self.assertEqual(
+            env_variables["runtimes_check_targets_needs_reconfig"],
+            "check-cxx check-cxxabi check-unwind",
+        )
+        self.assertEqual(env_variables["enable_cir"], "ON")
 
     def test_bolt(self):
         env_variables = compute_projects.get_env_variables(
@@ -153,11 +183,12 @@ def test_mlir(self):
         )
         self.assertEqual(env_variables["projects_to_build"], "clang;flang;llvm;mlir")
         self.assertEqual(
-            env_variables["project_check_targets"], "check-flang check-mlir"
+            env_variables["project_check_targets"], "check-clang-cir check-flang check-mlir"
         )
         self.assertEqual(env_variables["runtimes_to_build"], "")
         self.assertEqual(env_variables["runtimes_check_targets"], "")
         self.assertEqual(env_variables["runtimes_check_targets_needs_reconfig"], "")
+        self.assertEqual(env_variables["enable_cir"], "ON")
 
     def test_flang(self):
         env_variables = compute_projects.get_env_variables(
@@ -168,6 +199,7 @@ def test_flang(self):
         self.assertEqual(env_variables["runtimes_to_build"], "")
         self.assertEqual(env_variables["runtimes_check_targets"], "")
         self.assertEqual(env_variables["runtimes_check_targets_needs_reconfig"], "")
+        self.assertEqual(env_variables["enable_cir"], "OFF")
 
     def test_invalid_subproject(self):
         env_variables = compute_projects.get_env_variables(
@@ -237,7 +269,7 @@ def test_ci(self):
         )
         self.assertEqual(
             env_variables["project_check_targets"],
-            "check-bolt check-clang check-clang-tools check-flang check-lld check-lldb check-llvm check-mlir check-polly",
+            "check-bolt check-clang check-clang-cir check-clang-tools check-flang check-lld check-lldb check-llvm check-mlir check-polly",
         )
         self.assertEqual(
             env_variables["runtimes_to_build"],

>From a4ed027faf5616a4629b333fe86749d62a602b68 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Tue, 8 Jul 2025 09:50:32 -0700
Subject: [PATCH 5/5] Fix formatting

---
 .ci/compute_projects_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.ci/compute_projects_test.py b/.ci/compute_projects_test.py
index 3f7ed33d340b8..207eb9dc8a99d 100644
--- a/.ci/compute_projects_test.py
+++ b/.ci/compute_projects_test.py
@@ -183,7 +183,8 @@ def test_mlir(self):
         )
         self.assertEqual(env_variables["projects_to_build"], "clang;flang;llvm;mlir")
         self.assertEqual(
-            env_variables["project_check_targets"], "check-clang-cir check-flang check-mlir"
+            env_variables["project_check_targets"],
+            "check-clang-cir check-flang check-mlir"
         )
         self.assertEqual(env_variables["runtimes_to_build"], "")
         self.assertEqual(env_variables["runtimes_check_targets"], "")



More information about the llvm-commits mailing list