diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index f123c457cdb79..a3b9ffbead17b 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -11,6 +11,7 @@ option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON) option(SYCL_ENABLE_COVERAGE "Enables code coverage for runtime and unit tests" OFF) option(SYCL_ENABLE_STACK_PRINTING "Enables stack printing on crashes of SYCL applications" OFF) option(SYCL_LIB_WITH_DEBUG_SYMBOLS "Builds SYCL runtime libraries with debug symbols" OFF) +option(SYCL_ENABLE_IPO "Builds SYCL runtime libraries with interprocedural optimization" OFF) if (NOT SYCL_COVERAGE_PATH) set(SYCL_COVERAGE_PATH "${CMAKE_CURRENT_BINARY_DIR}/profiles") diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index 4159303f87d19..be262a28d8093 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -4,6 +4,7 @@ #cmake_policy(SET CMP0057 NEW) #include(AddLLVM) include(CheckLinkerFlag) +include(CheckIPOSupported) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @@ -16,6 +17,13 @@ if (SYCL_ENABLE_XPTI_TRACING) include_directories(${LLVM_EXTERNAL_XPTI_SOURCE_DIR}/include) endif() +if(SYCL_ENABLE_IPO) + check_ipo_supported(RESULT SYCL_USE_IPO) + if (NOT SYCL_USE_IPO) + message(WARNING "Interprocedural optimization is not supported by the compiler, disabling") + endif() +endif() + function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) # Add an optional argument so we can get the library name to # link with for Windows Debug version @@ -23,6 +31,10 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) add_library(${LIB_OBJ_NAME} OBJECT ${ARG_SOURCES}) + if(SYCL_USE_IPO) + set_property(TARGET ${LIB_OBJ_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() + # Common compilation step setup check_cxx_compiler_flag(-Winstantiation-after-specialization @@ -79,6 +91,10 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) $ ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + if(SYCL_USE_IPO) + set_property(TARGET ${LIB_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() + find_package(Threads REQUIRED) target_link_libraries(${LIB_NAME}