use Clang11's -fpch-instantiate-templates if available

The optimization to instantiate templates already while creating
the PCH instead for every single compilation has been finally
accepted upstream, but it's opt-in.

Change-Id: Ia6456df05512329fc594f9ed0e400250c4f5029e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98948
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák 2020-07-17 12:05:58 +02:00
parent 621514cf1d
commit d60dc145ad
3 changed files with 24 additions and 4 deletions

View file

@ -463,6 +463,7 @@ export PATH=@LO_PATH@
export LIBO_PATH_SEPARATOR=@P_SEP@
export PAGEMAKER_CFLAGS=$(gb_SPACE)@PAGEMAKER_CFLAGS@
export PAGEMAKER_LIBS=$(gb_SPACE)@PAGEMAKER_LIBS@
export PCH_INSTANTIATE_TEMPLATES=@PCH_INSTANTIATE_TEMPLATES@
export PCH_MODULES_CODEGEN=@PCH_MODULES_CODEGEN@
export PCH_MODULES_DEBUGINFO=@PCH_MODULES_DEBUGINFO@
export PERL=@PERL@

View file

@ -5317,6 +5317,22 @@ if test -n "$ENABLE_PCH" -a -n "$CCACHE_DEPEND_MODE" -a "$GCC" = "yes" -a "$COM_
fi
fi
PCH_INSTANTIATE_TEMPLATES=
if test -n "$ENABLE_PCH"; then
AC_MSG_CHECKING([whether $CC supports -fpch-instantiate-templates])
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Werror -fpch-instantiate-templates"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ PCH_INSTANTIATE_TEMPLATES="-fpch-instantiate-templates" ],[])
CFLAGS=$save_CFLAGS
if test -n "$PCH_INSTANTIATE_TEMPLATES"; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
CFLAGS=$save_CFLAGS
fi
AC_SUBST(PCH_INSTANTIATE_TEMPLATES)
BUILDING_PCH_WITH_OBJ=
if test -n "$ENABLE_PCH"; then
AC_MSG_CHECKING([whether $CC supports -Xclang -building-pch-with-obj])

View file

@ -101,21 +101,24 @@ gb_PrecompiledHeader_get_enableflags = \
gb_PrecompiledHeader_EXT := .gch
endif
gb_PrecompiledHeader_extra_pch_cxxflags += $(PCH_INSTANTIATE_TEMPLATES)
# Clang supports building extra object file where it puts code that would be shared by all users of the PCH.
# Unlike with MSVC it is built as a separate step. The relevant options are used only when generating the PCH
# and when creating the PCH's object file, normal compilations using the PCH do not need extra options.
gb_PrecompiledHeader_pch_with_obj = $(BUILDING_PCH_WITH_OBJ)
gb_PrecompiledHeader_pch_with_obj += $(BUILDING_PCH_WITH_OBJ)
gb_PrecompiledHeader_extra_pch_cxxflags += $(BUILDING_PCH_WITH_OBJ)
ifneq ($(BUILDING_PCH_WITH_OBJ),)
# If using Clang's PCH extra object, we may need to strip unused sections, otherwise inline and template functions
# emitted in that object may in some cases cause unresolved references to private symbols in other libraries.
gb_LinkTarget_LDFLAGS += $(LD_GC_SECTIONS)
gb_PrecompiledHeader_pch_with_obj += -ffunction-sections -fdata-sections
# Enable generating more shared code and debuginfo in the PCH object file.
gb_PrecompiledHeader_pch_with_obj += $(PCH_MODULES_DEBUGINFO)
gb_PrecompiledHeader_extra_pch_cxxflags += $(PCH_MODULES_DEBUGINFO)
ifeq ($(ENABLE_OPTIMIZED),)
# -fmodules-codegen appears to be worth it only if not optimizing, otherwise optimizing all the functions emitted
# in the PCH object file may take way too long, especially given that many of those may get thrown away
gb_PrecompiledHeader_pch_with_obj += $(PCH_MODULES_CODEGEN)
gb_PrecompiledHeader_extra_pch_cxxflags += $(PCH_MODULES_CODEGEN)
endif
endif
@ -138,7 +141,7 @@ $(call gb_Helper_abbreviate_dirs,\
$(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \
$(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \
$(gb_NO_PCH_TIMESTAMP) \
$(gb_PrecompiledHeader_pch_with_obj) \
$(gb_PrecompiledHeader_extra_pch_cxxflags) \
$(6) \
$(call gb_cxx_dep_generation_options,$(1),$(call gb_PrecompiledHeader_get_dep_target_tmp,$(2),$(7))) \
-c $(patsubst %.cxx,%.hxx,$(3)) \