2017-01-25 18:46:41 +11:00
|
|
|
###############################################################################
|
|
|
|
if (__nc_optimisation)
|
|
|
|
return()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
set (__nc_optimisation TRUE)
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2017-01-17 19:20:12 +11:00
|
|
|
include (compile_flag)
|
|
|
|
include (link_flag)
|
|
|
|
include (canonical_host)
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2017-01-25 18:46:23 +11:00
|
|
|
option(LTO "enable link-time optimisation" OFF)
|
2017-01-17 19:20:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
##-----------------------------------------------------------------------------
|
2017-01-25 18:45:42 +11:00
|
|
|
## Enable link-time optimisation.
|
|
|
|
##
|
2017-05-12 15:57:30 +10:00
|
|
|
## The INTERPROCEDURAL_OPTIMISATION flag is silently ignored for almost all
|
|
|
|
## compilers. Fuck you too CMake. We have to make up for its deficiencies
|
|
|
|
## ourselves.
|
2017-01-25 18:46:23 +11:00
|
|
|
if (LTO)
|
2017-01-25 18:45:42 +11:00
|
|
|
# Add the linker flags first otherwise the linker may not recognise the
|
|
|
|
# object format
|
|
|
|
append_link_flag("-fuse-linker-plugin")
|
|
|
|
append_link_flag("-flto")
|
|
|
|
|
|
|
|
# Actually enable LTO object creation, but try very hard to avoid
|
|
|
|
# situations where we may accidentally use regular/fat objects.
|
2017-01-17 19:20:12 +11:00
|
|
|
append_compile_flag("-flto")
|
|
|
|
append_compile_flag("-fno-fat-lto-objects")
|
2017-01-25 18:45:42 +11:00
|
|
|
|
|
|
|
# Throw in some optimisation flags that are LTO specific. We don't
|
|
|
|
# particularly care about checking Debug/Release here because LTO is
|
|
|
|
# pretty heavyweight anyway.
|
|
|
|
append_compile_flag("-fdevirtualize-at-ltrans")
|
2017-05-12 15:57:30 +10:00
|
|
|
|
|
|
|
# If we're using GCC we probably need to use gcc-{ar,nm,ranlib} so that
|
|
|
|
# plugin support works. Ideally we'd actually do some compilation tests,
|
|
|
|
# but... it's a royal PITA with CMake.
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
set (CMAKE_AR "gcc-ar")
|
|
|
|
set (CMAKE_NM "gcc-nm")
|
|
|
|
set (CMAKE_RANLIB "gcc-ranlib")
|
|
|
|
endif ()
|
2017-01-25 18:45:42 +11:00
|
|
|
endif ()
|
2017-01-17 19:20:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2017-01-25 18:46:23 +11:00
|
|
|
option(FRAMEPOINTER "retain the framepointer even if optimising" OFF)
|
2017-01-17 19:20:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
##-----------------------------------------------------------------------------
|
2017-01-25 18:46:23 +11:00
|
|
|
if (FRAMEPOINTER)
|
|
|
|
append_compile_flag("-fno-omit-frame-pointer")
|
|
|
|
endif ()
|
2017-01-17 19:20:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
canonical_host()
|
|
|
|
|
|
|
|
|
|
|
|
##-----------------------------------------------------------------------------
|
2017-01-18 21:43:30 +11:00
|
|
|
if (${host_cpu} STREQUAL "x86_64")
|
2017-01-17 19:20:12 +11:00
|
|
|
append_compile_flag(-mtune=generic)
|
|
|
|
append_compile_flag(-msse)
|
|
|
|
append_compile_flag(-msse2)
|
|
|
|
append_compile_flag(-msahf)
|
2017-01-18 21:43:30 +11:00
|
|
|
elseif (${host_cpu} STREQUAL "i686")
|
2017-01-17 19:20:12 +11:00
|
|
|
append_compile_flag(-march=prescott)
|
|
|
|
append_compile_flag(-mtune=generic)
|
|
|
|
append_compile_flag(-mcmov)
|
|
|
|
append_compile_flag(-mfpmath=sse)
|
|
|
|
else ()
|
2017-01-18 21:43:30 +11:00
|
|
|
message (FATAL_ERROR "unknown HOST_CPU '${host_cpu}'")
|
2017-01-17 19:20:12 +11:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2017-01-23 21:42:34 +11:00
|
|
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
2017-01-17 19:20:12 +11:00
|
|
|
else()
|
|
|
|
append_compile_flag(-ftree-vectorize)
|
|
|
|
|
|
|
|
# clang vectorisation
|
|
|
|
append_compile_flag(-fvectorize)
|
|
|
|
append_compile_flag(-fslp-vectorize)
|
|
|
|
append_compile_flag(-fslp-vectorize-aggressive)
|
|
|
|
|
|
|
|
# loop hosting/distribution
|
|
|
|
append_compile_flag(-floop-nest-optimize)
|
|
|
|
|
|
|
|
append_compile_flag(-ftree-loop-distribution)
|
|
|
|
append_compile_flag(-ftree-loop-distribute-patterns)
|
|
|
|
append_compile_flag(-ftree-loop-im)
|
|
|
|
append_compile_flag(-ftree-loop-if-convert-stores)
|
|
|
|
|
|
|
|
append_compile_flag(-fivopts)
|
|
|
|
|
|
|
|
append_compile_flag(-funsafe-loop-optimizations)
|
|
|
|
append_compile_flag(-floop-interchange)
|
|
|
|
|
|
|
|
append_compile_flag(-fpredictive-commoning)
|
|
|
|
append_compile_flag(-funswitch-loops)
|
|
|
|
|
|
|
|
# options that require substantial time/memory
|
|
|
|
# GCC: ipa-pta can produce broken code when using LTO
|
|
|
|
#AS_IF([test "x$ax_cv_cxx_compiler_vendor" != "xgnu" ||
|
|
|
|
# test "x$enable_lto" != "xyes"], [
|
|
|
|
# AX_APPEND_COMPILE_FLAGS([-fipa-pta])
|
|
|
|
#])
|
|
|
|
|
|
|
|
# safety removal for performance
|
|
|
|
append_compile_flag(-fno-stack-protector)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2017-01-23 21:42:34 +11:00
|
|
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
2017-01-17 19:20:12 +11:00
|
|
|
else ()
|
|
|
|
append_compile_flag(-fdevirtualize)
|
|
|
|
append_compile_flag(-fdevirtualize-speculatively)
|
|
|
|
|
|
|
|
check_link_flag(TEST_GC_SECTIONS, "-Wl,--gc-sections")
|
|
|
|
if (TEST_LD_GC_SECTIONS)
|
|
|
|
append_compile_flag(-fdata-sections)
|
|
|
|
append_compile_flag(-ffunction-sections)
|
|
|
|
append_link_flag("-Wl,--gc-sections")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2017-01-23 21:42:34 +11:00
|
|
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
2017-01-17 19:20:12 +11:00
|
|
|
add_definitions(-DENABLE_DEBUGGING)
|
|
|
|
add_definitions(-D_GLIBCXX_DEBUG)
|
|
|
|
|
2017-07-04 16:20:31 +10:00
|
|
|
append_compile_flag(-Og)
|
2017-01-17 19:20:12 +11:00
|
|
|
append_compile_flag(-Werror)
|
|
|
|
# this was protected for xmingw32, find out why
|
|
|
|
append_compile_flag(-fstack-protector)
|
|
|
|
else ()
|
|
|
|
append_compile_flag(-O2)
|
|
|
|
append_compile_flag(-fno-rtti)
|
|
|
|
add_definitions(-DNO_RTTI)
|
|
|
|
add_definitions(-DNDEBUG)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
append_compile_flag(-g)
|
|
|
|
append_compile_flag(-ggdb)
|