Skip to content

Commit 330b9cf

Browse files
committed
WIP 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.
1 parent ab404f6 commit 330b9cf

File tree

10 files changed

+61
-3
lines changed

10 files changed

+61
-3
lines changed

CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
5959
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
6060
)
6161
# Ensure NDEBUG is not set for release builds
62-
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
62+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
6363
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
6464
# Enable lots of warnings
6565
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-deprecated-declarations -Wswitch-enum")
@@ -180,6 +180,10 @@ function(cprover_default_properties)
180180
CXX_STANDARD ${CBMC_CXX_STANDARD}
181181
CXX_STANDARD_REQUIRED ${CBMC_CXX_STANDARD_REQUIRED}
182182
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY})
183+
184+
if(ipo_supported)
185+
set_property(TARGET ${ARGN} PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
186+
endif()
183187
endfunction()
184188

185189
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
@@ -191,6 +195,21 @@ endif()
191195
option(WITH_MEMORY_ANALYZER
192196
"build the memory analyzer" ${WITH_MEMORY_ANALYZER_DEFAULT})
193197

198+
if((CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION GREATER_EQUAL 9)
199+
AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
200+
cmake_policy(SET CMP0069 NEW)
201+
include(CheckIPOSupported)
202+
check_ipo_supported(RESULT ipo_supported OUTPUT error LANGUAGES CXX)
203+
endif()
204+
205+
if(ipo_supported)
206+
message(STATUS "IPO / LTO enabled")
207+
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
208+
add_definitions(-DLTO)
209+
else()
210+
message(STATUS "IPO / LTO not supported: <${error}>")
211+
endif()
212+
194213
add_subdirectory(src)
195214
add_subdirectory(regression)
196215
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
@@ -14,6 +14,10 @@ set_target_properties(
1414
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Developer ID Application: Daniel Kroening"
1515
)
1616

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

scripts/minisat2_CMakeLists.txt

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

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

src/CMakeLists.txt

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

9595
target_compile_definitions(${target} PUBLIC HAVE_${define})
96+
if(ipo_supported)
97+
set_property(TARGET ${name} PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
98+
endif()
99+
endif()
100+
if(ipo_supported)
101+
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
96102
endif()
97103
endmacro(add_if_library)
98104

src/ansi-c/CMakeLists.txt

Lines changed: 4 additions & 0 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
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.inc"

src/config.inc

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

1616
# Select optimisation or debug info
17-
#CXXFLAGS += -O2 -DNDEBUG
17+
#CXXFLAGS += -O3 -DNDEBUG -flto -DLTO
1818
#CXXFLAGS += -O0 -g
1919

20+
# Matching -flto above
21+
#LINKFLAGS = -ftlo
22+
2023
# With GCC this adds function names in stack backtraces
2124
#LINKFLAGS = -rdynamic
2225

src/goto-symex/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ 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()
15+

src/memory-analyzer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target_link_libraries(memory-analyzer-lib
1616

1717
# Executable
1818
add_executable(memory-analyzer memory_analyzer_main.cpp)
19+
1920
target_link_libraries(memory-analyzer memory-analyzer-lib)
2021

2122
cprover_default_properties(memory-analyzer memory-analyzer-lib)

src/solvers/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ list(REMOVE_ITEM sources
5454
)
5555

5656
add_library(solvers ${sources})
57+
if(ipo_supported)
58+
set_property(TARGET solvers PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
59+
endif()
5760

5861
include("${CBMC_SOURCE_DIR}/../cmake/DownloadProject.cmake")
5962

@@ -104,7 +107,7 @@ elseif("${sat_impl}" STREQUAL "cadical")
104107
download_project(PROJ cadical
105108
URL https://github.com/arminbiere/cadical/archive/rel-1.3.0.tar.gz
106109
PATCH_COMMAND true
107-
COMMAND CXX=${CMAKE_CXX_COMPILER} ./configure -O3 -s -j
110+
COMMAND CXX="${CMAKE_CXX_COMPILER}" CXXFLAGS="${CMAKE_CXX_FLAGS}" ./configure -O3 -s -j
108111
URL_MD5 5bd15d1e198d2e904a8af8b7873dd341
109112
)
110113

@@ -117,6 +120,9 @@ elseif("${sat_impl}" STREQUAL "cadical")
117120

118121
add_library(cadical STATIC IMPORTED)
119122

123+
if(ipo_supported)
124+
set_property(TARGET cadical PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
125+
endif()
120126
set_target_properties(
121127
cadical
122128
PROPERTIES IMPORTED_LOCATION ${cadical_SOURCE_DIR}/build/libcadical.a
@@ -143,5 +149,8 @@ endif()
143149
# Executable
144150
add_executable(smt2_solver smt2/smt2_solver.cpp)
145151
target_link_libraries(smt2_solver solvers)
152+
if(ipo_supported)
153+
set_property(TARGET smt2_solver PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
154+
endif()
146155

147156
generic_includes(solvers)

0 commit comments

Comments
 (0)