@@ -154,6 +154,8 @@ set common_cmake_flags=^
154
154
-DCMAKE_CXX_FLAGS=" -DLIBXML_STATIC" ^
155
155
-DLLVM_ENABLE_PROJECTS=" clang;clang-tools-extra;lld;compiler-rt;lldb;openmp"
156
156
157
+ set cmake_profile_flag = " "
158
+
157
159
REM Preserve original path
158
160
set OLDPATH = %PATH%
159
161
@@ -261,9 +263,11 @@ set all_cmake_flags=^
261
263
-DCMAKE_RC=%stage0_bin_dir% /llvm-windres.exe
262
264
set cmake_flags = %all_cmake_flags:\ =/ %
263
265
266
+
264
267
mkdir build64
265
268
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
267
271
ninja || ninja || ninja || exit /b 1
268
272
ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
269
273
ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
@@ -388,8 +392,38 @@ ninja install || exit /b 1
388
392
set libxmldir = %cd% \install
389
393
set " libxmldir = %libxmldir:\ =/ % "
390
394
cd ..
395
+ exit /b 0
391
396
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%
392
425
exit /b 0
426
+
393
427
:: =============================================================================
394
428
:: Parse command line arguments.
395
429
:: The format for the arguments is:
0 commit comments