[Mesa-dev] [PATCH] mesa: Enable LTO by default on i965/libdricore release builds.
Eric Anholt
eric at anholt.net
Thu Aug 8 13:43:40 PDT 2013
We can't just smash it on globally due to (probably resolvable) issues
with the asm in glapi. And we don't want to penalize developers with
longer build times for their normal debug environment.
Due to libdricore making almost all of our symbols public, the effect is
very small -- cairo-gl with INTEL_NO_HW=1 shows -0.798709% +/- 0.333703%
change in runtime (n=30).
---
If we were to avoid dricore, there's an additional 5% improvement available
(see the "megadriver" branch of my tree).
configure.ac | 25 +++++++++++++++++++++++++
src/mesa/Makefile.am | 4 ++--
src/mesa/drivers/dri/i965/Makefile.am | 1 +
src/mesa/libdricore/Makefile.am | 8 +++++++-
src/mesa/program/Makefile.am | 4 ++--
5 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 62d06e0..26c230d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -314,6 +314,7 @@ AC_ARG_ENABLE([debug],
[enable_debug="$enableval"],
[enable_debug=no]
)
+enable_lto=yes
if test "x$enable_debug" = xyes; then
DEFINES_FOR_BUILD="$DEFINES_FOR_BUILD -DDEBUG"
if test "x$GCC_FOR_BUILD" = xyes; then
@@ -330,7 +331,31 @@ if test "x$enable_debug" = xyes; then
if test "x$GXX" = xyes; then
CXXFLAGS="$CXXFLAGS -g -O0"
fi
+
+ # Disable LTO by default on debug builds, since it's so expensive at
+ # compile time.
+ enable_lto=no
+fi
+
+AC_ARG_ENABLE([lto],
+ [AS_HELP_STRING([--disable-lto],
+ [Enable link-time optimization @<:@default=auto, disabled if debug is enabled@:>@])],
+ [enable_lto="$enableval"])
+
+if test "x$enable_lto" = "xyes"; then
+ # Enable LTO if the compiler supports it and not disabled by the user,
+ # which allows the compiler to inline Mesa's many small,
+ # non-manually-inlined helper functions.
+ save_CFLAGS="$CFLAGS"
+ AC_MSG_CHECKING([whether $CC supports LTO])
+ LTOFLAGS="-flto -fuse-linker-plugin"
+ CFLAGS="$CFLAGS $LTOFLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+ [AC_MSG_RESULT([yes])],
+ [AC_MSG_RESULT([no]); LTOFLAGS=""]);
+ CFLAGS="$save_CFLAGS"
fi
+AC_SUBST([LTOFLAGS])
dnl
dnl library names
diff --git a/src/mesa/Makefile.am b/src/mesa/Makefile.am
index e9c16e7..ad04cc6 100644
--- a/src/mesa/Makefile.am
+++ b/src/mesa/Makefile.am
@@ -94,8 +94,8 @@ BUILDDIR = $(top_builddir)/src/mesa/
include Makefile.sources
AM_CPPFLAGS = $(DEFINES) $(INCLUDE_DIRS)
-AM_CFLAGS = $(LLVM_CFLAGS) $(VISIBILITY_CFLAGS)
-AM_CXXFLAGS = $(LLVM_CFLAGS) $(VISIBILITY_CXXFLAGS)
+AM_CFLAGS = $(LLVM_CFLAGS) $(VISIBILITY_CFLAGS) $(LTOFLAGS)
+AM_CXXFLAGS = $(LLVM_CFLAGS) $(VISIBILITY_CXXFLAGS) $(LTOFLAGS)
MESA_ASM_FILES_FOR_ARCH =
diff --git a/src/mesa/drivers/dri/i965/Makefile.am b/src/mesa/drivers/dri/i965/Makefile.am
index 27c67d1..5b3e9cc 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -36,6 +36,7 @@ AM_CFLAGS = \
-I$(top_builddir)/src/mesa/drivers/dri/common \
$(DEFINES) \
$(VISIBILITY_CFLAGS) \
+ $(LTOFLAGS) \
$(INTEL_CFLAGS)
if HAVE_OPENGL_ES1
diff --git a/src/mesa/libdricore/Makefile.am b/src/mesa/libdricore/Makefile.am
index 56ceeb7..22a358d 100644
--- a/src/mesa/libdricore/Makefile.am
+++ b/src/mesa/libdricore/Makefile.am
@@ -31,6 +31,9 @@ AM_CPPFLAGS = \
$(DEFINES) \
-DUSE_DRICORE
+AM_CFLAGS = $(LTOFLAGS)
+AM_CXXFLAGS = $(LTOFLAGS)
+
libdricore at VERSION@_la_SOURCES = \
$(MESA_FILES) \
$(LIBGLCPP_GENERATED_FILES) \
@@ -38,7 +41,10 @@ libdricore at VERSION@_la_SOURCES = \
$(LIBGLSL_FILES) \
$(BUILTIN_COMPILER_GENERATED_CXX_FILES) \
$(top_builddir)/src/glsl/builtin_function.cpp
-libdricore at VERSION@_la_LDFLAGS = -version-number 1:0
+libdricore at VERSION@_la_LDFLAGS = \
+ -version-number 1:0 \
+ $(LTOFLAGS) \
+ $()
libdricore at VERSION@_la_LIBADD = \
../program/libdricore_program.la \
$()
diff --git a/src/mesa/program/Makefile.am b/src/mesa/program/Makefile.am
index ab565e2..f6b7c94 100644
--- a/src/mesa/program/Makefile.am
+++ b/src/mesa/program/Makefile.am
@@ -24,8 +24,8 @@ include ../Makefile.sources
AM_CPPFLAGS = $(DEFINES) $(INCLUDE_DIRS)
AM_CFLAGS = $(VISIBILITY_CFLAGS)
AM_CXXFLAGS = $(VISIBILITY_CXXFLAGS)
-libdricore_program_la_CFLAGS = $(NOVISIBILITY_CFLAGS)
-libdricore_program_la_CXXFLAGS = $(NOVISIBILITY_CXXFLAGS)
+libdricore_program_la_CFLAGS = $(NOVISIBILITY_CFLAGS) $(LTOFLAGS)
+libdricore_program_la_CXXFLAGS = $(NOVISIBILITY_CXXFLAGS) $(LTOFLAGS)
SRCDIR = $(top_srcdir)/src/mesa/
BUILDDIR = $(top_builddir)/src/mesa/
--
1.8.4.rc1
More information about the mesa-dev
mailing list