From 834a40b463af608684d102762e95b335ebedcfbb Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 8 Apr 2016 22:48:18 +0000 Subject: [PATCH] [Perf-Training] Reworked workflow improvements for order-file generation This is re-landing r260742. I've reworked the conditionals so that it only hits when targeting Apple platforms with ld64. Original Summary: With this change generating clang order files using dtrace uses the following workflow: cmake ninja generate-order-file ninja clang This patch works by setting a default path to the order file (which can be overridden by the user). If the order file doesn't exist during configuration CMake will create an empty one. CMake then ties up the dependencies between the clang link job and the order file, and generate-order-file overwrites CLANG_ORDER_FILE with the new order file. llvm-svn: 265864 --- clang/CMakeLists.txt | 29 ++++++++++++++++-------- clang/tools/driver/CMakeLists.txt | 21 +++++++++++++++-- clang/utils/perf-training/CMakeLists.txt | 3 +-- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 79af7e584975..5c0d28de36d4 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -595,17 +595,28 @@ if( CLANG_INCLUDE_DOCS ) add_subdirectory(docs) endif() -if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/clang.order") - file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/clang.order") -endif() -if(CLANG_ORDER_FILE STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/clang.order") - unset(CLANG_ORDER_FILE CACHE) - unset(CLANG_ORDER_FILE) -endif() +if(APPLE) + # this line is needed as a cleanup to ensure that any CMakeCaches with the old + # default value get updated to the new default. + if(CLANG_ORDER_FILE STREQUAL "") + unset(CLANG_ORDER_FILE CACHE) + unset(CLANG_ORDER_FILE) + endif() -set(CLANG_ORDER_FILE "" CACHE FILEPATH - "Order file to use when compiling clang in order to improve startup time.") + + set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH + "Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).") + + if(CLANG_ORDER_FILE AND NOT EXISTS ${CLANG_ORDER_FILE}) + string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START) + if(PATH_START EQUAL 0) + file(WRITE ${CLANG_ORDER_FILE} "\n") + else() + message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.") + endif() + endif() +endif() if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR CMAKE_VERSION VERSION_GREATER 3) diff --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt index 5f338853629e..e03b3fa3951e 100644 --- a/clang/tools/driver/CMakeLists.txt +++ b/clang/tools/driver/CMakeLists.txt @@ -87,8 +87,25 @@ if (APPLE) set(TOOL_INFO_BUILD_VERSION) endif() -if(CLANG_ORDER_FILE AND EXISTS ${CLANG_ORDER_FILE}) - target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}") +# the linker -order_file flag is only supported by ld64 +if(LD64_EXECUTABLE AND CLANG_ORDER_FILE) + include(CMakePushCheckState) + + function(check_linker_flag flag out_var) + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") + check_cxx_compiler_flag("" ${out_var}) + cmake_pop_check_state() + endfunction() + + # This is a test to ensure the actual order file works with the linker. + check_linker_flag("-Wl,-order_file,${CLANG_ORDER_FILE}" + LINKER_ORDER_FILE_WORKS) + + if(LINKER_ORDER_FILE_WORKS) + target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}") + set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE}) + endif() endif() if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) diff --git a/clang/utils/perf-training/CMakeLists.txt b/clang/utils/perf-training/CMakeLists.txt index 32f7c84555b4..f8647a0e44f7 100644 --- a/clang/utils/perf-training/CMakeLists.txt +++ b/clang/utils/perf-training/CMakeLists.txt @@ -55,9 +55,8 @@ if(DTRACE) COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} dtrace COMMENT "Clearing old dtrace data") - add_custom_target(generate-order-file - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $ --output ${CMAKE_CURRENT_BINARY_DIR}/clang.order ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $ --output ${CLANG_ORDER_FILE} ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating order file" DEPENDS generate-dtrace-logs) endif()