-
Notifications
You must be signed in to change notification settings - Fork 772
Enabled LTO (Link Time Optimization) #9254
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
Changes from 4 commits
5eb09bb
88b5631
9b43179
767dbf0
a226472
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 |
|---|---|---|
|
|
@@ -108,6 +108,56 @@ message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}") | |
| message(STATUS "C++ Standard Required: ${CMAKE_CXX_STANDARD_REQUIRED}") | ||
| message(STATUS "C++ Extensions: ${CMAKE_CXX_EXTENSIONS}") | ||
|
|
||
| # Detect OS distribution and version from /etc/os-release | ||
| # LTO is known to cause build errors on Debian 11 and Rocky Linux 8 | ||
| set(LTO_UNSUPPORTED_OS FALSE) | ||
| if(EXISTS "/etc/os-release") | ||
| file(STRINGS "/etc/os-release" OS_RELEASE_CONTENTS) | ||
| set(OS_ID "") | ||
| set(OS_VERSION_ID "") | ||
| foreach(line ${OS_RELEASE_CONTENTS}) | ||
| if(line MATCHES "^ID=(.*)$") | ||
| string(REGEX REPLACE "^ID=\"?([^\"]*)\"?$" "\\1" OS_ID "${line}") | ||
| endif() | ||
| if(line MATCHES "^VERSION_ID=(.*)$") | ||
| string(REGEX REPLACE "^VERSION_ID=\"?([^\"]*)\"?$" "\\1" OS_VERSION_ID "${line}") | ||
| endif() | ||
| endforeach() | ||
|
|
||
| # Check for Debian 11 (Bullseye) | ||
| if(OS_ID STREQUAL "debian" AND OS_VERSION_ID STREQUAL "11") | ||
| set(LTO_UNSUPPORTED_OS TRUE) | ||
| message(STATUS "Detected Debian 11: LTO will be disabled due to known build issues") | ||
| endif() | ||
|
|
||
| # Check for Rocky Linux 8 | ||
| if(OS_ID STREQUAL "rocky" AND OS_VERSION_ID MATCHES "^8") | ||
| set(LTO_UNSUPPORTED_OS TRUE) | ||
| message(STATUS "Detected Rocky Linux 8: LTO will be disabled due to known build issues") | ||
| endif() | ||
| endif() | ||
|
|
||
| option(LINK_TIME_OPTIMIZATION "Flag to control link time optimization: on by default" ON) | ||
| set(LTO_STATUS "disabled") | ||
| if (LINK_TIME_OPTIMIZATION AND NOT LTO_UNSUPPORTED_OS) | ||
| include(CheckIPOSupported) | ||
| check_ipo_supported(RESULT lto_supported OUTPUT lto_error) | ||
| if(lto_supported) | ||
| # LTO is enabled globally for Release build | ||
| set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) | ||
| set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO FALSE) | ||
| set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE) | ||
|
|
||
| string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE) | ||
| if(UPPER_BUILD_TYPE STREQUAL "RELEASE") | ||
| set(LTO_STATUS "enabled") | ||
| endif() | ||
|
Comment on lines
+147
to
+149
Contributor
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. The status message for LTO can be misleading. When the build type is not |
||
| else() | ||
| set(LTO_STATUS "not supported: ${lto_error}") | ||
| endif() | ||
| endif() | ||
| message(STATUS "LTO/IPO is ${LTO_STATUS}") | ||
|
|
||
| # configure a header file to pass some of the CMake settings | ||
| configure_file( | ||
| ${OPENROAD_HOME}/include/ord/Version.hh.cmake | ||
|
|
||
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.
The separate checks for different unsupported operating systems can be combined into a single
ifstatement usingOR. This would make the code more concise and easier to extend with more unsupported OS versions in the future. The status message can also be made more generic to report which OS was detected.