Skip to content
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

Use LTO for linux as well #103058

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
16 changes: 12 additions & 4 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLinkerFlag)
include(CheckIPOSupported)

# "configureoptimization.cmake" must be included after CLR_CMAKE_HOST_UNIX has been set.
include(${CMAKE_CURRENT_LIST_DIR}/configureoptimization.cmake)
Expand Down Expand Up @@ -152,6 +153,17 @@ elseif (CLR_CMAKE_HOST_UNIX)
endif()
endif(MSVC)

check_ipo_supported(RESULT result OUTPUT output)
if(result AND NOT CLR_CMAKE_TARGET_APPLE)
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment about why IPO is disabled on apple platforms?

# Apple does not properly support IPO and need more involved
# way on how to support this. For now, disable it for Apple.
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_CHECKED OFF)
else()
message(WARNING "IPO is not supported")
endif()

if (CLR_CMAKE_ENABLE_SANITIZERS)
set (CLR_CMAKE_BUILD_SANITIZERS "")
set (CLR_CMAKE_SANITIZER_RUNTIMES "")
Expand Down Expand Up @@ -889,10 +901,6 @@ if (MSVC)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gz>)
endif (CLR_CMAKE_HOST_ARCH_I386)

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_CHECKED OFF)

if (CLR_CMAKE_HOST_ARCH_AMD64)
# The generator expression in the following command means that the /homeparams option is added only for debug builds for C and C++ source files
add_compile_options($<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C,CXX>>:/homeparams>) # Force parameters passed in registers to be written to the stack
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/runtimeinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ else()
target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR})
target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR}/${ARCH_SOURCES_DIR})
target_include_directories(cdac_data_descriptor PRIVATE ${CLR_DIR}/interop/inc)
# LTO not supported for cdac, so disable it
set_target_properties(cdac_data_descriptor PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment about why we're disabling IPO here?


set(GENERATED_CDAC_DESCRIPTOR_DIR "${CMAKE_CURRENT_BINARY_DIR}/cdac")
set(CONTRACT_DESCRIPTOR_OUTPUT "${GENERATED_CDAC_DESCRIPTOR_DIR}/contract-descriptor.c")
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ if(MSVC)
set_property(DIRECTORY PROPERTY CLR_EH_OPTION /EHa-s-) # Native AOT runtime does not use C++ exception handling
set_property(DIRECTORY PROPERTY CLR_CONTROL_FLOW_GUARD OFF)

# The code generated by the Native AOT compiler doesn't work with Link Time Code Generation
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)

# Sets the options that create the fastest code in the majority of cases
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:C,CXX>,$<CONFIG:Release>>:/O2>)
endif (MSVC)

# The code generated by the Native AOT compiler doesn't work with Link Time Code Generation
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)

if(CLR_CMAKE_HOST_UNIX)
add_compile_options(-fno-exceptions) # Native AOT runtime doesn't use C++ exception handling
add_compile_options(-fno-asynchronous-unwind-tables)
Expand Down
Loading