Skip to content

Commit a84b200

Browse files
committed
[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 llvm-svn: 372209
1 parent 1786117 commit a84b200

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

llvm/CMakeLists.txt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
618618
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL
619619
"Enable per-target runtimes directory")
620620

621+
set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
622+
"Profiling data file to use when compiling in order to improve runtime performance.")
623+
621624
# All options referred to from HandleLLVMOptions have to be specified
622625
# BEFORE this include, otherwise options will not be correctly set on
623626
# first cmake run
@@ -880,17 +883,6 @@ endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
880883
# use export_executable_symbols(target).
881884
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
882885

883-
set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
884-
"Profiling data file to use when compiling in order to improve runtime performance.")
885-
886-
if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
887-
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
888-
add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
889-
else()
890-
message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
891-
endif()
892-
endif()
893-
894886
include(AddLLVM)
895887
include(TableGen)
896888

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -821,32 +821,48 @@ string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" uppercase_LLVM_BUILD_INSTRUMENTED)
821821

822822
if (LLVM_BUILD_INSTRUMENTED)
823823
if (LLVM_ENABLE_IR_PGO OR uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "IR")
824-
append("-fprofile-generate='${LLVM_PROFILE_DATA_DIR}'"
824+
append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\""
825825
CMAKE_CXX_FLAGS
826-
CMAKE_C_FLAGS
827-
CMAKE_EXE_LINKER_FLAGS
828-
CMAKE_SHARED_LINKER_FLAGS)
826+
CMAKE_C_FLAGS)
827+
if(NOT LINKER_IS_LLD_LINK)
828+
append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\""
829+
CMAKE_EXE_LINKER_FLAGS
830+
CMAKE_SHARED_LINKER_FLAGS)
831+
endif()
829832
elseif(uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSIR")
830-
append("-fcs-profile-generate='${LLVM_CSPROFILE_DATA_DIR}'"
833+
append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
831834
CMAKE_CXX_FLAGS
832-
CMAKE_C_FLAGS
833-
CMAKE_EXE_LINKER_FLAGS
834-
CMAKE_SHARED_LINKER_FLAGS)
835+
CMAKE_C_FLAGS)
836+
if(NOT LINKER_IS_LLD_LINK)
837+
append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\""
838+
CMAKE_EXE_LINKER_FLAGS
839+
CMAKE_SHARED_LINKER_FLAGS)
840+
endif()
835841
else()
836-
append("-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}'"
842+
append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
837843
CMAKE_CXX_FLAGS
838-
CMAKE_C_FLAGS
839-
CMAKE_EXE_LINKER_FLAGS
840-
CMAKE_SHARED_LINKER_FLAGS)
844+
CMAKE_C_FLAGS)
845+
if(NOT LINKER_IS_LLD_LINK)
846+
append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
847+
CMAKE_EXE_LINKER_FLAGS
848+
CMAKE_SHARED_LINKER_FLAGS)
849+
endif()
841850
endif()
842851
endif()
843852

844-
# Need to pass -fprofile-instr-use to linker for context-sensitive PGO
845-
# compilation.
846853
if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
847-
append("-fprofile-instr-use='${LLVM_PROFDATA_FILE}'"
848-
CMAKE_EXE_LINKER_FLAGS
849-
CMAKE_SHARED_LINKER_FLAGS)
854+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
855+
append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
856+
CMAKE_CXX_FLAGS
857+
CMAKE_C_FLAGS)
858+
if(NOT LINKER_IS_LLD_LINK)
859+
append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
860+
CMAKE_EXE_LINKER_FLAGS
861+
CMAKE_SHARED_LINKER_FLAGS)
862+
endif()
863+
else()
864+
message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
865+
endif()
850866
endif()
851867

852868
option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation" Off)

0 commit comments

Comments
 (0)