diff --git a/Docs/sphinx_documentation/source/BuildingAMReX.rst b/Docs/sphinx_documentation/source/BuildingAMReX.rst index 0f3787bd85a..3176730320e 100644 --- a/Docs/sphinx_documentation/source/BuildingAMReX.rst +++ b/Docs/sphinx_documentation/source/BuildingAMReX.rst @@ -535,6 +535,12 @@ The list of available options is reported in the :ref:`table ` bel | AMReX_FLATTEN_FOR | Enable flattening of ParallelFor and similar | NO | YES, NO | | | functions for host code | | | +------------------------------+-------------------------------------------------+-------------------------+-----------------------+ + | AMReX_COMPILER_DEFAULT_INLINE| Use default inline behavior of compiler, | NO for GCC | YES, NO | + | | so far relevant for GCC Only | YES otherwise | | + +------------------------------+-------------------------------------------------+-------------------------+-----------------------+ + | AMReX_INLINE_LIMIT | Inline limit. Relevant only when | 43210 | Non-negative number | + | | AMReX_COMPILER_DEFAULT_INLINE is NO. | | | + +------------------------------+-------------------------------------------------+-------------------------+-----------------------+ .. raw:: latex \end{center} diff --git a/Src/CMakeLists.txt b/Src/CMakeLists.txt index febdea04b5b..56cd426efb9 100644 --- a/Src/CMakeLists.txt +++ b/Src/CMakeLists.txt @@ -86,6 +86,14 @@ foreach(D IN LISTS AMReX_SPACEDIM) $ ) endif () + + if (NOT AMReX_COMPILER_DEFULT_INLINE) + target_link_libraries(amrex_${D}d + PUBLIC + $ + ) + endif () + endforeach() # General configuration diff --git a/Tools/CMake/AMReXClangTidy.cmake b/Tools/CMake/AMReXClangTidy.cmake index 65d84442424..96c67622a21 100644 --- a/Tools/CMake/AMReXClangTidy.cmake +++ b/Tools/CMake/AMReXClangTidy.cmake @@ -17,7 +17,7 @@ macro(setup_clang_tidy) # Need --extra-arg to suppress warnings like clang-diagnostic-unknown-warning-option # when GCC is used. - set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_EXE};--extra-arg=-Wno-unknown-warning-option") + set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_EXE};--extra-arg=-Wno-unknown-warning-option;--extra-arg=-Wno-ignored-optimization-argument") if (AMReX_CLANG_TIDY_CONFIG_FILE_NAME) set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_COMMAND}" "--config-file=${AMReX_CLANG_TIDY_CONFIG_FILE_NAME}") diff --git a/Tools/CMake/AMReXConfig.cmake.in b/Tools/CMake/AMReXConfig.cmake.in index 6ee60df4990..c8714daf223 100644 --- a/Tools/CMake/AMReXConfig.cmake.in +++ b/Tools/CMake/AMReXConfig.cmake.in @@ -91,6 +91,8 @@ set(AMReX_FPE_FOUND @AMReX_FPE@) set(AMReX_PIC_FOUND @AMReX_PIC@) set(AMReX_ASSERTIONS_FOUND @AMReX_ASSERTIONS@) set(AMReX_FLATTEN_FOR_FOUND @AMReX_FLATTEN_FOR@) +set(AMReX_COMPILER_DEFAULT_INLINE_FOUND @AMReX_COMPILER_DEFAULT_INLINE@) +set(AMReX_INLINE_LIMIT_FOUND @AMReX_INLINE_LIMIT@) # Profiling options set(AMReX_BASEP_FOUND @AMReX_BASE_PROFILE@) diff --git a/Tools/CMake/AMReXFlagsTargets.cmake b/Tools/CMake/AMReXFlagsTargets.cmake index a2e86b2fbd3..a5c00a10274 100644 --- a/Tools/CMake/AMReXFlagsTargets.cmake +++ b/Tools/CMake/AMReXFlagsTargets.cmake @@ -5,6 +5,7 @@ # Flags_CXX --> Optional flags for C++ code # Flags_Fortran --> Optional flags for Fortran code # Flags_FPE --> Floating-Point Exception flags for both C++ and Fortran +# Flags_INLINE --> Optional flags for inlining # # These INTERFACE targets can be added to the AMReX export set. # @@ -93,6 +94,17 @@ target_compile_options( Flags_CXX $<${_cxx_intelllvm_rel}:> ) +add_library(Flags_INLINE INTERFACE) +add_library(AMReX::Flags_INLINE ALIAS Flags_INLINE) + +if (NOT AMReX_COMPILER_DEFAULT_INLINE) + target_compile_options( Flags_INLINE + INTERFACE + $<${_cxx_gnu_rwdbg}:-finline-limit=${AMReX_INLINE_LIMIT}> + $<${_cxx_gnu_rel}:-finline-limit=${AMReX_INLINE_LIMIT}> + ) +endif () + # # Fortran flags # diff --git a/Tools/CMake/AMReXOptions.cmake b/Tools/CMake/AMReXOptions.cmake index 85c280f684f..c99c3a63791 100644 --- a/Tools/CMake/AMReXOptions.cmake +++ b/Tools/CMake/AMReXOptions.cmake @@ -369,6 +369,20 @@ print_option( AMReX_IPO ) option(AMReX_FPE "Enable Floating Point Exceptions checks" OFF) print_option( AMReX_FPE ) +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + option(AMReX_COMPILER_DEFAULT_INLINE "Use compiler default inline behavior" OFF) + set(AMReX_INLINE_LIMIT 43210 CACHE STRING "Inline limit") + if (NOT AMReX_COMPILER_DEFAULT_INLINE) + if (AMReX_INLINE_LIMIT LESS 0) + message(FATAL_ERROR "AMReX_INLINE_LIMIT, if set, must be non-negative") + endif() + message(STATUS " AMReX_INLINE_LIMIT = ${AMReX_INLINE_LIMIT}") + endif () +else () + set(AMReX_COMPILER_DEFAULT_INLINE ON) +endif () + + if ( "${CMAKE_BUILD_TYPE}" MATCHES "Debug" ) option( AMReX_ASSERTIONS "Enable assertions" ON) else () diff --git a/Tools/C_scripts/mmclt.py b/Tools/C_scripts/mmclt.py index 0ddcc0f0c6e..747ebe45219 100755 --- a/Tools/C_scripts/mmclt.py +++ b/Tools/C_scripts/mmclt.py @@ -28,7 +28,7 @@ def mmclt(argv): fout = open(args.output, "w") fout.write("CLANG_TIDY ?= clang-tidy\n") - fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n") + fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg=-Wno-ignored-optimization-argument --extra-arg-before=--driver-mode=g++\n") fout.write("\n") fout.write(".SECONDEXPANSION:\n") diff --git a/Tools/GNUMake/comps/gnu.mak b/Tools/GNUMake/comps/gnu.mak index ca9a7ea9d84..9e8430ec88d 100644 --- a/Tools/GNUMake/comps/gnu.mak +++ b/Tools/GNUMake/comps/gnu.mak @@ -44,6 +44,8 @@ gcc_major_ge_10 = $(shell expr $(gcc_major_version) \>= 10) gcc_major_ge_11 = $(shell expr $(gcc_major_version) \>= 11) gcc_major_ge_12 = $(shell expr $(gcc_major_version) \>= 12) +INLINE_LIMIT ?= 43210 + ifneq ($(NO_CONFIG_CHECKING),TRUE) ifneq ($(gcc_major_ge_8),1) $(error GCC < 8 not supported) @@ -96,6 +98,9 @@ else CXXFLAGS += -g -O3 CFLAGS += -g -O3 endif + ifneq ($(USE_COMPILER_DEFAULT_INLINE),TRUE) + CXXFLAGS += -finline-limit=$(INLINE_LIMIT) + endif endif ifeq ($(WARN_ALL),TRUE) diff --git a/Tools/GNUMake/tools/Make.clang-tidy b/Tools/GNUMake/tools/Make.clang-tidy index a1b61b564cc..2a7c91dabfe 100644 --- a/Tools/GNUMake/tools/Make.clang-tidy +++ b/Tools/GNUMake/tools/Make.clang-tidy @@ -1,6 +1,6 @@ CLANG_TIDY = clang-tidy -CLANG_TIDY_ARGS = --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++ +CLANG_TIDY_ARGS = --extra-arg=-Wno-unknown-warning-option --extra-arg=-Wno-ignored-optimization-argument --extra-arg-before=--driver-mode=g++ # space-separated list of paths to skip, matched against the absolute path of each source file CLANG_TIDY_IGNORE_SOURCES ?=