Skip to content

Commit

Permalink
Use PGO for x86_64 windows release packaging (llvm#71067)
Browse files Browse the repository at this point in the history
Applying this to 17.0.4 makes the toolchain 22% faster (as measured by building clang).
  • Loading branch information
zmodem authored and zahiraam committed Nov 20, 2023
1 parent eeb2e89 commit c410e21
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion llvm/utils/release/build_llvm_release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%

Expand Down Expand Up @@ -261,9 +263,11 @@ set all_cmake_flags=^
-DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe
set cmake_flags=%all_cmake_flags:\=/%


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
Expand Down Expand Up @@ -388,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:
Expand Down

0 comments on commit c410e21

Please sign in to comment.