Renamed bonded module as 'listed-forces'
[alexxy/gromacs.git] / cmake / gmxGCC44O3BugWorkaround.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 # Due to a bug, gcc 4.4.x crashes when compiling listed-forces/bonded.cpp with -O3 and
36 # -fopenmp, but strangely it does not crash with -O2 + all additional options.
37 # -O3 uses. Therefore, for the affected files, when compiling in release mode,
38 # we override -O3 with -O2 and add the additional option.
39 #
40
41 # Considering compiler version and build configuration, check if the workaround
42 # is needed to avoid gcc crash.
43 macro(gmx_check_gcc44_bug_workaround_needed OUT_VAR)
44     if(CMAKE_COMPILER_IS_GNUCC AND
45     CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.3.999" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.4.999")
46
47         set(_gcc44_workaround FALSE)
48
49         # only apply the workaround if we are actually using -O3
50         string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
51         if ("${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}}" MATCHES ".*-O3.*" AND
52             GMX_OPENMP)
53             if(GMX_DISABLE_GCC44_BUG_WORKAROUND)
54                 set(_msg "gcc ${CMAKE_C_COMPILER_VERSION} detected, using -O3, but workaround for optimization bug is disabled")
55             else()
56                 set(_msg "gcc ${CMAKE_C_COMPILER_VERSION} detected, using -O3, will apply workaround for optimization bug (disable with GMX_DISABLE_GCC44_BUG_WORKAROUND)")
57                 set(_gcc44_workaround TRUE)
58             endif()
59             # only issues message if the value has changed
60             if((NOT _gcc44_workaround AND ${OUT_VAR}) OR (_gcc44_workaround AND NOT ${OUT_VAR}))
61                 message(STATUS "${_msg}")
62             endif()
63         endif()
64
65         set(${OUT_VAR} ${_gcc44_workaround} CACHE INTERNAL "Use gcc 4.4.x O3 optimization bug workaround" FORCE)
66     endif()
67 endmacro()
68
69 # Apply workaround on the specified source file.
70 #
71 # This workaround does not seem to affect the performance in a measurable way.
72 macro(gmx_apply_gcc44_bug_workaround FILE_NAME)
73     set_source_files_properties(
74         ${FILE_NAME}
75         PROPERTIES
76         COMPILE_FLAGS "-O2 -finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -fipa-cp-clone"
77         )
78 endmacro()