Skip to content

Commit

Permalink
Fix using the nopgooptimize flag in the CoreCLR build scripts. (dotne…
Browse files Browse the repository at this point in the history
…t#31931)

* Only try to resolve PGO package path when PGOOptimize is enabled.

* Don't resolve PGO files unless we're optimizing with PGO.

* Only get the PgoDataPackagePath whne PGOOptimize is enabled.
  • Loading branch information
jkoritzinsky authored Feb 7, 2020
1 parent a6228db commit 7814f97
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
30 changes: 16 additions & 14 deletions src/coreclr/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 11 additions & 11 deletions src/coreclr/pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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}")
Expand Down

0 comments on commit 7814f97

Please sign in to comment.