Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ project(CoreCLR)
# Include cmake functions
include(functions.cmake)

# Include global configure settings
include(configure.cmake)

if (WIN32)
message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
Expand Down
12 changes: 12 additions & 0 deletions configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include(CheckCXXSourceCompiles)

# 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)
set(CMAKE_REQUIRED_LIBRARIES -flto -fuse-ld=gold)
check_cxx_source_compiles("int main() { return 0; }" HAVE_LTO)
endfunction(check_have_lto)
check_have_lto()
endif(NOT WIN32)
43 changes: 27 additions & 16 deletions pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ endfunction(clr_pgo_unknown_arch)
function(add_pgo TargetName)
if(WIN32)
set(ProfileFileName "${TargetName}.pgd")
else(WIN32)
# Clang/LLVM uses one profdata file for the entire repo
set(ProfileFileName "coreclr.profdata")
endif(WIN32)

set(CLR_CMAKE_OPTDATA_PACKAGEWITHRID "optimization.${CLR_CMAKE_TARGET_OS}-${CLR_CMAKE_TARGET_ARCH}.PGO.CoreCLR")
Expand All @@ -18,24 +21,32 @@ function(add_pgo TargetName)
ProfilePath
)

# Enable PGO only for optimized configs
set(ConfigTypeList RELEASE RELWITHDEBINFO)

foreach(ConfigType IN LISTS ConfigTypeList)
set(LinkFlagsProperty "LINK_FLAGS_${ConfigType}")
if(CLR_CMAKE_PGO_INSTRUMENT)
if(CLR_CMAKE_PGO_INSTRUMENT)
if(WIN32)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /GENPROFILE")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /GENPROFILE")
else(WIN32)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-generate)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-generate")
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
endif(WIN32)
else(CLR_CMAKE_PGO_INSTRUMENT)
# If we don't have profile data availble, gracefully fall back to a non-PGO opt build
if(EXISTS ${ProfilePath})
if(WIN32)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY ${LinkFlagsProperty} "/LTCG /GENPROFILE")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /USEPROFILE:PGD=${ProfilePath}")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /USEPROFILE:PGD=${ProfilePath}")
else(WIN32)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
if(HAVE_LTO)
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath})
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-use=${ProfilePath}")
endif(HAVE_LTO)
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
endif(WIN32)
else(CLR_CMAKE_PGO_INSTRUMENT)
# If we don't have profile data availble, gracefully fall back to a non-PGO opt build
if(EXISTS ${ProfilePath})
if(WIN32)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY ${LinkFlagsProperty} "/LTCG /USEPROFILE:PGD=${ProfilePath}")
endif(WIN32)
endif(EXISTS ${ProfilePath})
endif(CLR_CMAKE_PGO_INSTRUMENT)
endforeach(ConfigType)
endif(EXISTS ${ProfilePath})
endif(CLR_CMAKE_PGO_INSTRUMENT)
endfunction(add_pgo)

if(WIN32)
Expand Down