Skip to content

Commit

Permalink
Use Link Time Optimisation whenever possible (#6967)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou committed Jun 30, 2024
1 parent bdc6ed8 commit d0ed29a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/osrm-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ jobs:
CCOMPILER: clang-15
CXXCOMPILER: clang++-15
CUCUMBER_TIMEOUT: 60000
ENABLE_LTO: OFF

- name: clang-15-debug
continue-on-error: false
Expand All @@ -210,6 +211,7 @@ jobs:
CCOMPILER: clang-15
CXXCOMPILER: clang++-15
CUCUMBER_TIMEOUT: 60000
ENABLE_LTO: OFF

- name: clang-18-debug-clang-tidy
continue-on-error: false
Expand All @@ -232,6 +234,7 @@ jobs:
CCOMPILER: clang-14
CXXCOMPILER: clang++-14
CUCUMBER_TIMEOUT: 60000
ENABLE_LTO: OFF

- name: clang-13-release
continue-on-error: false
Expand All @@ -242,6 +245,7 @@ jobs:
CCOMPILER: clang-13
CXXCOMPILER: clang++-13
CUCUMBER_TIMEOUT: 60000
ENABLE_LTO: OFF

- name: conan-linux-debug-asan-ubsan
continue-on-error: false
Expand All @@ -253,6 +257,7 @@ jobs:
CXXCOMPILER: clang++-15
ENABLE_CONAN: ON
ENABLE_SANITIZER: ON
ENABLE_LTO: OFF

- name: conan-linux-release
continue-on-error: false
Expand All @@ -263,6 +268,7 @@ jobs:
CCOMPILER: clang-15
CXXCOMPILER: clang++-15
ENABLE_CONAN: ON
ENABLE_LTO: OFF

- name: gcc-14-release
continue-on-error: false
Expand Down Expand Up @@ -361,6 +367,7 @@ jobs:
TARGET_ARCH: ${{ matrix.TARGET_ARCH }}
OSRM_CONNECTION_RETRIES: ${{ matrix.OSRM_CONNECTION_RETRIES }}
OSRM_CONNECTION_EXP_BACKOFF_COEF: ${{ matrix.OSRM_CONNECTION_EXP_BACKOFF_COEF }}
ENABLE_LTO: ${{ matrix.ENABLE_LTO }}
steps:
- uses: actions/checkout@v4
- name: Build machine architecture
Expand Down Expand Up @@ -521,6 +528,7 @@ jobs:
-DENABLE_SANITIZER=${ENABLE_SANITIZER:-OFF} \
-DBUILD_TOOLS=${BUILD_TOOLS:-OFF} \
-DENABLE_CCACHE=ON \
-DENABLE_LTO=${ENABLE_LTO:-ON} \
-DCMAKE_INSTALL_PREFIX=${OSRM_INSTALL_DIR}
make --jobs=${JOBS}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Use Link Time Optimisation whenever possible. [#6967](https://github.com/Project-OSRM/osrm-backend/pull/6967)
- CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](https://github.com/Project-OSRM/osrm-backend/pull/6974)
- CHANGED: Micro performance optimisation in map matching. [#6976](https://github.com/Project-OSRM/osrm-backend/pull/6976)
- CHANGED: Re-use priority queue in StaticRTree. [#6952](https://github.com/Project-OSRM/osrm-backend/pull/6952)
Expand Down
27 changes: 15 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ option(ENABLE_ASSERTIONS "Use assertions in release mode" OFF)
option(ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF)
option(ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF)
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)
option(ENABLE_LTO "Use LTO if available" OFF)
option(ENABLE_LTO "Use Link Time Optimisation" ON)
option(ENABLE_FUZZING "Fuzz testing using LLVM's libFuzzer" OFF)
option(ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF)
option(ENABLE_CLANG_TIDY "Enables clang-tidy checks" OFF)


if (ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
if(NOT CLANG_TIDY_COMMAND)
Expand All @@ -57,6 +58,18 @@ if (POLICY CMP0074)
endif()
project(OSRM C CXX)


if(ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
if(LTO_SUPPORTED)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(FATAL_ERROR "IPO / LTO not supported: <${error}>")
endif()
endif()

# add @loader_path/$ORIGIN to rpath to make binaries relocatable
if (APPLE)
set(CMAKE_BUILD_RPATH "@loader_path")
Expand Down Expand Up @@ -208,17 +221,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb")
endif()

if(ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
if(LTO_SUPPORTED)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO / LTO not supported: <${error}>")
endif()
endif()

set(MAYBE_COVERAGE_LIBRARIES "")
if (ENABLE_COVERAGE)
if (NOT CMAKE_BUILD_TYPE MATCHES "Debug")
Expand Down Expand Up @@ -290,6 +292,7 @@ include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})

add_library(MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src/microtar.c")
set_property(TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON)

target_no_warning(MICROTAR unused-variable)
target_no_warning(MICROTAR format)

Expand Down
4 changes: 3 additions & 1 deletion cmake/warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ add_warning(init-self)
add_warning(bool-compare)
add_warning(logical-not-parentheses)
add_warning(logical-op)
add_warning(maybe-uninitialized)
add_warning(misleading-indentation)
# `no-` prefix is part of warning name(i.e. doesn't mean we are disabling it)
add_warning(no-return-local-addr)
Expand All @@ -84,3 +83,6 @@ no_warning(comma-subscript)
no_warning(ambiguous-reversed-operator)
no_warning(restrict)
no_warning(free-nonheap-object)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
no_warning(stringop-overflow)
endif()
2 changes: 1 addition & 1 deletion docker/Dockerfile-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
case ${DOCKER_TAG} in *"-debug"*) BUILD_TYPE="Debug";; esac && \
case ${DOCKER_TAG} in *"-assertions"*) BUILD_TYPE="RelWithDebInfo" && ENABLE_ASSERTIONS="On" && BUILD_TOOLS="On";; esac && \
echo "Building ${BUILD_TYPE} with ENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} BUILD_TOOLS=${BUILD_TOOLS}" && \
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=On && \
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=OFF && \
make -j${NPROC} install && \
cd ../profiles && \
cp -r * /opt && \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-debian
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPY . /src
WORKDIR /src

RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized" && \
export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized -Wno-stringop-overflow" && \
echo "Building OSRM ${DOCKER_TAG}" && \
git show --format="%H" | head -n1 > /opt/OSRM_GITSHA && \
echo "Building OSRM gitsha $(cat /opt/OSRM_GITSHA)" && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/windows-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SET test_region_ch=ch\monaco
SET test_region_corech=corech\monaco
SET test_region_mld=mld\monaco
SET test_osm=%test_region%.osm.pbf
COPY %PROJECT_DIR%\test\data\%test_region%.osm.pbf %test_osm%
COPY %PROJECT_DIR%\test\data\%test_region%.osm.pbf %test_osm%
%CONFIGURATION%\osrm-extract.exe -p %PROJECT_DIR%\profiles\car.lua %test_osm%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR

Expand Down
4 changes: 0 additions & 4 deletions src/extractor/extractor_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include <vector>

#ifdef _MSC_VER
#if (_MSC_VER >= 1928)
#ifdef _DEBUG
namespace osrm
{
namespace extractor
Expand All @@ -37,8 +35,6 @@ const ByEdgeOrByMeterValue::ValueByMeter ByEdgeOrByMeterValue::by_meter;
} // namespace extractor
} // namespace osrm
#endif
#endif
#endif

namespace osrm::extractor
{
Expand Down

0 comments on commit d0ed29a

Please sign in to comment.