From e864674fbda61cb573fe6bf30685688f8d4ed23f Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Wed, 17 Sep 2025 15:19:56 -0700 Subject: [PATCH] add pgo support to build.cmd --- build.bat | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/build.bat b/build.bat index 34a69c08..872312bf 100644 --- a/build.bat +++ b/build.bat @@ -43,6 +43,26 @@ if "%telemetry%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_TELE if "%spall%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_SPALL=1 && echo [spall profiling enabled] if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=address && echo [asan enabled] if "%opengl%"=="1" set auto_compile_flags=%auto_compile_flags% -DR_BACKEND=R_BACKEND_OPENGL && echo [opengl render backend] +if "%pgo%"=="1" ( + if "%no_meta%"=="" echo ERROR: PGO build must have no_meta argument || exit /b 1 + where llvm-profdata /q || echo llvm-profdata is not in the PATH || exit /b 1 + + if "%clang%"=="1" ( + if "%pgo_run%" == "1" ( + call llvm-profdata merge %LLVM_PROFILE_FILE% -output=%~dp0build\build.profdata || exit /b 1 + set auto_compile_flags=%auto_compile_flags% -fprofile-use=%~dp0build\build.profdata + set pgo_run=0 + ) else ( + echo [pgo enabled] + set auto_compile_flags=%auto_compile_flags% -fprofile-generate -mllvm -vp-counters-per-site=5 + set LLVM_PROFILE_FILE=%~dp0build\build.profraw + set pgo_run=1 + ) + ) else ( + echo ERROR: PGO build is not supported with current compiler + exit /b 1 + ) +) :: --- Compile/Link Line Definitions ------------------------------------------ set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7 @@ -139,3 +159,15 @@ if "%didbuild%"=="" ( echo [WARNING] no valid build target specified; must use build target names as arguments to this script, like `build raddbg` or `build rdi_from_pdb`. exit /b 1 ) + +:: --- PGO Run --------------------------------------------------------------- + +if "%pgo_run%"=="1" ( + if "%radlink%"=="1" ( + pushd build + call radlink lnk.obj /debug:full + popd + ) + call %0 %* +) +