Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ build --cxxopt "-std=c++20" --host_cxxopt "-std=c++20"
build --cxxopt "-xc++" --host_cxxopt "-xc++"
build --cxxopt "-DBAZEL_BUILD" --host_cxxopt "-DBAZEL_BUILD"

# Default to optimized build (-c opt), O3
build -c opt
build:opt --copt=-O3

# Enable Full-LTO (Link Time Optimization)
build:opt --copt=-flto
build:opt --linkopt=-flto

# Needed for floating point stability in FFT (fft_test will check this).
# See also https://kristerw.github.io/2021/11/09/fp-contract/
build --cxxopt "-ffp-contract=off" --host_cxxopt "-ffp-contract=off"
Expand Down
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The separate checks for different unsupported operating systems can be combined into a single if statement using OR. 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.

  # Check for unsupported OS for LTO
  if((OS_ID STREQUAL "debian" AND OS_VERSION_ID STREQUAL "11") OR
     (OS_ID STREQUAL "rocky" AND OS_VERSION_ID MATCHES "^8"))
    set(LTO_UNSUPPORTED_OS TRUE)
    message(STATUS "Detected unsupported OS (${OS_ID} ${OS_VERSION_ID}): 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The status message for LTO can be misleading. When the build type is not RELEASE, it reports LTO as "disabled", which is true for the current build but doesn't convey that LTO is configured and will be used for RELEASE builds. This could cause confusion. It would be more informative to indicate that LTO is configured for Release builds even when the current build type is different.

    if(UPPER_BUILD_TYPE STREQUAL "RELEASE")
      set(LTO_STATUS "enabled")
    else()
      set(LTO_STATUS "configured for Release builds")
    endif()

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
Expand Down
8 changes: 8 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ if (Qt5_FOUND AND BUILD_GUI)
OpenSTA
)

# Disable LTO for gui. LTO causes a crash with Qt plugin loading
set_target_properties(gui PROPERTIES
INTERPROCEDURAL_OPTIMIZATION OFF
INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF
)
target_compile_options(gui PRIVATE "-fno-lto")
target_link_options(gui PRIVATE "-fno-lto")

messages(
TARGET gui
)
Expand Down