Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/coreclr/pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,41 @@ function(add_pgo TargetName)
endif(NOT EXISTS ${ProfilePath})
endif(CLR_CMAKE_PGO_INSTRUMENT)
endfunction(add_pgo)

# On non-Windows platforms, PGO compile flags (-fprofile-instr-generate for instrumentation,
# -fprofile-instr-use for optimization) must be applied at directory scope so they also affect
# the static and object libraries (cee_wks, utilcode, coreclrpal, etc.) that are linked into
# the final shared libraries. The per-target add_pgo function above only applies compile flags
# to the shared library target itself, which only covers its directly compiled sources
# (e.g. mscoree.cpp and exports.cpp for coreclr). add_pgo still sets the per-target LTO
# link flags needed by the final shared library.
# On Windows, PGO is handled entirely via link-time flags (/LTCG) so this isn't needed.
if(NOT WIN32)
if(CLR_CMAKE_PGO_INSTRUMENT)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-fprofile-instr-generate>)
# All shared libraries need to link the profiling runtime to resolve
# instrumentation symbols from their static library dependencies.
add_link_options(-fprofile-instr-generate)
endif()
endif()
Comment thread
EgorBo marked this conversation as resolved.
elseif(CLR_CMAKE_PGO_OPTIMIZE AND NOT CLR_CMAKE_ENABLE_SANITIZERS)
file(TO_NATIVE_PATH "${CLR_CMAKE_OPTDATA_PATH}/data/coreclr.profdata" _PgoGlobalProfilePath)
if(EXISTS "${_PgoGlobalProfilePath}")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
check_have_lto_and_pgodata_supported("${_PgoGlobalProfilePath}")
if(HAVE_LTO_AND_PGO_DATA_SUPPORTED)
message(STATUS "Enabling profile guided optimizations globally for coreclr static libraries")
add_compile_options(
$<$<COMPILE_LANGUAGE:C,CXX>:-fprofile-instr-use=${_PgoGlobalProfilePath}>
$<$<COMPILE_LANGUAGE:C,CXX>:-Wno-profile-instr-out-of-date>
$<$<COMPILE_LANGUAGE:C,CXX>:-Wno-profile-instr-unprofiled>
)
Comment thread
EgorBo marked this conversation as resolved.
endif()
endif()
endif()
endif()
endif()
endif()
Loading