]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Enable the use of interprocedural/link-time optimization.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 18 Oct 2024 23:31:26 +0000 (17:31 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 6 Nov 2024 22:58:20 +0000 (15:58 -0700)
cmake/checks/check_02_compiler_features.cmake
cmake/macros/macro_populate_target_properties.cmake
cmake/setup_cached_variables.cmake
doc/users/cmake_dealii.html
source/CMakeLists.txt

index 59251dca98662192ef0619b6a8ed8da1b2beaad6..cab88ab5bb46dca138095fd91e459eb51eea3e48 100644 (file)
@@ -407,3 +407,25 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
 
   reset_cmake_required()
 endif()
+
+
+#
+# Check whether the compiler supports interprocedural and link-time
+# optimization. If so, we can set the corresponding property on the
+# compile and link targets later on.
+#
+if(DEAL_II_USE_LTO)
+  include(CheckIPOSupported)
+  check_ipo_supported(RESULT _res OUTPUT _out LANGUAGES CXX)
+  if (_res)
+    message(STATUS "Compiler supports interprocedural/link-time optimizations")
+    set(DEAL_II_USE_LTO "YES")
+  else()
+    message(FATAL_ERROR "You asked for interprocedural/link-time optimizations, but the compiler does not support these optimizations: ${_out}")
+    set(DEAL_II_USE_LTO "NO")
+  endif()
+else()
+  # User did not set DEAL_II_USE_LTO on the command line. Set the
+  # variable to a specific (negative) value.
+  set(DEAL_II_USE_LTO "NO")
+endif()
index b85a803ccddb84fade9017f907d168caa1b82a5b..7223089c5b8855d7aabcaa0404967a304d7dae26 100644 (file)
@@ -15,7 +15,7 @@
 #
 # populate_target_properties(<target> <build>)
 #
-# This function populate target properties according to (globally) defined
+# This function populates target properties according to (globally) defined
 # DEAL_II_* variables. Specifically:
 #
 #   DEAL_II_LIBRARIES DEAL_II_LIBRARIES_<build>
@@ -126,4 +126,13 @@ function(populate_target_properties _target _build)
     ${DEAL_II_LIBRARIES} ${DEAL_II_LIBRARIES_${_build}}
     ${DEAL_II_TARGETS} ${DEAL_II_TARGETS_${_build}}
     )
+
+
+   # For release builds (and their corresponding object files),
+   # use interprocedural optimizations if possible
+   if (DEAL_II_USE_LTO AND ("${_build}" STREQUAL "RELEASE"))
+     set_property(TARGET ${_target}
+                  PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
+   endif()
+
 endfunction()
index b3fc8b9e5dbc266ed7309a9904c09f0500804884..eb2d5957bf50062d63cb0b86eb518911ff4daadb 100644 (file)
@@ -31,6 +31,7 @@
 #
 #     CMAKE_BUILD_TYPE
 #     DEAL_II_ALLOW_PLATFORM_INTROSPECTION
+#     DEAL_II_USE_LTO
 #     DEAL_II_SETUP_COVERAGE
 #     DEAL_II_UNITY_BUILD
 #     DEAL_II_EARLY_DEPRECATIONS
@@ -159,6 +160,12 @@ option(DEAL_II_ALLOW_PLATFORM_INTROSPECTION
   )
 mark_as_advanced(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
 
+option(DEAL_II_USE_LTO
+  "Allow the compiler to use interprocedural and link-time optimization (LTO)."
+  OFF
+  )
+mark_as_advanced(DEAL_II_USE_LTO)
+
 option(DEAL_II_SETUP_COVERAGE
   "Setup debug compiler flags to provide additional test coverage information. Currently only gprof is supported."
   OFF
index ddc2f12b8ee2091fca0556dc9817c9d97bdc0069..26305f34ddadafe42dd72887578297dbd25925c6 100644 (file)
@@ -781,6 +781,14 @@ cmake -DLAPACK_FOUND=true \
           (default), <acronym>deal.II</acronym> will perform platform
           introspection for the given CPU.
 
+        <li>
+          <code>DEAL_II_USE_LTO</code>: If set to "ON" (the default is
+          "OFF"), allow the compiler to use interprocedural and
+          link-time optimization for release builds. These
+          optimizations often substantially improve performance, but
+          take both a substantial amount of memory and CPU time when
+          compiling the library.
+
         <li>
           <code>BUILD_SHARED_LIBS</code>: If set (default),
           <acronym>deal.II</acronym> will be linked as a shared library
index 5d4f55ba06326fc57df8a2e5c9630ed5d298d0ab..502e7e921df1d4b39aa782a044facc32c6ac1491 100644 (file)
@@ -94,6 +94,7 @@ foreach(build ${DEAL_II_BUILD_TYPES})
     set(build_camelcase "Release")
   endif()
 
+
   #
   # Combine all ${build} OBJECT targets to a ${build} library:
   #

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.