-
Notifications
You must be signed in to change notification settings - Fork 275
Enable IPO / LTO and -O3 #6011
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 IPO / LTO and -O3 #6011
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR | |
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" | ||
) | ||
# Ensure NDEBUG is not set for release builds | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O2") | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | ||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") | ||
# Enable lots of warnings | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-deprecated-declarations -Wswitch-enum") | ||
|
@@ -180,6 +180,10 @@ function(cprover_default_properties) | |
CXX_STANDARD ${CBMC_CXX_STANDARD} | ||
CXX_STANDARD_REQUIRED ${CBMC_CXX_STANDARD_REQUIRED} | ||
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY}) | ||
|
||
if(ipo_supported) | ||
set_property(TARGET ${ARGN} PROPERTY INTERPROCEDURAL_OPTIMIZATION True) | ||
endif() | ||
endfunction() | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL Linux) | ||
|
@@ -191,6 +195,36 @@ endif() | |
option(WITH_MEMORY_ANALYZER | ||
"build the memory analyzer" ${WITH_MEMORY_ANALYZER_DEFAULT}) | ||
|
||
if((CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION GREATER_EQUAL 9) | ||
AND (CMAKE_BUILD_TYPE STREQUAL "Release")) | ||
cmake_policy(SET CMP0069 NEW) | ||
include(CheckIPOSupported) | ||
check_ipo_supported(RESULT ipo_supported OUTPUT error LANGUAGES CXX) | ||
endif() | ||
|
||
if(ipo_supported) | ||
message(STATUS "IPO / LTO enabled") | ||
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION True) | ||
add_definitions(-DLTO) | ||
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") | ||
OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "i386") | ||
OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "i586") | ||
OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "i686") | ||
OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") # freebsd | ||
OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # windows | ||
OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")) | ||
set(PROCESSOR_FAMILY "Intel") | ||
if(CMAKE_COMPILER_IS_GNUCC | ||
OR (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang) | ||
OR (CMAKE_CXX_COMPILER_ID STREQUAL Clang) | ||
OR (CMAKE_CXX_COMPILER_ID STREQUAL Intel)) | ||
add_definitions(-march=native) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit nervous of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Packagers need to get rid of that somehow. Maybe only add it to CFLAGS and CXXFLAGS via env. The idea was to find sloppy visibility and alignment, and test it in develop. Also have locally fast binaries |
||
endif() | ||
endif() | ||
else() | ||
message(STATUS "IPO / LTO not supported: <${error}>") | ||
endif() | ||
|
||
add_subdirectory(src) | ||
add_subdirectory(regression) | ||
add_subdirectory(unit) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake noob here: could we use
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DLTO")
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this is easier. It only adds it to the Release flags anyway, because only there ipo_supported will be true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, but then I wasn't able to find a way to surface this to the CaDiCaL build configuration. You might know how to make this work?