[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 07:56:13 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/2] [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/2] 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.
More information about the Openmp-commits
mailing list