[PATCH] D16896: [CMake] Improve the clang order-file generation workflow

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 4 13:23:30 PST 2016


Chris Bieneman <beanz at apple.com> writes:
> beanz created this revision.
> beanz added a reviewer: bogner.
> beanz added a subscriber: cfe-commits.
>
> With this change generating clang order files using dtrace uses the
> following workflow:
>
> # Configure LLVM & Clang using any options on a system with dtrace
> cmake <whatever options you want>
>
> # Builds clang and runs the perf-training data to generate the order file
> ninja generate-order-file
>
> # Re-link clang with the new 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.

This is kind of a strange workflow, but it seems reasonable (especially
for experimenting and testing purposes). LGTM once the comment below is
resolved.

> http://reviews.llvm.org/D16896
>
> Files:
>   CMakeLists.txt
>   tools/driver/CMakeLists.txt
>   utils/perf-training/CMakeLists.txt
>
> Index: utils/perf-training/CMakeLists.txt
> ===================================================================
> --- utils/perf-training/CMakeLists.txt
> +++ utils/perf-training/CMakeLists.txt
> @@ -55,9 +55,8 @@
>      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 $<TARGET_FILE:clang> --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 $<TARGET_FILE:clang> --output ${CLANG_ORDER_FILE} ${CMAKE_CURRENT_BINARY_DIR}
>      COMMENT "Generating order file"
>      DEPENDS generate-dtrace-logs)
>  endif()
> Index: tools/driver/CMakeLists.txt
> ===================================================================
> --- tools/driver/CMakeLists.txt
> +++ tools/driver/CMakeLists.txt
> @@ -87,8 +87,10 @@
>    set(TOOL_INFO_BUILD_VERSION)
>  endif()
>  
> -if(CLANG_ORDER_FILE)
> +# The MSVC linker doesn't respect the order_file option
> +if(NOT MSVC)
>    target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}")
> +  set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})

It's probably better to have cmake check if the linker supports this
flag rather than hard coding MSVC in particular here. Who knows what
strange linkers are being used in the wild.

>  endif()
>  
>  if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
> Index: CMakeLists.txt
> ===================================================================
> --- CMakeLists.txt
> +++ CMakeLists.txt
> @@ -586,9 +586,19 @@
>    add_subdirectory(docs)
>  endif()
>  
> -set(CLANG_ORDER_FILE "" CACHE FILEPATH
> +# 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)
> +endif()
> +
> +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.")
>  
> +if(NOT EXISTS ${CLANG_ORDER_FILE})
> +  execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${CLANG_ORDER_FILE})
> +endif()
> +
>  if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR
>      CMAKE_VERSION VERSION_GREATER 3)
>    # Generate a list of CMake library targets so that other CMake projects can
>


More information about the cfe-commits mailing list