Skip to content

Commit 060af26

Browse files
authored
Use PGO for x86_64 windows release packaging (#71067)
Applying this to 17.0.4 makes the toolchain 22% faster (as measured by building clang).
1 parent 5f32bcf commit 060af26

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

llvm/utils/release/build_llvm_release.bat

+35-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ set common_cmake_flags=^
154154
-DCMAKE_CXX_FLAGS="-DLIBXML_STATIC" ^
155155
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;lldb;openmp"
156156

157+
set cmake_profile_flag=""
158+
157159
REM Preserve original path
158160
set OLDPATH=%PATH%
159161

@@ -261,9 +263,11 @@ set all_cmake_flags=^
261263
-DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe
262264
set cmake_flags=%all_cmake_flags:\=/%
263265

266+
264267
mkdir build64
265268
cd build64
266-
cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1
269+
call :do_generate_profile || exit /b 1
270+
cmake -GNinja %cmake_flags% %cmake_profile_flag% ..\llvm-project\llvm || exit /b 1
267271
ninja || ninja || ninja || exit /b 1
268272
ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
269273
ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
@@ -388,8 +392,38 @@ ninja install || exit /b 1
388392
set libxmldir=%cd%\install
389393
set "libxmldir=%libxmldir:\=/%"
390394
cd ..
395+
exit /b 0
391396

397+
::==============================================================================
398+
:: Generate a PGO profile.
399+
::==============================================================================
400+
:do_generate_profile
401+
REM Build Clang with instrumentation.
402+
mkdir instrument
403+
cd instrument
404+
cmake -GNinja %cmake_flags% -DLLVM_TARGETS_TO_BUILD=Native ^
405+
-DLLVM_BUILD_INSTRUMENTED=IR ..\..\llvm-project\llvm || exit /b 1
406+
ninja clang || ninja clang || ninja clang || exit /b 1
407+
set instrumented_clang=%cd:\=/%/bin/clang-cl.exe
408+
cd ..
409+
REM Use that to build part of llvm to generate a profile.
410+
mkdir train
411+
cd train
412+
cmake -GNinja %cmake_flags% ^
413+
-DCMAKE_C_COMPILER=%instrumented_clang% ^
414+
-DCMAKE_CXX_COMPILER=%instrumented_clang% ^
415+
-DLLVM_ENABLE_PROJECTS=clang ^
416+
-DLLVM_TARGETS_TO_BUILD=Native ^
417+
..\..\llvm-project\llvm || exit /b 1
418+
REM Drop profiles generated from running cmake; those are not representative.
419+
del ..\instrument\profiles\*.profraw
420+
ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/Sema.cpp.obj
421+
cd ..
422+
set profile=%cd:\=/%/profile.profdata
423+
%stage0_bin_dir%\llvm-profdata merge -output=%profile% instrument\profiles\*.profraw || exit /b 1
424+
set cmake_profile_flag=-DLLVM_PROFDATA_FILE=%profile%
392425
exit /b 0
426+
393427
::=============================================================================
394428
:: Parse command line arguments.
395429
:: The format for the arguments is:

0 commit comments

Comments
 (0)