2015-01-30 16:49:14 +11:00
|
|
|
AC_DEFUN([NC_OPTIMISATION],[
|
|
|
|
##-------------------------------------------------------------------------
|
|
|
|
AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
|
|
|
|
AX_REQUIRE_DEFINED([AC_CANONICAL_HOST])
|
2015-02-04 15:59:22 +11:00
|
|
|
AX_REQUIRE_DEFINED([AX_COMPILER_VENDOR])
|
|
|
|
|
|
|
|
AX_COMPILER_VENDOR
|
2015-01-30 16:49:14 +11:00
|
|
|
|
|
|
|
##-------------------------------------------------------------------------
|
2015-03-18 17:14:58 +11:00
|
|
|
## Enable LTO
|
|
|
|
|
2015-01-30 16:49:14 +11:00
|
|
|
AC_ARG_ENABLE([lto], [
|
|
|
|
AS_HELP_STRING([--enable-lto], [enable link-time optimisation])
|
|
|
|
])
|
|
|
|
|
|
|
|
AS_IF([test "x$enable_lto" == "xyes"], [
|
2015-01-30 17:37:36 +11:00
|
|
|
AS_IF([test x"${host_os}" == x"mingw32"], [
|
2015-01-30 16:49:14 +11:00
|
|
|
AC_ERROR([mingw32 link-time optimisation is currently broken])
|
|
|
|
])
|
|
|
|
|
2015-02-04 15:59:22 +11:00
|
|
|
AS_IF([test "x$ax_cv_cxx_compiler_vendor" == "xgnu"], [
|
|
|
|
AC_CHECK_TOOLS([RANLIB], [gcc-ranlib ranlib])
|
|
|
|
AC_CHECK_TOOLS([AR], [gcc-ar ar])
|
|
|
|
AC_CHECK_TOOLS([NM], [gcc-nm nm])
|
|
|
|
])
|
|
|
|
|
2015-01-30 16:49:14 +11:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-flto], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fno-fat-lto-objects], [], [-Werror])
|
2015-04-29 17:42:52 +10:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-flto-odr-type-merging], [], [-Werror])
|
2015-01-30 16:49:14 +11:00
|
|
|
AX_APPEND_LINK_FLAGS([-fuse-linker-plugin], [], [-Werror])
|
2015-06-30 22:01:32 +10:00
|
|
|
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fdevirtualize-at-ltrans], [], [-Werror])
|
2015-01-30 16:49:14 +11:00
|
|
|
])
|
|
|
|
|
2015-10-12 19:20:29 +11:00
|
|
|
##-------------------------------------------------------------------------
|
|
|
|
## Enable frame pointer
|
|
|
|
|
|
|
|
AC_ARG_ENABLE([frame-pointer], [
|
|
|
|
AS_HELP_STRING([--enable-frame-pointer], [retain the frame pointer even if optimising])
|
|
|
|
])
|
|
|
|
|
|
|
|
AS_IF([test "x$enable_frame_pointer" = "xyes"], [
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer], [], [-Werror])
|
|
|
|
])
|
|
|
|
|
|
|
|
|
2015-01-30 16:49:14 +11:00
|
|
|
##-------------------------------------------------------------------------
|
2015-03-18 17:14:58 +11:00
|
|
|
## Choose the most performant processor architecture and features
|
|
|
|
|
2015-01-30 16:49:14 +11:00
|
|
|
AC_CANONICAL_HOST
|
|
|
|
|
|
|
|
AS_CASE([$host_cpu],
|
|
|
|
[x86_64], [
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-mtune=generic], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-msse], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-msse2], [], [-Werror])
|
|
|
|
],
|
|
|
|
|
|
|
|
[i686], [
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-march=prescott], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-mtune=generic], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-mcmov], [], [-Werror])
|
|
|
|
],
|
|
|
|
|
|
|
|
[AC_MSG_WARN([unknown host_cpu])]
|
|
|
|
)
|
|
|
|
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-pipe])
|
2015-09-10 14:40:18 +10:00
|
|
|
|
|
|
|
# base instruction set requirements for x86
|
2015-01-30 16:49:14 +11:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-mfpmath=sse], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-msahf], [], [-Werror])
|
|
|
|
|
2015-03-18 17:14:58 +11:00
|
|
|
##-------------------------------------------------------------------------
|
|
|
|
## Enable aggressive code generation optimisations
|
|
|
|
|
2015-01-30 16:49:14 +11:00
|
|
|
AS_IF([test "x$enable_debugging" != "xyes"], [
|
2015-09-10 14:40:18 +10:00
|
|
|
# gcc vectorisation
|
2015-01-30 16:49:14 +11:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-ftree-vectorize], [], [-Werror])
|
|
|
|
|
2015-09-10 14:40:18 +10:00
|
|
|
# clang vectorisation
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fvectorize], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fslp-vectorize], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fslp-vectorize-aggressive], [], [-Werror])
|
2015-06-30 22:01:32 +10:00
|
|
|
|
2015-09-10 14:40:18 +10:00
|
|
|
# loop hosting/distribution
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-ftree-loop-distribute-patterns], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-ftree-loop-distribution], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-ftree-loop-if-convert-stores], [], [-Werror])
|
2015-06-30 22:01:32 +10:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-ftree-loop-linear], [], [-Werror])
|
|
|
|
|
2015-09-10 14:40:18 +10:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-funsafe-loop-optimizations], [], [-Werror])
|
2015-06-30 22:01:32 +10:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-floop-interchange], [], [-Werror])
|
|
|
|
|
2015-09-10 14:40:18 +10:00
|
|
|
# safety removal for performance
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fno-stack-protector], [], [-Werror])
|
2015-01-30 16:49:14 +11:00
|
|
|
])
|
2015-03-18 17:14:58 +11:00
|
|
|
|
|
|
|
##-------------------------------------------------------------------------
|
|
|
|
## Enable code size optimisations (that don't impact performance)
|
|
|
|
## Note: we assume CXX, and that CXXLINK is g++ not ld, hence the -Wl opt
|
|
|
|
AS_IF([test "x$enable_debugging" != "xyes"], [
|
2015-09-10 14:40:18 +10:00
|
|
|
AX_APPEND_COMPILE_FLAGS([-fdevirtualize], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fdevirtualize-speculatively], [], [-Werror])
|
|
|
|
|
2015-03-18 17:14:58 +11:00
|
|
|
AX_CHECK_LINK_FLAG([-Wl,--gc-sections], [
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-fdata-sections], [], [-Werror])
|
|
|
|
AX_APPEND_COMPILE_FLAGS([-ffunction-sections], [], [-Werror])
|
|
|
|
AX_APPEND_LINK_FLAGS([-Wl,--gc-sections], [], [-Werror])
|
|
|
|
])
|
|
|
|
])
|
2015-01-30 16:49:14 +11:00
|
|
|
])
|