@@ -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+
157159REM Preserve original path
158160set OLDPATH = %PATH%
159161
@@ -261,9 +263,11 @@ set all_cmake_flags=^
261263 -DCMAKE_RC=%stage0_bin_dir% /llvm-windres.exe
262264set cmake_flags = %all_cmake_flags:\ =/ %
263265
266+
264267mkdir build64
265268cd 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
267271ninja || ninja || ninja || exit /b 1
268272ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
269273ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
@@ -388,8 +392,38 @@ ninja install || exit /b 1
388392set libxmldir = %cd% \install
389393set " libxmldir = %libxmldir:\ =/ % "
390394cd ..
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%
392425exit /b 0
426+
393427:: =============================================================================
394428:: Parse command line arguments.
395429:: The format for the arguments is:
0 commit comments