Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Podder <dapodd@microsoft.com>2017-03-30 05:01:55 +0300
committerGitHub <noreply@github.com>2017-03-30 05:01:55 +0300
commitdf3eac55bb16b52b2d513a643a202b9c36a3078d (patch)
tree60645c8aa503dc96b627be68e19c3a7d30b5c47c /src/coreclr/pgosupport.cmake
parent52d9df51520d729b90601857008996d0905b7a69 (diff)
Add PGO support for Clang/LLVM on Unix (dotnet/coreclr#10533)
Extend PGO support from VC++ on WIN32 to Clang/LLVM on UNIX as well. * Just like on Windows: if profile data is missing, skip enabling PGO (allows non-PGO builds in branches where we don't publish PGO data). * PGO with LTO requires additional dependencies (namely a discoverable `ld.gold` and `LLVMgold.so`). To protect against broken support and keep the build flexible across a wider array of distros, attempt to detect whether PGO compilation would work (using cmake's `try_compile()`), and fall back to a non-PGO/non-LTO build if the test fails. Commit migrated from https://github.com/dotnet/coreclr/commit/926d104068fffb7e7cf867ab4c92082aab968692
Diffstat (limited to 'src/coreclr/pgosupport.cmake')
-rw-r--r--src/coreclr/pgosupport.cmake43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/coreclr/pgosupport.cmake b/src/coreclr/pgosupport.cmake
index e4e6bd50914..dbba415a618 100644
--- a/src/coreclr/pgosupport.cmake
+++ b/src/coreclr/pgosupport.cmake
@@ -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")
@@ -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)