Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable LTO #1627

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions hilti/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ set(SOURCES
src/version.cc
${PROJECT_SOURCE_DIR}/3rdparty/utf8proc/utf8proc.c)

include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported)

foreach (lib hilti-rt hilti-rt-debug)
add_library(${lib}-objects OBJECT ${SOURCES})
target_compile_options(${lib}-objects PRIVATE "-fPIC")

if (ipo_supported)
set_property(TARGET ${lib}-objects PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
endif ()

target_link_libraries(${lib}-objects PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
target_include_directories(${lib}-objects BEFORE
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
Expand All @@ -74,6 +82,9 @@ foreach (lib hilti-rt hilti-rt-debug)
target_link_libraries(${lib} ${lib}-objects)
target_link_libraries(${lib} jrx-objects)
target_link_libraries(${lib} fiber)
if (ipo_supported)
set_property(TARGET ${lib} PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
endif ()
endforeach ()

# Build hilti-rt with release flags.
Expand Down
6 changes: 6 additions & 0 deletions hilti/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ add_dependencies(hilti-objects reproc++)
target_include_directories(hilti-objects BEFORE
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/reproc/reproc++/include)

include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if (IPO_SUPPORTED)
set_property(TARGET hilti-objects PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
endif ()

add_library(hilti)
hilti_link_object_libraries_in_tree(hilti PUBLIC)

Expand Down
14 changes: 8 additions & 6 deletions hilti/toolchain/src/config.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void Configuration::init(bool use_build_directory) {
prefix("${HILTI_CONFIG_RUNTIME_CXX_FLAGS_DEBUG}", "", installation_tag)});

runtime_cxx_flags_release = flatten({"-fPIC", "-std=c++17", "-g", "-O3", "-DNDEBUG", "-fvisibility=hidden",
"-flto", // FIXME(bbannier): enable if detected in CMake.
prefix("${HILTI_CONFIG_RUNTIME_CXX_INCLUDE_DIRS}", "-I", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_CXX_FLAGS_RELEASE}", "", installation_tag)});

Expand All @@ -162,12 +163,13 @@ void Configuration::init(bool use_build_directory) {
prefix("${HILTI_CONFIG_RUNTIME_LD_FLAGS_DEBUG}", "", installation_tag),
prefix(CMAKE_THREAD_LIBS_INIT, "-l", installation_tag), prefix(CMAKE_DL_LIBS, "-l", installation_tag)});

runtime_ld_flags_release = flatten(
{prefix("${HILTI_CONFIG_RUNTIME_CXX_LIBRARY_DIRS}", "-L", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_CXX_LIBRARY_DIRS}", "-Wl,-rpath,", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_LIBRARIES_RELEASE}", "-l", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_LD_FLAGS_RELEASE}", "", installation_tag),
prefix(CMAKE_THREAD_LIBS_INIT, "-l", installation_tag), prefix(CMAKE_DL_LIBS, "-l", installation_tag)});
runtime_ld_flags_release =
flatten({prefix("${HILTI_CONFIG_RUNTIME_CXX_LIBRARY_DIRS}", "-L", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_CXX_LIBRARY_DIRS}", "-Wl,-rpath,", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_LIBRARIES_RELEASE}", "-l", installation_tag),
prefix("${HILTI_CONFIG_RUNTIME_LD_FLAGS_RELEASE}", "", installation_tag),
prefix(CMAKE_THREAD_LIBS_INIT, "-l", installation_tag), prefix(CMAKE_DL_LIBS, "-l", installation_tag),
"-flto"}); // FIXME(bbannier): enable if detected in CMake.

hlto_cxx_flags_debug = runtime_cxx_flags_debug;
hlto_cxx_flags_release = runtime_cxx_flags_release;
Expand Down
5 changes: 2 additions & 3 deletions scripts/precompile-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ cp "${LIBHILTI}" "${CACHE}/precompiled_libhilti_debug.h"
$("${HILTI_CONFIG}" --cxx --cxxflags --debug) -x c++-header "${LIBHILTI}" -o "${CACHE}/precompiled_libhilti_debug.h.gch"

cp "${LIBHILTI}" "${CACHE}/precompiled_libhilti.h"

$("${HILTI_CONFIG}" --cxx --cxxflags) -x c++-header "${LIBHILTI}" -o "${CACHE}/precompiled_libhilti.h.gch"
$("${HILTI_CONFIG}" --cxx --cxxflags | sed 's/-flto//g') -x c++-header "${LIBHILTI}" -o "${CACHE}/precompiled_libhilti.h.gch"

cp "${LIBSPICY}" "${CACHE}/precompiled_libspicy_debug.h"
$("${SPICY_CONFIG}" --cxx --cxxflags --debug) -x c++-header "${LIBSPICY}" -o "${CACHE}/precompiled_libspicy_debug.h.gch"

cp "${LIBSPICY}" "${CACHE}/precompiled_libspicy.h"
$("${SPICY_CONFIG}" --cxx --cxxflags) -x c++-header "${LIBSPICY}" -o "${CACHE}/precompiled_libspicy.h.gch"
$("${SPICY_CONFIG}" --cxx --cxxflags | sed 's/-flto//g') -x c++-header "${LIBSPICY}" -o "${CACHE}/precompiled_libspicy.h.gch"
6 changes: 6 additions & 0 deletions spicy/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ target_link_libraries(spicy-objects
target_link_libraries(spicy-objects PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
target_link_libraries(spicy-objects PRIVATE hilti)

include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if (IPO_SUPPORTED)
set_property(TARGET spicy-objects PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
endif ()

add_library(spicy)
hilti_link_libraries_in_tree(spicy PUBLIC)
spicy_link_object_libraries_in_tree(spicy PUBLIC)
Expand Down