Skip to content

Commit 308fda4

Browse files
committed
Enable IPO / LTO and -O3
LTO and -O3 give a good performance improvement. I would not recommend -O3 with bad compiler versions though, such as gcc-9. WIP: GLOBAL properties are not enough, add the IPO property to all targets. Which leads to various problems still. See the next commit to fix yyalloc name collisions.
1 parent e11c079 commit 308fda4

File tree

9 files changed

+65
-4
lines changed

9 files changed

+65
-4
lines changed

CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
7373

7474
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
7575
# Ensure NDEBUG is not set for release builds
76-
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
76+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
7777
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
7878
# Enable lots of warnings
7979
set(CMAKE_CXX_FLAGS
@@ -214,6 +214,10 @@ function(cprover_default_properties)
214214
CXX_STANDARD ${CBMC_CXX_STANDARD}
215215
CXX_STANDARD_REQUIRED ${CBMC_CXX_STANDARD_REQUIRED}
216216
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY})
217+
218+
if(ipo_supported)
219+
set_property(TARGET ${ARGN} PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
220+
endif()
217221
endfunction()
218222

219223
if(CMAKE_SYSTEM_NAME STREQUAL Linux AND
@@ -227,6 +231,22 @@ endif()
227231
option(WITH_MEMORY_ANALYZER
228232
"build the memory analyzer" ${WITH_MEMORY_ANALYZER_DEFAULT})
229233

234+
# Our requirement is 3.8
235+
if((CMAKE_MAJOR_VERSION GREATER_EQUAL 4 OR CMAKE_MINOR_VERSION GREATER_EQUAL 9)
236+
AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
237+
cmake_policy(SET CMP0069 NEW)
238+
include(CheckIPOSupported)
239+
check_ipo_supported(RESULT ipo_supported OUTPUT error LANGUAGES CXX)
240+
endif()
241+
242+
if(ipo_supported)
243+
message(STATUS "IPO / LTO enabled")
244+
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
245+
add_definitions(-DLTO)
246+
else()
247+
message(STATUS "IPO / LTO not supported: <${error}>")
248+
endif()
249+
230250
add_subdirectory(src)
231251
add_subdirectory(regression)
232252
add_subdirectory(unit)

regression/invariants/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
add_executable(driver driver.cpp)
22
target_link_libraries(driver big-int util)
3+
if(ipo_supported)
4+
set_property(TARGET driver PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
5+
endif()
36

47
add_test_pl_tests(
58
"$<TARGET_FILE:driver>"

scripts/glucose_CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ set_target_properties(
1515
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Developer ID Application: Daniel Kroening"
1616
)
1717

18+
if(ipo_supported)
19+
set_property(TARGET glucose-condensed PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
20+
endif()
21+
1822
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
1923
target_compile_options(glucose-condensed PUBLIC /w)
2024
endif()

scripts/minisat2_CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ set_target_properties(
1616
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Developer ID Application: Daniel Kroening"
1717
)
1818

19+
if(ipo_supported)
20+
set_property(TARGET minisat2-condensed PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
21+
endif()
22+
1923
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
2024
target_compile_options(minisat2-condensed PUBLIC /w)
2125
endif()

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ macro(add_if_library target name)
8484
string(REGEX REPLACE "-" "_" define ${upper_name})
8585

8686
target_compile_definitions(${target} PUBLIC HAVE_${define})
87+
if(ipo_supported)
88+
set_property(TARGET ${name} PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
89+
endif()
90+
endif()
91+
if(ipo_supported)
92+
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
8793
endif()
8894
endmacro(add_if_library)
8995

src/ansi-c/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
1010
DEPENDS converter ${ansi_c_library_sources})
1111

1212
add_executable(file_converter file_converter.cpp)
13+
if(ipo_supported)
14+
set_property(TARGET converter PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
15+
set_property(TARGET file_converter PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
16+
endif()
1317

1418
function(make_inc name)
1519
get_filename_component(inc_path "${CMAKE_CURRENT_BINARY_DIR}/${name}.inc" DIRECTORY)
@@ -53,9 +57,10 @@ add_custom_command(
5357
)
5458

5559
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
60+
if(NOT ipo_supported)
5661
add_custom_target(c_library_check
57-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp
58-
)
62+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp)
63+
endif()
5964
endif()
6065

6166
################################################################################

src/config.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ ifeq ($(CPROVER_WITH_PROFILING),1)
1717
endif
1818

1919
# Select optimisation or debug info
20-
#CXXFLAGS += -O2 -DNDEBUG
20+
#CXXFLAGS += -O3 -DNDEBUG -flto -DLTO
2121
#CXXFLAGS += -O0 -g
2222

23+
# Matching -flto above
24+
#LINKFLAGS = -ftlo
25+
2326
# With GCC this adds function names in stack backtraces
2427
#LINKFLAGS = -rdynamic
2528

src/goto-symex/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ if(CMAKE_USE_CUDD)
88
endif()
99

1010
target_link_libraries(goto-symex util)
11+
12+
if(ipo_supported)
13+
set_property(TARGET goto-symex PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
14+
endif()

src/solvers/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ list(REMOVE_ITEM sources
5858
)
5959

6060
add_library(solvers ${sources})
61+
if(ipo_supported)
62+
set_property(TARGET solvers PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
63+
endif()
6164

6265
include("${CBMC_SOURCE_DIR}/cmake/DownloadProject.cmake")
6366

@@ -177,6 +180,9 @@ foreach(SOLVER ${sat_impl})
177180
)
178181

179182
add_library(cadical_ipasir STATIC IMPORTED)
183+
if(ipo_supported)
184+
set_property(TARGET cadical_ipasir PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
185+
endif()
180186
set_property(TARGET cadical_ipasir
181187
PROPERTY IMPORTED_LOCATION ${cadical_SOURCE_DIR}/build/libcadical.a
182188
)
@@ -222,6 +228,9 @@ foreach(SOLVER ${sat_impl})
222228
)
223229

224230
add_library(ipasir_custom STATIC IMPORTED)
231+
if(ipo_supported)
232+
set_property(TARGET cadical_custom PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
233+
endif()
225234
set_property(TARGET ipasir_custom
226235
PROPERTY IMPORTED_LOCATION ${IPASIR_LIB}
227236
)
@@ -247,5 +256,8 @@ endif()
247256
# Executable
248257
add_executable(smt2_solver smt2/smt2_solver.cpp)
249258
target_link_libraries(smt2_solver solvers)
259+
if(ipo_supported)
260+
set_property(TARGET smt2_solver PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
261+
endif()
250262

251263
generic_includes(solvers)

0 commit comments

Comments
 (0)