[flang-commits] [flang] [flang] Add FLANG_PARALLEL_COMPILE_JOBS option (PR #127364)

Tom Stellard via flang-commits flang-commits at lists.llvm.org
Mon Feb 17 11:37:38 PST 2025


https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/127364

>From e8ffc92f5178ca752aefd00058c5bee6be14e8ee Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Sat, 15 Jun 2024 17:36:33 +0000
Subject: [PATCH 1/2] [flang] Add FLANG_PARALLEL_COMPILE_JOBS option

This is a re-apply of 083c683969b2436afdc45becadc955841f5f4d31 with a
fix for the flang runtime build.

This works the same way as LLVM_PARALLEL_COMPILE_JOBS except that it
is specific to the flang source rather than for the whole project.

Configuring with -DFLANG_PARALLEL_COMPILE_JOBS=1 would mean that there
would only ever be one flang source being compiled at a time.

Some of the flang sources require large amounts of memory to compile,
so this option can be used to avoid OOM erros when compiling those
files while still allowing the rest of the project to compile using
the maximum number of jobs.

Update flang/CMakeLists.txt

Co-authored-by: Nikita Popov <github at npopov.com>
---
 flang/CMakeLists.txt               | 12 ++++++++++++
 flang/cmake/modules/AddFlang.cmake |  1 +
 flang/runtime/CMakeLists.txt       |  5 +++++
 3 files changed, 18 insertions(+)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 0f98d12343c43..421a997bf048e 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -473,6 +473,18 @@ if (APPLE)
   endif()
 endif()
 
+# Set up job pools for flang.  Some of the flang sources take a lot of memory to
+# compile, so allow users to limit the number of parallel flang jobs.  This is
+# useful for building flang alongside several other projects since you can use
+# the maximum number of build jobs for the other projects while limiting the
+# number of flang compile jobs.
+#
+# We want this set to infinity by default
+set(FLANG_PARALLEL_COMPILE_JOBS 0 CACHE STRING
+  "The maximum number of concurrent compilation jobs (Ninja only)")
+
+set_property(GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool=${FLANG_PARALLEL_COMPILE_JOBS})
+
 include(AddFlang)
 
 if (FLANG_INCLUDE_TESTS)
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index badbd4e7b964b..b9fa6bb8c249f 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -94,6 +94,7 @@ function(add_flang_library name)
       set_property(GLOBAL APPEND PROPERTY FLANG_LIBS ${name})
     endif()
     set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
+    set_property(TARGET ${name} PROPERTY JOB_POOL_COMPILE flang_compile_job_pool)
   else()
     # Add empty "phony" target
     add_custom_target(${name})
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 1f4ee69598918..09846ad5bcd44 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -57,6 +57,11 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     REAL(16) is mapped to __float128, or libm for targets where REAL(16) \
     is mapped to long double, etc."
     )
+
+   # For the stand alone runtime builds, we need to define this job pool,
+   # because add_flang_library will use it.  If we don't define it here, the
+   # build will fail.
+   set_property(GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool=0)
 endif()
 
 set(linked_libraries "")

>From 6ae69e5bea0295856603d94ec424acce11785c7d Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 17 Feb 2025 19:32:37 +0000
Subject: [PATCH 2/2] Only define job pools when FLANG_PARALLEL_COMPILE_JOB is
 defined

---
 flang/CMakeLists.txt               | 11 +++++------
 flang/cmake/modules/AddFlang.cmake |  4 +++-
 flang/runtime/CMakeLists.txt       |  4 ----
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 421a997bf048e..92f54529312ed 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -478,12 +478,11 @@ endif()
 # useful for building flang alongside several other projects since you can use
 # the maximum number of build jobs for the other projects while limiting the
 # number of flang compile jobs.
-#
-# We want this set to infinity by default
-set(FLANG_PARALLEL_COMPILE_JOBS 0 CACHE STRING
-  "The maximum number of concurrent compilation jobs (Ninja only)")
-
-set_property(GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool=${FLANG_PARALLEL_COMPILE_JOBS})
+set(FLANG_PARALLEL_COMPILE_JOBS CACHE STRING
+  "The maximum number of concurrent compilation jobs for Flang(Ninja only)")
+if (FLANG_PARALLEL_COMPILE_JOBS)
+  set_property(GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool=${FLANG_PARALLEL_COMPILE_JOBS})
+endif()
 
 include(AddFlang)
 
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index b9fa6bb8c249f..ca233103ccdbe 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -94,7 +94,9 @@ function(add_flang_library name)
       set_property(GLOBAL APPEND PROPERTY FLANG_LIBS ${name})
     endif()
     set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
-    set_property(TARGET ${name} PROPERTY JOB_POOL_COMPILE flang_compile_job_pool)
+    if (FLANG_PARALLEL_COMPILE_JOBS)
+      set_property(TARGET ${name} PROPERTY JOB_POOL_COMPILE flang_compile_job_pool)
+    endif()
   else()
     # Add empty "phony" target
     add_custom_target(${name})
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 09846ad5bcd44..4e9ad2906077c 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -58,10 +58,6 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     is mapped to long double, etc."
     )
 
-   # For the stand alone runtime builds, we need to define this job pool,
-   # because add_flang_library will use it.  If we don't define it here, the
-   # build will fail.
-   set_property(GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool=0)
 endif()
 
 set(linked_libraries "")



More information about the flang-commits mailing list