[llvm] Use thinlto and pgo for x86_64 windows release packaging (PR #71067)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 2 08:09:38 PDT 2023


https://github.com/zmodem created https://github.com/llvm/llvm-project/pull/71067

Applying this to 17.0.4 makes the installer 5% smaller (298 MB vs. 315 MB) and the toolchain 20% faster (as measured by building clang).

>From 9ae604d3341c13119a7230ac07db68f806f402d8 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Tue, 31 Oct 2023 18:36:29 +0100
Subject: [PATCH] Use thinlto and pgo for x86_64 windows release packaging

---
 llvm/utils/release/build_llvm_release.bat | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 3b4f431cee65646..896d890b0703d60 100755
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -261,6 +261,23 @@ set all_cmake_flags=^
   -DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe
 set cmake_flags=%all_cmake_flags:\=/%
 
+
+REM Build Clang with instrumentation.
+mkdir build64.instr
+cd build64.instr
+cmake -GNinja %cmake_flags% -DLLVM_BUILD_INSTRUMENTED=IR ..\llvm-project\llvm || exit /b 1
+ninja clang || ninja clang || ninja clang || exit /b 1
+cd ..
+REM Run instrumented Clang to generate a profile.
+curl -L https://commondatastorage.googleapis.com/chromium-browser-clang/pgo_training-1.ii -o train.ii || exit /b 1
+set profile=%build_dir:\=/%/build64.instr/profile.profdata
+build64.instr\bin\clang++ -target x86_64-unknown-unknown -O2 -g -std=c++14 -fno-exceptions -fno-rtti -w -c train.ii
+%stage0_bin_dir%\llvm-profdata merge -output=%profile% build64.instr\profiles\*.profraw || exit /b 1
+set cmake_flags=%cmake_flags% -DLLVM_PROFDATA_FILE=%profile%
+
+REM Enable ThinLTO
+set cmake_flags=%cmake_flags% -DLLVM_ENABLE_LTO=Thin
+
 mkdir build64
 cd build64
 cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1



More information about the llvm-commits mailing list