Skip to content

Commit 9228859

Browse files
authored
[CMake] Add tablegen job pool support (#84762)
Add the ability to set the number of tablegen jobs that can run in parallel similar to the LLVM_PARALLEL_[COMPILE|LINK]_JOBS options that already exist.
1 parent bba4a1d commit 9228859

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
3636
# The following only works with the Ninja generator in CMake >= 3.0.
3737
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
3838
"Define the maximum number of concurrent compilation jobs (Ninja only).")
39-
if(LLVM_RAM_PER_COMPILE_JOB OR LLVM_RAM_PER_LINK_JOB)
39+
if(LLVM_RAM_PER_COMPILE_JOB OR LLVM_RAM_PER_LINK_JOB OR LLVM_RAM_PER_TABLEGEN_JOB)
4040
cmake_host_system_information(RESULT available_physical_memory QUERY AVAILABLE_PHYSICAL_MEMORY)
4141
cmake_host_system_information(RESULT number_of_logical_cores QUERY NUMBER_OF_LOGICAL_CORES)
4242
endif()
@@ -86,6 +86,28 @@ elseif(LLVM_PARALLEL_LINK_JOBS)
8686
message(WARNING "Job pooling is only available with Ninja generators.")
8787
endif()
8888

89+
set(LLVM_PARALLEL_TABLEGEN_JOBS "" CACHE STRING
90+
"Define the maximum number of concurrent tablegen jobs (Ninja only).")
91+
if(LLVM_RAM_PER_TABLEGEN_JOB)
92+
math(EXPR jobs_with_sufficient_memory "${available_physical_memory} / ${LLVM_RAM_PER_TABLEGEN_JOB}" OUTPUT_FORMAT DECIMAL)
93+
if (jobs_with_sufficient_memory LESS 1)
94+
set(jobs_with_sufficient_memory 1)
95+
endif()
96+
if (jobs_with_sufficient_memory LESS number_of_logical_cores)
97+
set(LLVM_PARALLEL_TABLEGEN_JOBS "${jobs_with_sufficient_memory}")
98+
else()
99+
set(LLVM_PARALLEL_TABLEGEN_JOBS "${number_of_logical_cores}")
100+
endif()
101+
endif()
102+
if(LLVM_PARALLEL_TABLEGEN_JOBS)
103+
if(NOT CMAKE_GENERATOR MATCHES "Ninja")
104+
message(WARNING "Job pooling is only available with Ninja generators.")
105+
else()
106+
set_property(GLOBAL APPEND PROPERTY JOB_POOLS tablegen_job_pool=${LLVM_PARALLEL_TABLEGEN_JOBS})
107+
# Job pool for tablegen is set on the add_custom_command
108+
endif()
109+
endif()
110+
89111
if( LLVM_ENABLE_ASSERTIONS )
90112
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
91113
if( NOT MSVC )

llvm/cmake/modules/TableGen.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ function(tablegen project ofn)
125125
set(tablegen_exe ${${project}_TABLEGEN_EXE})
126126
set(tablegen_depends ${${project}_TABLEGEN_TARGET} ${tablegen_exe})
127127

128+
if(LLVM_PARALLEL_TABLEGEN_JOBS)
129+
set(LLVM_TABLEGEN_JOB_POOL JOB_POOL tablegen_job_pool)
130+
else()
131+
set(LLVM_TABLEGEN_JOB_POOL "")
132+
endif()
133+
128134
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
129135
COMMAND ${tablegen_exe} ${ARG_UNPARSED_ARGUMENTS} -I ${CMAKE_CURRENT_SOURCE_DIR}
130136
${tblgen_includes}
@@ -139,6 +145,7 @@ function(tablegen project ofn)
139145
${local_tds} ${global_tds}
140146
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
141147
${LLVM_TARGET_DEPENDS}
148+
${LLVM_TABLEGEN_JOB_POOL}
142149
COMMENT "Building ${ofn}..."
143150
)
144151

llvm/docs/CMake.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,9 @@ enabled sub-projects. Nearly all of these variable names begin with
762762
**LLVM_PARALLEL_LINK_JOBS**:STRING
763763
Define the maximum number of concurrent link jobs.
764764

765+
**LLVM_PARALLEL_TABLEGEN_JOBS**:STRING
766+
Define the maximum number of concurrent tablegen jobs.
767+
765768
**LLVM_RAM_PER_COMPILE_JOB**:STRING
766769
Calculates the amount of Ninja compile jobs according to available resources.
767770
Value has to be in MB, overwrites LLVM_PARALLEL_COMPILE_JOBS. Compile jobs
@@ -775,6 +778,11 @@ enabled sub-projects. Nearly all of these variable names begin with
775778
to be sure its not terminated in your memory restricted environment. On ELF
776779
platforms also consider ``LLVM_USE_SPLIT_DWARF`` in Debug build.
777780

781+
**LLVM_RAM_PER_TABLEGEN_JOB**:STRING
782+
Calculates the amount of Ninja tablegen jobs according to available resources.
783+
Value has to be in MB, overwrites LLVM_PARALLEL_TABLEGEN_JOBS. Tablegen jobs
784+
will be between one and amount of logical cores.
785+
778786
**LLVM_PROFDATA_FILE**:PATH
779787
Path to a profdata file to pass into clang's -fprofile-instr-use flag. This
780788
can only be specified if you're building with clang.

llvm/docs/GettingStarted.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ Getting the Source Code and Building LLVM
9090
is installed on your system. This can dramatically speed up link times
9191
if the default linker is slow.
9292

93-
* ``-DLLVM_PARALLEL_{COMPILE,LINK}_JOBS=N`` --- Limit the number of
94-
compile/link jobs running in parallel at the same time. This is
93+
* ``-DLLVM_PARALLEL_{COMPILE,LINK,TABLEGEN}_JOBS=N`` --- Limit the number of
94+
compile/link/tablegen jobs running in parallel at the same time. This is
9595
especially important for linking since linking can use lots of memory. If
9696
you run into memory issues building LLVM, try setting this to limit the
97-
maximum number of compile/link jobs running at the same time.
97+
maximum number of compile/link/tablegen jobs running at the same time.
9898

9999
* ``cmake --build build [--target <target>]`` or the build system specified
100100
above directly.

0 commit comments

Comments
 (0)