diff --git a/src/coreclr/build.cmd b/src/coreclr/build.cmd index 7e8a3d74c61d2..4f23a962ee56d 100644 --- a/src/coreclr/build.cmd +++ b/src/coreclr/build.cmd @@ -388,24 +388,26 @@ if %__RestoreOptData% EQU 1 ( goto ExitWithCode ) ) +set __PgoOptDataPath= +if %__PgoOptimize% EQU 1 ( + set PgoDataPackagePathOutputFile="%__IntermediatesDir%\optdatapath.txt" -set PgoDataPackagePathOutputFile="%__IntermediatesDir%\optdatapath.txt" + REM Parse the optdata package versions out of msbuild so that we can pass them on to CMake + powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" /clp:nosummary %__ArcadeScriptArgs%^ + "%OptDataProjectFilePath%" /t:DumpPgoDataPackagePath %__CommonMSBuildArgs% /p:PgoDataPackagePathOutputFile="!PgoDataPackagePathOutputFile!" -REM Parse the optdata package versions out of msbuild so that we can pass them on to CMake -powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" /clp:nosummary %__ArcadeScriptArgs%^ - "%OptDataProjectFilePath%" /t:DumpPgoDataPackagePath %__CommonMSBuildArgs% /p:PgoDataPackagePathOutputFile="!PgoDataPackagePathOutputFile!" + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%Failed to get PGO data package path. + set __exitCode=!errorlevel! + goto ExitWithCode + ) + if not exist "!PgoDataPackagePathOutputFile!" ( + echo %__ErrMsgPrefix%Failed to get PGO data package path. + goto ExitWithError + ) - if not !errorlevel! == 0 ( - echo %__ErrMsgPrefix%Failed to get PGO data package path. - set __exitCode=!errorlevel! - goto ExitWithCode + set /p __PgoOptDataPath=<"!PgoDataPackagePathOutputFile!" ) -if not exist "!PgoDataPackagePathOutputFile!" ( - echo %__ErrMsgPrefix%Failed to get PGO data package path. - goto ExitWithError -) - -set /p __PgoOptDataPath=<"!PgoDataPackagePathOutputFile!" REM ========================================================================================= REM === diff --git a/src/coreclr/build.sh b/src/coreclr/build.sh index 131fd7ca809f1..c7e32b7e100c9 100755 --- a/src/coreclr/build.sh +++ b/src/coreclr/build.sh @@ -62,7 +62,7 @@ restore_optdata() fi fi - if [[ "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then + if [[ "$__PgoOptimize" == 1 && "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then # Parse the optdata package versions out of msbuild so that we can pass them on to CMake local PgoDataPackagePathOutputFile="${__IntermediatesDir}/optdatapath.txt" diff --git a/src/coreclr/pgosupport.cmake b/src/coreclr/pgosupport.cmake index f5a2d2f62d69b..7e24b7d2f2102 100644 --- a/src/coreclr/pgosupport.cmake +++ b/src/coreclr/pgosupport.cmake @@ -3,17 +3,6 @@ check_ipo_supported(RESULT HAVE_LTO) # Adds Profile Guided Optimization (PGO) flags to the current target function(add_pgo TargetName) - if(CLR_CMAKE_HOST_WIN32) - set(ProfileFileName "${TargetName}.pgd") - else(CLR_CMAKE_HOST_WIN32) - set(ProfileFileName "${TargetName}.profdata") - endif(CLR_CMAKE_HOST_WIN32) - - file(TO_NATIVE_PATH - "${CLR_CMAKE_OPTDATA_PATH}/data/${ProfileFileName}" - ProfilePath - ) - if(CLR_CMAKE_PGO_INSTRUMENT) if(CLR_CMAKE_HOST_WIN32) set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /GENPROFILE") @@ -25,6 +14,17 @@ function(add_pgo TargetName) endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO) endif(CLR_CMAKE_HOST_WIN32) elseif(CLR_CMAKE_PGO_OPTIMIZE) + if(CLR_CMAKE_HOST_WIN32) + set(ProfileFileName "${TargetName}.pgd") + else(CLR_CMAKE_HOST_WIN32) + set(ProfileFileName "${TargetName}.profdata") + endif(CLR_CMAKE_HOST_WIN32) + + file(TO_NATIVE_PATH + "${CLR_CMAKE_OPTDATA_PATH}/data/${ProfileFileName}" + ProfilePath + ) + # If we don't have profile data availble, gracefully fall back to a non-PGO opt build if(NOT EXISTS ${ProfilePath}) message("PGO data file NOT found: ${ProfilePath}")