[Openmp-commits] [llvm] [openmp] [flang][runtimes] Rebuild Fortran modules when dependency modules change (PR #203549)

Eugene Epshteyn via Openmp-commits openmp-commits at lists.llvm.org
Fri Jun 12 08:17:24 PDT 2026


https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/203549

>From 4bc3506afd2cead5d5e58846a0bb5c930dc4a2da Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Fri, 12 Jun 2026 10:23:58 -0400
Subject: [PATCH 1/3] [flang][runtimes] Rebuild Fortran modules when dependency
 modules change

With the Fortran intrinsic module generation moving to flang-rt, any time
someone changes some key modules, a buildbot or a build starts failing until
someone remembers to do a full rebuild. This change is trying to set
dependencies for some key modules to avoid this problem.
---
 flang-rt/lib/runtime/CMakeLists.txt | 8 ++++++++
 openmp/module/CMakeLists.txt        | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index a956cda31b52d..e0a871c8521ea 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -298,6 +298,14 @@ if (FLANG_RT_FORTRAN_MODULES)
   flang_module_target(flang_rt.mod.intrinsics PUBLIC)
   add_module_barrier(flang_rt.mod.intrinsics.barrier flang_rt.mod.intrinsics)
 
+  set(intrinsic_module_files
+    "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/__fortran_builtins.mod"
+    "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/__cuda_builtins.mod"
+  )
+  set_property(SOURCE ${module_sources}
+    APPEND PROPERTY OBJECT_DEPENDS "${intrinsic_module_files}"
+  )
+
   # The modules themselves
   add_flangrt_library(flang_rt.mod OBJECT
     ${module_sources}
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index c4b9554bdffa4..5cb9c3453f1f5 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -11,6 +11,11 @@
 configure_file(omp_lib.F90.var "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" @ONLY)
 configure_file(omp_lib.h.var "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h" @ONLY)
 
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
+  APPEND PROPERTY OBJECT_DEPENDS
+    "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/iso_c_binding.mod"
+)
+
 # One compilation step creates both, omp_lib.mod and omp_lib_kinds.mod. Only
 # these files are used, the object file itself can be discarded.
 # TODO: Adding it to libomp ($<TARGET_OBJECTS:libomp-mod>) would allow implementing Fortran API in Fortran

>From 73b9df52c0cad4c5db0248565cd6ed7e38ebec96 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Fri, 12 Jun 2026 10:55:29 -0400
Subject: [PATCH 2/3] The original fix only worked for incremental builds that
 already build flang-rt. AI suggested using module stamps for more generic
 fix.

---
 flang-rt/lib/runtime/CMakeLists.txt | 12 ++++++++----
 openmp/module/CMakeLists.txt        | 17 +++++++++++++----
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index e0a871c8521ea..356dfed33eef3 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -298,12 +298,16 @@ if (FLANG_RT_FORTRAN_MODULES)
   flang_module_target(flang_rt.mod.intrinsics PUBLIC)
   add_module_barrier(flang_rt.mod.intrinsics.barrier flang_rt.mod.intrinsics)
 
-  set(intrinsic_module_files
-    "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/__fortran_builtins.mod"
-    "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/__cuda_builtins.mod"
+  set(intrinsic_module_stamp
+    "${CMAKE_CURRENT_BINARY_DIR}/flang_rt.mod.intrinsics.stamp"
+  )
+  add_custom_command(OUTPUT "${intrinsic_module_stamp}"
+    COMMAND "${CMAKE_COMMAND}" -E touch "${intrinsic_module_stamp}"
+    DEPENDS "$<TARGET_OBJECTS:flang_rt.mod.intrinsics>"
+    VERBATIM
   )
   set_property(SOURCE ${module_sources}
-    APPEND PROPERTY OBJECT_DEPENDS "${intrinsic_module_files}"
+    APPEND PROPERTY OBJECT_DEPENDS "${intrinsic_module_stamp}"
   )
 
   # The modules themselves
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 5cb9c3453f1f5..b593c2d044aa3 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -11,10 +11,19 @@
 configure_file(omp_lib.F90.var "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" @ONLY)
 configure_file(omp_lib.h.var "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h" @ONLY)
 
-set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
-  APPEND PROPERTY OBJECT_DEPENDS
-    "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/iso_c_binding.mod"
-)
+if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+  set(flang_rt_module_stamp
+    "${CMAKE_CURRENT_BINARY_DIR}/flang_rt.mod.stamp"
+  )
+  add_custom_command(OUTPUT "${flang_rt_module_stamp}"
+    COMMAND "${CMAKE_COMMAND}" -E touch "${flang_rt_module_stamp}"
+    DEPENDS ${RUNTIMES_FORTRAN_BUILD_DEPS}
+    VERBATIM
+  )
+  set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
+    APPEND PROPERTY OBJECT_DEPENDS "${flang_rt_module_stamp}"
+  )
+endif ()
 
 # One compilation step creates both, omp_lib.mod and omp_lib_kinds.mod. Only
 # these files are used, the object file itself can be discarded.

