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

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 09:40:14 PST 2023


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

>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 1/4] 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

>From dd1d7cc8f88c61d63b30099aced1443c9934fa58 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Fri, 3 Nov 2023 10:57:08 +0100
Subject: [PATCH 2/4] Train by building Sema.cpp instead.

---
 llvm/utils/release/build_llvm_release.bat | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 896d890b0703d60..6288eba1ab78107 100755
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -268,10 +268,21 @@ 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
+REM Use that to buid some part of llvm to generate a profile.
+mkdir build64.train
+cd build64.train
+set instrumented_clang=%build_dir:\=/%/build64.instr/bin/clang-cl.exe
+cmake -GNinja %cmake_flags% ^
+  -DCMAKE_C_COMPILER=%instrumented_clang% ^
+  -DCMAKE_CXX_COMPILER=%instrumented_clang% ^
+  -DLLVM_ENABLE_PROJECTS=clang ^
+  -DLLVM_TARGETS_TO_BUILD=X86 ^
+  ..\llvm-project\llvm || exit /b 1
+REM Drop profiles from running cmake, those are not representative.
+del ..\build64.instr\profiles\*.profraw
+ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/Sema.cpp.obj
+cd ..
+set profile=%build_dir:\=/%/profile.profdata
 %stage0_bin_dir%\llvm-profdata merge -output=%profile% build64.instr\profiles\*.profraw || exit /b 1
 set cmake_flags=%cmake_flags% -DLLVM_PROFDATA_FILE=%profile%
 

>From b84b93305c89a88cb25747a538bdf67cbea3e7d7 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Tue, 7 Nov 2023 13:43:15 +0100
Subject: [PATCH 3/4] Drop ThinLTO

---
 llvm/utils/release/build_llvm_release.bat | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 6288eba1ab78107..7da1fad2cb4e1fe 100755
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -286,9 +286,6 @@ set profile=%build_dir:\=/%/profile.profdata
 %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

>From 090bfda65c3f27f7ffc29f49686ab252388edf95 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Tue, 14 Nov 2023 12:42:32 +0100
Subject: [PATCH 4/4] Extract do_generate_profile

---
 llvm/utils/release/build_llvm_release.bat | 59 +++++++++++++----------
 1 file changed, 34 insertions(+), 25 deletions(-)

diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 7da1fad2cb4e1fe..2a1503eef8ae5c9 100755
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -154,6 +154,8 @@ set common_cmake_flags=^
   -DCMAKE_CXX_FLAGS="-DLIBXML_STATIC" ^
   -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;lldb;openmp"
 
+set cmake_profile_flag=""
+
 REM Preserve original path
 set OLDPATH=%PATH%
 
@@ -262,33 +264,10 @@ set all_cmake_flags=^
 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 Use that to buid some part of llvm to generate a profile.
-mkdir build64.train
-cd build64.train
-set instrumented_clang=%build_dir:\=/%/build64.instr/bin/clang-cl.exe
-cmake -GNinja %cmake_flags% ^
-  -DCMAKE_C_COMPILER=%instrumented_clang% ^
-  -DCMAKE_CXX_COMPILER=%instrumented_clang% ^
-  -DLLVM_ENABLE_PROJECTS=clang ^
-  -DLLVM_TARGETS_TO_BUILD=X86 ^
-  ..\llvm-project\llvm || exit /b 1
-REM Drop profiles from running cmake, those are not representative.
-del ..\build64.instr\profiles\*.profraw
-ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/Sema.cpp.obj
-cd ..
-set profile=%build_dir:\=/%/profile.profdata
-%stage0_bin_dir%\llvm-profdata merge -output=%profile% build64.instr\profiles\*.profraw || exit /b 1
-set cmake_flags=%cmake_flags% -DLLVM_PROFDATA_FILE=%profile%
-
 mkdir build64
 cd build64
-cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1
+call :do_generate_profile || exit /b 1
+cmake -GNinja %cmake_flags% %cmake_profile_flag% ..\llvm-project\llvm || exit /b 1
 ninja || ninja || ninja || exit /b 1
 ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
 ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
@@ -413,8 +392,38 @@ ninja install || exit /b 1
 set libxmldir=%cd%\install
 set "libxmldir=%libxmldir:\=/%"
 cd ..
+exit /b 0
 
+::==============================================================================
+:: Generate a PGO profile.
+::==============================================================================
+:do_generate_profile
+REM Build Clang with instrumentation.
+mkdir instrument
+cd instrument
+cmake -GNinja %cmake_flags% -DLLVM_TARGETS_TO_BUILD=Native ^
+  -DLLVM_BUILD_INSTRUMENTED=IR ..\..\llvm-project\llvm || exit /b 1
+ninja clang || ninja clang || 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-project\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
+cd ..
+set profile=%cd:\=/%/profile.profdata
+%stage0_bin_dir%\llvm-profdata merge -output=%profile% instrument\profiles\*.profraw || exit /b 1
+set cmake_profile_flag=-DLLVM_PROFDATA_FILE=%profile%
 exit /b 0
+
 ::=============================================================================
 :: Parse command line arguments.
 :: The format for the arguments is:



More information about the llvm-commits mailing list