Skip to content

Commit d0ed29a

Browse files
Use Link Time Optimisation whenever possible (#6967)
1 parent bdc6ed8 commit d0ed29a

File tree

8 files changed

+30
-20
lines changed

8 files changed

+30
-20
lines changed

.github/workflows/osrm-backend.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ jobs:
200200
CCOMPILER: clang-15
201201
CXXCOMPILER: clang++-15
202202
CUCUMBER_TIMEOUT: 60000
203+
ENABLE_LTO: OFF
203204

204205
- name: clang-15-debug
205206
continue-on-error: false
@@ -210,6 +211,7 @@ jobs:
210211
CCOMPILER: clang-15
211212
CXXCOMPILER: clang++-15
212213
CUCUMBER_TIMEOUT: 60000
214+
ENABLE_LTO: OFF
213215

214216
- name: clang-18-debug-clang-tidy
215217
continue-on-error: false
@@ -232,6 +234,7 @@ jobs:
232234
CCOMPILER: clang-14
233235
CXXCOMPILER: clang++-14
234236
CUCUMBER_TIMEOUT: 60000
237+
ENABLE_LTO: OFF
235238

236239
- name: clang-13-release
237240
continue-on-error: false
@@ -242,6 +245,7 @@ jobs:
242245
CCOMPILER: clang-13
243246
CXXCOMPILER: clang++-13
244247
CUCUMBER_TIMEOUT: 60000
248+
ENABLE_LTO: OFF
245249

246250
- name: conan-linux-debug-asan-ubsan
247251
continue-on-error: false
@@ -253,6 +257,7 @@ jobs:
253257
CXXCOMPILER: clang++-15
254258
ENABLE_CONAN: ON
255259
ENABLE_SANITIZER: ON
260+
ENABLE_LTO: OFF
256261

257262
- name: conan-linux-release
258263
continue-on-error: false
@@ -263,6 +268,7 @@ jobs:
263268
CCOMPILER: clang-15
264269
CXXCOMPILER: clang++-15
265270
ENABLE_CONAN: ON
271+
ENABLE_LTO: OFF
266272

267273
- name: gcc-14-release
268274
continue-on-error: false
@@ -361,6 +367,7 @@ jobs:
361367
TARGET_ARCH: ${{ matrix.TARGET_ARCH }}
362368
OSRM_CONNECTION_RETRIES: ${{ matrix.OSRM_CONNECTION_RETRIES }}
363369
OSRM_CONNECTION_EXP_BACKOFF_COEF: ${{ matrix.OSRM_CONNECTION_EXP_BACKOFF_COEF }}
370+
ENABLE_LTO: ${{ matrix.ENABLE_LTO }}
364371
steps:
365372
- uses: actions/checkout@v4
366373
- name: Build machine architecture
@@ -521,6 +528,7 @@ jobs:
521528
-DENABLE_SANITIZER=${ENABLE_SANITIZER:-OFF} \
522529
-DBUILD_TOOLS=${BUILD_TOOLS:-OFF} \
523530
-DENABLE_CCACHE=ON \
531+
-DENABLE_LTO=${ENABLE_LTO:-ON} \
524532
-DCMAKE_INSTALL_PREFIX=${OSRM_INSTALL_DIR}
525533
make --jobs=${JOBS}
526534

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- NodeJS:
2525
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
2626
- Misc:
27+
- CHANGED: Use Link Time Optimisation whenever possible. [#6967](https://github.com/Project-OSRM/osrm-backend/pull/6967)
2728
- CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](https://github.com/Project-OSRM/osrm-backend/pull/6974)
2829
- CHANGED: Micro performance optimisation in map matching. [#6976](https://github.com/Project-OSRM/osrm-backend/pull/6976)
2930
- CHANGED: Re-use priority queue in StaticRTree. [#6952](https://github.com/Project-OSRM/osrm-backend/pull/6952)

CMakeLists.txt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ option(ENABLE_ASSERTIONS "Use assertions in release mode" OFF)
3131
option(ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF)
3232
option(ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF)
3333
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)
34-
option(ENABLE_LTO "Use LTO if available" OFF)
34+
option(ENABLE_LTO "Use Link Time Optimisation" ON)
3535
option(ENABLE_FUZZING "Fuzz testing using LLVM's libFuzzer" OFF)
3636
option(ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF)
3737
option(ENABLE_CLANG_TIDY "Enables clang-tidy checks" OFF)
3838

39+
3940
if (ENABLE_CLANG_TIDY)
4041
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
4142
if(NOT CLANG_TIDY_COMMAND)
@@ -57,6 +58,18 @@ if (POLICY CMP0074)
5758
endif()
5859
project(OSRM C CXX)
5960

61+
62+
if(ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
63+
include(CheckIPOSupported)
64+
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
65+
if(LTO_SUPPORTED)
66+
message(STATUS "IPO / LTO enabled")
67+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
68+
else()
69+
message(FATAL_ERROR "IPO / LTO not supported: <${error}>")
70+
endif()
71+
endif()
72+
6073
# add @loader_path/$ORIGIN to rpath to make binaries relocatable
6174
if (APPLE)
6275
set(CMAKE_BUILD_RPATH "@loader_path")
@@ -208,17 +221,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
208221
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb")
209222
endif()
210223

211-
if(ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
212-
include(CheckIPOSupported)
213-
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
214-
if(LTO_SUPPORTED)
215-
message(STATUS "IPO / LTO enabled")
216-
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
217-
else()
218-
message(WARNING "IPO / LTO not supported: <${error}>")
219-
endif()
220-
endif()
221-
222224
set(MAYBE_COVERAGE_LIBRARIES "")
223225
if (ENABLE_COVERAGE)
224226
if (NOT CMAKE_BUILD_TYPE MATCHES "Debug")
@@ -290,6 +292,7 @@ include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})
290292

291293
add_library(MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src/microtar.c")
292294
set_property(TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON)
295+
293296
target_no_warning(MICROTAR unused-variable)
294297
target_no_warning(MICROTAR format)
295298

cmake/warnings.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ add_warning(init-self)
6464
add_warning(bool-compare)
6565
add_warning(logical-not-parentheses)
6666
add_warning(logical-op)
67-
add_warning(maybe-uninitialized)
6867
add_warning(misleading-indentation)
6968
# `no-` prefix is part of warning name(i.e. doesn't mean we are disabling it)
7069
add_warning(no-return-local-addr)
@@ -84,3 +83,6 @@ no_warning(comma-subscript)
8483
no_warning(ambiguous-reversed-operator)
8584
no_warning(restrict)
8685
no_warning(free-nonheap-object)
86+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
87+
no_warning(stringop-overflow)
88+
endif()

docker/Dockerfile-alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
3131
case ${DOCKER_TAG} in *"-debug"*) BUILD_TYPE="Debug";; esac && \
3232
case ${DOCKER_TAG} in *"-assertions"*) BUILD_TYPE="RelWithDebInfo" && ENABLE_ASSERTIONS="On" && BUILD_TOOLS="On";; esac && \
3333
echo "Building ${BUILD_TYPE} with ENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} BUILD_TOOLS=${BUILD_TOOLS}" && \
34-
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=On && \
34+
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=OFF && \
3535
make -j${NPROC} install && \
3636
cd ../profiles && \
3737
cp -r * /opt && \

docker/Dockerfile-debian

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ COPY . /src
2121
WORKDIR /src
2222

2323
RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
24-
export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized" && \
24+
export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized -Wno-stringop-overflow" && \
2525
echo "Building OSRM ${DOCKER_TAG}" && \
2626
git show --format="%H" | head -n1 > /opt/OSRM_GITSHA && \
2727
echo "Building OSRM gitsha $(cat /opt/OSRM_GITSHA)" && \

scripts/ci/windows-build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SET test_region_ch=ch\monaco
6262
SET test_region_corech=corech\monaco
6363
SET test_region_mld=mld\monaco
6464
SET test_osm=%test_region%.osm.pbf
65-
COPY %PROJECT_DIR%\test\data\%test_region%.osm.pbf %test_osm%
65+
COPY %PROJECT_DIR%\test\data\%test_region%.osm.pbf %test_osm%
6666
%CONFIGURATION%\osrm-extract.exe -p %PROJECT_DIR%\profiles\car.lua %test_osm%
6767
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
6868

src/extractor/extractor_callbacks.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <vector>
2424

2525
#ifdef _MSC_VER
26-
#if (_MSC_VER >= 1928)
27-
#ifdef _DEBUG
2826
namespace osrm
2927
{
3028
namespace extractor
@@ -37,8 +35,6 @@ const ByEdgeOrByMeterValue::ValueByMeter ByEdgeOrByMeterValue::by_meter;
3735
} // namespace extractor
3836
} // namespace osrm
3937
#endif
40-
#endif
41-
#endif
4238

4339
namespace osrm::extractor
4440
{

0 commit comments

Comments
 (0)