Skip to content

Only use PGO data if clang can read it #114005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
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
25 changes: 12 additions & 13 deletions src/coreclr/pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ include(CheckCXXCompilerFlag)
# VC++ guarantees support for LTCG (LTO's equivalent)
if(NOT WIN32)
# Function required to give CMAKE_REQUIRED_* local scope
function(check_have_lto)
set(CMAKE_REQUIRED_FLAGS -flto)
function(check_have_lto_and_pgodata_supported profile_path)
set(CMAKE_REQUIRED_FLAGS "-flto -fprofile-instr-use=${profile_path} -Wno-profile-instr-out-of-date -Wno-profile-instr-unprofiled")
set(CMAKE_REQUIRED_LIBRARIES -flto)
check_cxx_source_compiles("int main() { return 0; }" HAVE_LTO)
endfunction(check_have_lto)
check_have_lto()
check_cxx_source_compiles("int main() { return 0; }" HAVE_LTO_AND_PGO_DATA_SUPPORTED)
endfunction(check_have_lto_and_pgodata_supported)

check_cxx_compiler_flag(-faligned-new COMPILER_SUPPORTS_F_ALIGNED_NEW)
endif(NOT WIN32)
Expand Down Expand Up @@ -52,17 +51,17 @@ function(add_pgo TargetName)
add_compile_definitions(WITH_NATIVE_PGO)
else(CLR_CMAKE_HOST_WIN32)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16))
if(HAVE_LTO)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_have_lto_and_pgodata_supported(${ProfilePath})
if(HAVE_LTO_AND_PGO_DATA_SUPPORTED)
message(STATUS "Enabling profile guided optimizations for ${TargetName}")
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath} -Wno-profile-instr-out-of-date -Wno-profile-instr-unprofiled)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fprofile-instr-use=${ProfilePath}")
add_compile_definitions(WITH_NATIVE_PGO)
else(HAVE_LTO)
message(WARNING "LTO is not supported, skipping profile guided optimizations")
endif(HAVE_LTO)
else((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16))
message(WARNING "PGO is not supported; Clang 16 or later is required for profile guided optimizations")
endif((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16))
else(HAVE_LTO_AND_PGO_DATA_SUPPORTED)
message(WARNING "LTO is not supported or PGO optimization data not compatible, skipping profile guided optimizations for ${TargetName}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass msbuild's OfficialBuildId != '' to cmake as CLR_IS_OFFICIAL_BUILD e.g., then we can use it to error out to make the problem visible (probably we don't want it to slip through unnoticed).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, but that is also set for source-build and afaik they can't use our PGO packages so we shouldn't error in that case. I'd do that in a separate PR.

endif(HAVE_LTO_AND_PGO_DATA_SUPPORTED)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
endif(CLR_CMAKE_HOST_WIN32)
endif(NOT EXISTS ${ProfilePath})
Expand Down
Loading