llvm.org GIT mirror llvm / 5270967
[cmake] Changes to get Windows self-host working with PGO Fixes quoting of profile arguments to work on Windows Suppresses adding profile arguments to linker flags when using lld-link Avoids -fprofile-instr-use being added to rc.exe flags Removes duplicated adding of -fprofile-instr-use to linker flags (since r355541) Move handling LLVM_PROFDATA_FILE to HandleLLVMOptions.cmake Differential Revision: https://reviews.llvm.org/D62063 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372209 91177308-0d34-0410-b5e6-96231b3b80d8 Russell Gallop 25 days ago
2 changed file(s) with 39 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
617617 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL
618618 "Enable per-target runtimes directory")
619619
620 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
621 "Profiling data file to use when compiling in order to improve runtime performance.")
622
620623 # All options referred to from HandleLLVMOptions have to be specified
621624 # BEFORE this include, otherwise options will not be correctly set on
622625 # first cmake run
878881 # Make sure we don't get -rdynamic in every binary. For those that need it,
879882 # use export_executable_symbols(target).
880883 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
881
882 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
883 "Profiling data file to use when compiling in order to improve runtime performance.")
884
885 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
886 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
887 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
888 else()
889 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
890 endif()
891 endif()
892884
893885 include(AddLLVM)
894886 include(TableGen)
820820
821821 if (LLVM_BUILD_INSTRUMENTED)
822822 if (LLVM_ENABLE_IR_PGO OR uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "IR")
823 append("-fprofile-generate='${LLVM_PROFILE_DATA_DIR}'"
823 append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\""
824824 CMAKE_CXX_FLAGS
825 CMAKE_C_FLAGS
826 CMAKE_EXE_LINKER_FLAGS
827 CMAKE_SHARED_LINKER_FLAGS)
825 CMAKE_C_FLAGS)
826 if(NOT LINKER_IS_LLD_LINK)
827 append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\""
828 CMAKE_EXE_LINKER_FLAGS
829 CMAKE_SHARED_LINKER_FLAGS)
830 endif()
828831 elseif(uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSIR")
829 append("-fcs-profile-generate='${LLVM_CSPROFILE_DATA_DIR}'"
832 append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
830833 CMAKE_CXX_FLAGS
831 CMAKE_C_FLAGS
832 CMAKE_EXE_LINKER_FLAGS
833 CMAKE_SHARED_LINKER_FLAGS)
834 CMAKE_C_FLAGS)
835 if(NOT LINKER_IS_LLD_LINK)
836 append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
837 CMAKE_EXE_LINKER_FLAGS
838 CMAKE_SHARED_LINKER_FLAGS)
839 endif()
834840 else()
835 append("-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}'"
841 append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
836842 CMAKE_CXX_FLAGS
837 CMAKE_C_FLAGS
838 CMAKE_EXE_LINKER_FLAGS
839 CMAKE_SHARED_LINKER_FLAGS)
840 endif()
841 endif()
842
843 # Need to pass -fprofile-instr-use to linker for context-sensitive PGO
844 # compilation.
843 CMAKE_C_FLAGS)
844 if(NOT LINKER_IS_LLD_LINK)
845 append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
846 CMAKE_EXE_LINKER_FLAGS
847 CMAKE_SHARED_LINKER_FLAGS)
848 endif()
849 endif()
850 endif()
851
845852 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
846 append("-fprofile-instr-use='${LLVM_PROFDATA_FILE}'"
847 CMAKE_EXE_LINKER_FLAGS
848 CMAKE_SHARED_LINKER_FLAGS)
853 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
854 append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
855 CMAKE_CXX_FLAGS
856 CMAKE_C_FLAGS)
857 if(NOT LINKER_IS_LLD_LINK)
858 append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
859 CMAKE_EXE_LINKER_FLAGS
860 CMAKE_SHARED_LINKER_FLAGS)
861 endif()
862 else()
863 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
864 endif()
849865 endif()
850866
851867 option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation" Off)