Skip PGO if clang is too old, and add warnings for skipped PGO (#12248)
authorDaniel Podder <dapodd@microsoft.com>
Tue, 13 Jun 2017 21:51:55 +0000 (14:51 -0700)
committerGitHub <noreply@github.com>
Tue, 13 Jun 2017 21:51:55 +0000 (14:51 -0700)
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

index f3d00b7..e92923f 100644 (file)
@@ -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})