From 94788b256bc2aaa930341e27dc5ae3baf3bbf8b5 Mon Sep 17 00:00:00 2001 From: Daniel Podder Date: Tue, 13 Jun 2017 14:51:55 -0700 Subject: [PATCH] Skip PGO if clang is too old, and add warnings for skipped PGO (#12248) Clang/LLVM cannot merge profile data generated by a newer version of itself. Training currently requires 3.6, but we don't want to completely break the build for 3.5. I'm adding a version check to allow non-PGO release builds on 3.5, along with a warning message. I'm also updating the LTO detection to print a warning message if it causes PGO to be disabled. --- pgosupport.cmake | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pgosupport.cmake b/pgosupport.cmake index f3d00b7..e92923f 100644 --- a/pgosupport.cmake +++ b/pgosupport.cmake @@ -42,10 +42,16 @@ function(add_pgo TargetName) 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} -Wno-profile-instr-out-of-date) - set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-use=${ProfilePath}") - endif(HAVE_LTO) + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) + if(HAVE_LTO) + target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath} -Wno-profile-instr-out-of-date) + set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-use=${ProfilePath}") + else(HAVE_LTO) + message(WARNING "LTO is not supported, skipping profile guided optimizations") + endif(HAVE_LTO) + else(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) + message(WARNING "PGO is not supported; Clang 3.6 or later is required for profile guided optimizations") + endif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO) endif(WIN32) endif(EXISTS ${ProfilePath}) -- 2.7.4