>From b831576442d573fe0927ed64154882177bf23c96 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Fri, 12 Jun 2026 11:15:53 -0400
Subject: [PATCH 3/3] The new CI error is different from the original stale
 .mod failure. In run 27423676117, check-flang-rt tried to execute the
 runtimes bootstrap placeholder:

  /home/gha/.../build/./bin/flang: Permission denied

Make the top-level per-runtime check targets, including check-flang-rt, depend
on the real just-built flang executable before entering the external runtimes
build.

Also tightened the module dependency fix:

  - llvm-project/llvm/runtimes/CMakeLists.txt: adds check-${runtime_name} targets to the test dependency list so check-flang-rt
    gets the existing flang dependency.

  - llvm-project/flang-rt/lib/runtime/CMakeLists.txt: adds a real flang_rt.mod.stamp produced from flang_rt.mod object files.
  - llvm-project/openmp/module/CMakeLists.txt: makes omp_lib.F90 depend on that stamp.
---
 flang-rt/lib/runtime/CMakeLists.txt | 13 +++++++++++++
 llvm/runtimes/CMakeLists.txt        | 13 ++++++++++++-
 openmp/module/CMakeLists.txt        |  7 +------
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index 356dfed33eef3..8d9c795a616c3 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -318,6 +318,19 @@ if (FLANG_RT_FORTRAN_MODULES)
   flang_module_target(flang_rt.mod PUBLIC)
   add_module_barrier(flang-rt-mod flang_rt.mod)
 
+  set(flang_rt_module_stamp
+    "${CMAKE_CURRENT_BINARY_DIR}/flang_rt.mod.stamp"
+  )
+  add_custom_command(OUTPUT "${flang_rt_module_stamp}"
+    COMMAND "${CMAKE_COMMAND}" -E touch "${flang_rt_module_stamp}"
+    DEPENDS "$<TARGET_OBJECTS:flang_rt.mod>"
+    VERBATIM
+  )
+  add_custom_target(flang-rt-mod-stamp
+    DEPENDS "${flang_rt_module_stamp}"
+  )
+  add_dependencies(flang-rt-mod flang-rt-mod-stamp)
+
   if (RUNTIMES_FORTRAN_MODULES)
     set(_mod_install_dest "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}/..")
     cmake_path(NORMAL_PATH _mod_install_dest)
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index bbc91a709c553..9631d377d216c 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -663,7 +663,12 @@ if(build_runtimes)
       CMAKE_ARGS ${extra_cmake_args}
       PREFIXES ${prefixes}
       EXTRA_ARGS ${extra_args})
-    set(test_targets check-runtimes)
+    if(LLVM_INCLUDE_TESTS)
+      list(APPEND test_targets check-runtimes)
+      foreach(runtime_name ${RUNTIME_NAMES})
+        list(APPEND test_targets check-${runtime_name})
+      endforeach()
+    endif()
   else()
     if("default" IN_LIST LLVM_RUNTIME_TARGETS)
       runtime_default_target(
@@ -671,6 +676,12 @@ if(build_runtimes)
         CMAKE_ARGS ${extra_cmake_args}
         PREFIXES ${prefixes}
         EXTRA_ARGS ${extra_args})
+      if(LLVM_INCLUDE_TESTS)
+        list(APPEND test_targets check-runtimes)
+        foreach(runtime_name ${RUNTIME_NAMES})
+          list(APPEND test_targets check-${runtime_name})
+        endforeach()
+      endif()
       list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
     else()
       add_custom_target(runtimes)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index b593c2d044aa3..7dac82ea712ef 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -13,12 +13,7 @@ configure_file(omp_lib.h.var "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h" @ON
 
 if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
   set(flang_rt_module_stamp
-    "${CMAKE_CURRENT_BINARY_DIR}/flang_rt.mod.stamp"
-  )
-  add_custom_command(OUTPUT "${flang_rt_module_stamp}"
-    COMMAND "${CMAKE_COMMAND}" -E touch "${flang_rt_module_stamp}"
-    DEPENDS ${RUNTIMES_FORTRAN_BUILD_DEPS}
-    VERBATIM
+    "${CMAKE_BINARY_DIR}/flang-rt/lib/runtime/flang_rt.mod.stamp"
   )
   set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
     APPEND PROPERTY OBJECT_DEPENDS "${flang_rt_module_stamp}"



More information about the Openmp-commits mailing list