[llvm] [Windows] 12% faster compile by improved PGO training and re-enable ThinLTO (PR #219263)
Marcus Perryman via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 1 08:20:13 PDT 2026
https://github.com/marcpems updated https://github.com/llvm/llvm-project/pull/219263
>From efc04fb0e7eade5d0d0d7e01e4c70bdc04511714 Mon Sep 17 00:00:00 2001
From: marcpems <marcpems at users.noreply.github.com>
Date: Fri, 28 Aug 2026 11:05:26 +0100
Subject: [PATCH 1/2] [Windows] Add optional ThinLTO, PDB debug info, and
enhanced PGO training to release-binaries.yml
Adds minimal, additive inputs to the existing release-binaries.yml
workflow (rather than a separate duplicate workflow file):
- enable-thinlto: build stage2 with ThinLTO (default off, matches
current behavior).
- enable-pdb: also generate and upload PDB debug info as a separate
artifact (default off).
- enhanced-pgo: PGO training always runs (matching the pre-existing,
unconditional upstream behavior); this flag only selects the
training method. Default false uses the legacy single-file
Sema.cpp training step (byte-for-byte the same as current upstream
behavior). Setting it to true trains by building LLVMSupport
instead, exercising the compiler across many more translation
units for a broader, more representative profile.
Default behavior (enable-thinlto=false, enable-pdb=false,
enhanced-pgo=false) is unchanged from current upstream.
Co-authored-by: Copilot <223556219+Copilot at users.noreply.github.com>
---
.github/workflows/release-binaries.yml | 95 +++++++++++++++++++++--
llvm/utils/release/build_llvm_release.bat | 83 ++++++++++++++++----
2 files changed, 158 insertions(+), 20 deletions(-)
diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index e95a6c5936137..0ff52df0809be 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -12,6 +12,21 @@ on:
required: true
default: false
type: boolean
+ enable-thinlto:
+ description: "Windows only: build stage2 with ThinLTO"
+ required: false
+ default: false
+ type: boolean
+ enable-pdb:
+ description: "Windows only: also generate and upload PDB debug info"
+ required: false
+ default: false
+ type: boolean
+ enhanced-pgo:
+ description: "Windows only: train the instrumented clang by building LLVMSupport instead of the legacy single-file Sema.cpp training step (PGO training always runs; this only selects the method)"
+ required: false
+ default: false
+ type: boolean
runs-on:
description: "Runner to use for the build"
required: true
@@ -36,6 +51,21 @@ on:
required: true
default: false
type: boolean
+ enable-thinlto:
+ description: "Windows only: build stage2 with ThinLTO"
+ required: false
+ default: false
+ type: boolean
+ enable-pdb:
+ description: "Windows only: also generate and upload PDB debug info"
+ required: false
+ default: false
+ type: boolean
+ enhanced-pgo:
+ description: "Windows only: train the instrumented clang by building LLVMSupport instead of the legacy single-file Sema.cpp training step (PGO training always runs; this only selects the method)"
+ required: false
+ default: false
+ type: boolean
runs-on:
description: "Runner to use for the build"
required: true
@@ -69,6 +99,9 @@ jobs:
build-runs-on: ${{ steps.vars.outputs.build-runs-on }}
test-runs-on: ${{ steps.vars.outputs.build-runs-on }}
attestation-name: ${{ steps.vars.outputs.attestation-name }}
+ windows-enable-thinlto: ${{ steps.vars.outputs.windows-enable-thinlto }}
+ windows-enable-pdb: ${{ steps.vars.outputs.windows-enable-pdb }}
+ windows-enhanced-pgo: ${{ steps.vars.outputs.windows-enhanced-pgo }}
steps:
- name: Validate Release Version
@@ -90,6 +123,9 @@ jobs:
LLVM_VERSION_MAJOR: ${{ steps.version-from-source.outputs.major }}
INPUTS_RUNS_ON: ${{ inputs.runs-on }}
INPUTS_RELEASE_VERSION: ${{ inputs.release-version }}
+ INPUTS_ENABLE_THINLTO: ${{ inputs.enable-thinlto }}
+ INPUTS_ENABLE_PDB: ${{ inputs.enable-pdb }}
+ INPUTS_ENHANCED_PGO: ${{ inputs.enhanced-pgo }}
shell: bash
# In order for the test-release.sh script to run correctly, the LLVM
# source needs to be at the following location relative to the build dir:
@@ -160,8 +196,10 @@ jobs:
fi
if [ "$RUNNER_OS" = "Windows" ]; then
- # The build times out on Windows, so we need to disable LTO.
- target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_LTO=OFF"
+ # Disable LTO by default; use --enable-thinlto to enable ThinLTO.
+ if [ "$INPUTS_ENABLE_THINLTO" != "true" ]; then
+ target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_LTO=OFF"
+ fi
fi
case "$INPUTS_RUNS_ON" in
@@ -206,10 +244,29 @@ jobs:
target_cmake_flags="$target_cmake_flags -D${bootstrap_prefix}_CPACK_PACKAGE_FILE_NAME=$release_binary_basename"
+ # Translate --enable-thinlto/--enable-pdb/--enhanced-pgo into individual
+ # flags consumed by the Windows build_llvm_release.bat invocation below
+ # (only meaningful for Windows builds).
+ windows_enable_thinlto="false"
+ if [ "$INPUTS_ENABLE_THINLTO" = "true" ]; then
+ windows_enable_thinlto="true"
+ fi
+ windows_enable_pdb="false"
+ if [ "$INPUTS_ENABLE_PDB" = "true" ]; then
+ windows_enable_pdb="true"
+ fi
+ windows_enhanced_pgo="false"
+ if [ "$INPUTS_ENHANCED_PGO" = "true" ]; then
+ windows_enhanced_pgo="true"
+ fi
+
echo "target-cmake-flags=$target_cmake_flags" >> $GITHUB_OUTPUT
echo "build-runs-on=$build_runs_on" >> $GITHUB_OUTPUT
echo "test-runs-on=$test_runs_on" >> $GITHUB_OUTPUT
echo "attestation-name=$RUNNER_OS-$RUNNER_ARCH-release-binary-attestation" >> $GITHUB_OUTPUT
+ echo "windows-enable-thinlto=$windows_enable_thinlto" >> $GITHUB_OUTPUT
+ echo "windows-enable-pdb=$windows_enable_pdb" >> $GITHUB_OUTPUT
+ echo "windows-enhanced-pgo=$windows_enhanced_pgo" >> $GITHUB_OUTPUT
build-release-package:
name: "Build Release Package"
@@ -297,21 +354,42 @@ jobs:
env:
INPUTS_RUNS_ON: ${{ inputs.runs-on }}
LLVM_VERSION: ${{ needs.prepare.outputs.release-version }}
- EXTRA_ARGS: ${{ case(needs.prepare.outputs.build-runs-on == 'windows-11-arm', '--fast-build', '--fast-build') }}
+ BUILD_RUNS_ON: ${{ needs.prepare.outputs.build-runs-on }}
+ WINDOWS_ENABLE_THINLTO: ${{ needs.prepare.outputs.windows-enable-thinlto }}
+ WINDOWS_ENABLE_PDB: ${{ needs.prepare.outputs.windows-enable-pdb }}
+ WINDOWS_ENHANCED_PGO: ${{ needs.prepare.outputs.windows-enhanced-pgo }}
run: |
subst S: ${{ github.workspace }}
cd S:\llvm\utils\release\
- .\build_llvm_release.bat "--$($env:RUNNER_ARCH.ToLower())" --version $env:LLVM_VERSION --local-python --skip-checkout $env:EXTRA_ARGS
+ $variantArgs = @()
+ # --fast-build trades PGO training and stage0 test coverage for
+ # build speed; it exists solely so the GitHub-hosted windows-11-arm
+ # runner can finish within its 6-hour job timeout. Other runners
+ # (including our self-hosted ones) don't need that trade-off, and
+ # --enhanced-pgo/--enable-thinlto/--enable-pdb below are explicit,
+ # deliberate opt-ins that should not be silently defeated by it.
+ if ($env:BUILD_RUNS_ON -eq "windows-11-arm") { $variantArgs += "--fast-build" }
+ if ($env:WINDOWS_ENABLE_THINLTO -eq "true") { $variantArgs += "--enable-thinlto" }
+ if ($env:WINDOWS_ENABLE_PDB -eq "true") { $variantArgs += "--enable-pdb" }
+ if ($env:WINDOWS_ENHANCED_PGO -eq "true") { $variantArgs += "--enhanced-pgo" }
+ .\build_llvm_release.bat "--$($env:RUNNER_ARCH.ToLower())" --version $env:LLVM_VERSION --local-python --skip-checkout @variantArgs
if ($env:INPUTS_RUNS_ON -eq "windows-11-arm") {
$zstd = (Get-ChildItem -Recurse -Filter "zstd.exe" | Select-Object -First 1).fullName
mv $zstd $env:GITHUB_WORKSPACE
}
$installer = (Get-ChildItem -Recurse -Filter "LLVM-*.msi" | Select-Object -First 1).fullName
- $tarball = (Get-ChildItem -Recurse -Filter "*.tar.xz" | Select-Object -First 1).fullName
+ $tarball = (Get-ChildItem -Recurse -Filter "*.tar.xz" | Where-Object { $_.Name -notlike "*-pdb.tar.xz" } | Select-Object -First 1).fullName
# Move installer to top-level directory so it is easier to upload.
mv $installer $env:GITHUB_WORKSPACE
mv $tarball $env:GITHUB_WORKSPACE
echo "windows-installer-filename=$(Split-Path -Path $installer -Leaf)" >> $env:GITHUB_OUTPUT
+ if ($env:WINDOWS_ENABLE_PDB -eq "true") {
+ $pdbArchive = (Get-ChildItem -Recurse -Filter "*-pdb.tar.xz" | Select-Object -First 1).fullName
+ if ($pdbArchive) {
+ mv $pdbArchive $env:GITHUB_WORKSPACE
+ echo "windows-pdb-filename=$(Split-Path -Path $pdbArchive -Leaf)" >> $env:GITHUB_OUTPUT
+ }
+ }
- name: Dump Wix logs
if: runner.os == 'Windows' && failure()
@@ -364,6 +442,13 @@ jobs:
${{ needs.prepare.outputs.release-binary-filename-zstd }}
${{ steps.build-windows.outputs.windows-installer-filename }}
+ - name: Upload Windows PDB debug info
+ if: runner.os == 'Windows' && steps.build-windows.outputs.windows-pdb-filename != ''
+ uses: actions/upload-artifact at 043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: ${{ runner.os }}-${{ runner.arch }}-release-pdb
+ path: ${{ steps.build-windows.outputs.windows-pdb-filename }}
+
- name: Run Tests
# These almost always fail so don't let them fail the build and prevent the uploads.
if : runner.os != 'Windows'
diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 66c4a0380667a..5d30f3f5cb0f0 100644
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -10,7 +10,7 @@ goto begin
echo Script for building the LLVM installer on Windows,
echo used for the releases at https://github.com/llvm/llvm-project/releases
echo.
-echo Usage: build_llvm_release.bat --version ^<version^> [--x86,--x64, --arm64] [--skip-checkout] [--local-python] [--force-msvc] [--fast-build]
+echo Usage: build_llvm_release.bat --version ^<version^> [--x86,--x64, --arm64] [--skip-checkout] [--local-python] [--force-msvc] [--fast-build] [--enhanced-pgo] [--enable-thinlto] [--enable-pdb]
echo.
echo Options:
echo --version: [required] version to build
@@ -21,6 +21,11 @@ echo --arm64: build and test arm64 variant
echo --skip-checkout: use local git checkout instead of downloading src.zip
echo --local-python: use installed Python and does not try to use a specific version (3.11)
echo --force-msvc: use MSVC compiler for stage0, even if clang-cl is present
+echo --enhanced-pgo: train the instrumented stage1 clang by building LLVMSupport instead of
+echo the legacy single-file Sema.cpp training step, and use the resulting profile for
+echo stage2 (64-bit builds only).
+echo --enable-thinlto: build stage2 with ThinLTO (64-bit builds only)
+echo --enable-pdb: generate PDB debug info files for stage2 and include them as an additional artifact (64-bit builds only)
echo.
echo Note: At least one variant to build is required.
echo.
@@ -40,7 +45,10 @@ set arm64=
set skip-checkout=
set local-python=
set force-msvc=
-set fast-build=
+set fast-build=
+set enhanced-pgo=
+set enable-thinlto=
+set enable-pdb=
call :parse_args %*
if "%help%" NEQ "" goto usage
@@ -355,12 +363,21 @@ set cmake_flags=%all_cmake_flags:\=/%
mkdir build_%arch%
cd build_%arch%
-if "%fast-build%" neq "true" (
+REM --fast-build skips PGO training for CI speed on time-constrained
+REM runners (see build_llvm_release.bat's usage doc), but --enhanced-pgo
+REM is an explicit, deliberate opt-in and should not be silently defeated
+REM by it; only skip training when enhanced-pgo was not also requested.
+if "%fast-build%" == "true" if "%enhanced-pgo%" neq "true" (
+ echo Skipping PGO training due to --fast-build.
+) else (
call :do_generate_profile || exit /b 1
-)
+)
+set lto_cmake_flag=
+if "%enable-thinlto%" == "true" set lto_cmake_flag=-DLLVM_ENABLE_LTO=Thin
cmake -GNinja %cmake_flags% ^
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;flang;mlir" ^
-DLLVM_ENABLE_RUNTIMES="compiler-rt;openmp" ^
+ %lto_cmake_flag% ^
%common_lldb_flags% ^
-DPYTHON_HOME=%PYTHONHOME% ^
%cmake_profile_flags% %llvm_src%\llvm || exit /b 1
@@ -384,14 +401,31 @@ if "%arch%"=="amd64" (
) else (
set filename=clang+llvm-%version%-aarch64-pc-windows-msvc
)
+REM NOTE: LLVM_ENABLE_PDB is intentionally only set for this toolchain-only
+REM (tarball) reconfigure, not for the MSI/WiX "ninja package" build above:
+REM bundling PDBs into the WiX-generated MSI causes CPack/WiX packaging
+REM failures, so PDBs are packaged separately as their own tarball instead.
+set pdb_cmake_flag=
+if "%enable-pdb%" == "true" set pdb_cmake_flag=-DLLVM_ENABLE_PDB=ON
cmake -GNinja %cmake_flags% %cmake_profile_flags% -DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF ^
- -DCMAKE_INSTALL_PREFIX=%build_dir%/%filename% %llvm_src%\llvm || exit /b 1
+ -DCMAKE_INSTALL_PREFIX=%build_dir%/%filename% ^
+ %pdb_cmake_flag% ^
+ %llvm_src%\llvm || exit /b 1
ninja install || exit /b 1
:: check llvm_config is present & returns something
%build_dir%/%filename%/bin/llvm-config.exe --bindir || exit /b 1
cd ..
7z a -ttar -so %filename%.tar %filename% | 7z a -txz -si %filename%.tar.xz
+if "%enable-pdb%" == "true" (
+ :: Package the PDB debug info files produced alongside the install tree
+ :: into their own archive so they can be uploaded as a separate artifact.
+ set pdb_filename=%filename%-pdb
+ pushd %filename%
+ 7z a -ttar -so ..\!pdb_filename!.tar bin\*.pdb lib\*.pdb | 7z a -txz -si ..\!pdb_filename!.tar.xz
+ popd
+)
+
exit /b 0
::==============================================================================
@@ -503,18 +537,37 @@ cmake -GNinja %cmake_flags% -DLLVM_TARGETS_TO_BUILD=Native ^
ninja clang || exit /b 1
set instrumented_clang=%cd:\=/%/bin/clang-cl.exe
cd ..
-REM Use that to build part of llvm to generate a profile.
mkdir train
cd train
-cmake -GNinja %cmake_flags% ^
- -DCMAKE_C_COMPILER=%instrumented_clang% ^
- -DCMAKE_CXX_COMPILER=%instrumented_clang% ^
- -DLLVM_ENABLE_PROJECTS=clang ^
- -DLLVM_TARGETS_TO_BUILD=Native ^
- %llvm_src%\llvm || exit /b 1
-REM Drop profiles generated from running cmake; those are not representative.
-del ..\instrument\profiles\*.profraw
-ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/Sema.cpp.obj
+if "%enhanced-pgo%" == "true" (
+ REM Build LLVMSupport with the instrumented clang to generate a broad profile.
+ REM This mirrors the Linux perf-training approach (llvm-support/build.test)
+ REM and exercises the compiler across many translation units and code paths,
+ REM rather than compiling a single file (Sema.cpp).
+ cmake -GNinja ^
+ -DCMAKE_BUILD_TYPE=Release ^
+ -DCMAKE_C_COMPILER=%instrumented_clang% ^
+ -DCMAKE_CXX_COMPILER=%instrumented_clang% ^
+ -DLLVM_TARGETS_TO_BUILD=Native ^
+ -DLLVM_ENABLE_PROJECTS="" ^
+ -DLLVM_ENABLE_RUNTIMES="" ^
+ %llvm_src%\llvm || exit /b 1
+ REM Drop profiles generated from running cmake; those are not representative.
+ del ..\instrument\profiles\*.profraw
+ ninja LLVMSupport || exit /b 1
+) else (
+ REM Use instrumented build of clang to compile a complex single file to
+ REM deliver minimum build times.
+ cmake -GNinja %cmake_flags% ^
+ -DCMAKE_C_COMPILER=%instrumented_clang% ^
+ -DCMAKE_CXX_COMPILER=%instrumented_clang% ^
+ -DLLVM_ENABLE_PROJECTS=clang ^
+ -DLLVM_TARGETS_TO_BUILD=Native ^
+ %llvm_src%\llvm || exit /b 1
+ REM Drop profiles generated from running cmake; those are not representative.
+ del ..\instrument\profiles\*.profraw
+ ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/Sema.cpp.obj || exit /b 1
+)
cd ..
set profile=%cd:\=/%/profile.profdata
%stage0_bin_dir%\llvm-profdata merge -output=%profile% instrument\profiles\*.profraw || exit /b 1
>From 0eb66a583a989060871454a3b4c8d4dff51a254a Mon Sep 17 00:00:00 2001
From: marcpems <marcpe at microsoft.com>
Date: Tue, 1 Sep 2026 07:27:54 +0100
Subject: [PATCH 2/2] Fix double-packaging of PDB files in Windows release main
tarball
Previously, when --enable-pdb was set, the main release tarball
included the full install tree (with all bin\*.pdb and lib\*.pdb
files) *and* a separate dedicated -pdb.tar.xz archive packaged those
same PDBs again, roughly doubling the compressed payload and
needlessly inflating the main artifact.
Fix: package the dedicated PDB archive first (as before), then delete
bin\*.pdb and lib\*.pdb from the install tree, then run the main
archive command. The main archive command itself is left completely
unmodified from upstream (byte-for-byte identical to the pre-existing
single 7z line) since the PDBs are simply no longer present in the
tree by the time it runs; only the ordering changed and one "del"
line was added inside the existing PDB-packaging block.
This is deliberately simpler than an earlier version of this fix that
added a "-xr!pattern" 7-Zip exclusion to the main archive command:
that syntax requires a literal "!", which is fragile under this
script's `setlocal enabledelayedexpansion` and needs extra
setlocal/endlocal scoping and careful comment placement to avoid
cmd.exe parser pitfalls. Deleting the files before archiving avoids
that whole class of issues and keeps the main archive command
identical to upstream's non-PDB behavior.
Verified locally in real cmd.exe with a synthetic install tree
(including a decoy nested\bin\keep.pdb outside the top-level bin/lib
directories, to confirm the deletion is scoped the same way the prior
"-xr!" recursive exclusion was): the PDB archive contains exactly
bin\*.pdb and lib\*.pdb, the main archive contains everything else
(including the decoy nested PDB, correctly left untouched), and the
non-PDB (enable-pdb=false) path is completely unchanged.
Co-authored-by: Copilot <223556219+Copilot at users.noreply.github.com>
---
llvm/utils/release/build_llvm_release.bat | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 5d30f3f5cb0f0..068243977ce4a 100644
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -415,16 +415,18 @@ ninja install || exit /b 1
:: check llvm_config is present & returns something
%build_dir%/%filename%/bin/llvm-config.exe --bindir || exit /b 1
cd ..
-7z a -ttar -so %filename%.tar %filename% | 7z a -txz -si %filename%.tar.xz
-
if "%enable-pdb%" == "true" (
:: Package the PDB debug info files produced alongside the install tree
- :: into their own archive so they can be uploaded as a separate artifact.
+ :: into their own archive so they can be uploaded as a separate artifact,
+ :: then delete them from the install tree so the main archive command
+ :: below does not compress them a second time.
set pdb_filename=%filename%-pdb
pushd %filename%
7z a -ttar -so ..\!pdb_filename!.tar bin\*.pdb lib\*.pdb | 7z a -txz -si ..\!pdb_filename!.tar.xz
+ del /s /q bin\*.pdb lib\*.pdb
popd
)
+7z a -ttar -so %filename%.tar %filename% | 7z a -txz -si %filename%.tar.xz
exit /b 0
More information about the llvm-commits
mailing list