From 1c8b2b6da13636b07d47e157b2ddac445966ddf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 15 Oct 2019 10:04:54 +0200 Subject: [PATCH] use PCH for clang plugin source too, if enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This currently supports only building with Clang on Linux, as I'm lazy to handle the other cases (and Clang should be usually self-built anyway). The main compile time cost is in optimizing the code, but this still saves few seconds per source. Change-Id: Ib6c0fd874820af737ee1257cb5234fb78bc63ad8 Reviewed-on: https://gerrit.libreoffice.org/80810 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- compilerplugins/.gitignore | 2 + compilerplugins/Makefile-clang.mk | 41 +++++++++++++++- compilerplugins/clang/precompiled_clang.hxx | 54 +++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 compilerplugins/clang/precompiled_clang.hxx diff --git a/compilerplugins/.gitignore b/compilerplugins/.gitignore index a20678901a16..a1c7d40d7bd8 100644 --- a/compilerplugins/.gitignore +++ b/compilerplugins/.gitignore @@ -1,6 +1,8 @@ /clang/clang-timestamp /clang/plugin.dll /clang/plugin.so +/clang/clang.pch +/clang/clang.pch.d /clang/sharedvisitor/*.plugininfo /clang/sharedvisitor/analyzer /clang/sharedvisitor/analyzer.d diff --git a/compilerplugins/Makefile-clang.mk b/compilerplugins/Makefile-clang.mk index c6b3b208c7e0..9e6b7fd490b2 100644 --- a/compilerplugins/Makefile-clang.mk +++ b/compilerplugins/Makefile-clang.mk @@ -43,6 +43,10 @@ ifeq ($(OS),WNT) LO_CLANG_SHARED_PLUGINS= endif +# Whether to use precompiled headers for the sources. This is actually controlled +# by gb_ENABLE_PCH like everywhere else, but unsetting this disables PCH. +LO_CLANG_USE_PCH=1 + # Whether to use precompiled headers for the analyzer too. Does not apply to compiling sources. LO_CLANG_USE_ANALYZER_PCH=1 @@ -100,6 +104,20 @@ CLANGWERROR := -Werror endif endif +ifneq ($(LO_CLANG_USE_PCH),) +# Reset and enable only if actually supported and enabled. +LO_CLANG_USE_PCH= +ifneq ($(gb_ENABLE_PCH),) +ifneq ($(OS),WNT) +# Currently only Clang PCH is supported (which should usually be the case, as Clang is usually self-built). +ifneq ($(findstring clang,$(COMPILER_PLUGINS_CXX)),) +LO_CLANG_USE_PCH=1 +endif +endif +endif +endif + + compilerplugins: compilerplugins-build ifdef LO_CLANG_SHARED_PLUGINS @@ -139,6 +157,7 @@ compilerplugins-clean: $(CLANGOBJDIR) \ $(CLANGOUTDIR)/clang-timestamp \ $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT) \ + $(CLANGOUTDIR)/clang.pch{,.d} \ $(CLANGOUTDIR)/sharedvisitor/*.plugininfo \ $(CLANGOUTDIR)/sharedvisitor/clang.pch{,.d} \ $(CLANGOUTDIR)/sharedvisitor/sharedvisitor.{cxx,d,o} \ @@ -176,10 +195,12 @@ else # clangbuildsrc cxxfile ofile dfile define clangbuildsrc -$(2): $(1) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp +$(2): $(1) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp \ + $(if $(LO_CLANG_USE_PCH),$(CLANGOUTDIR)/clang.pch) $$(call gb_Output_announce,$(subst $(SRCDIR)/,,$(subst $(BUILDDIR)/,,$(1))),$(true),CXX,3) $(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGDEFS) $(CLANGCXXFLAGS) $(CLANGWERROR) \ $(CLANGINCLUDES) -I$(BUILDDIR)/config_host -I$(CLANGINDIR) $(1) \ + $(if $(LO_CLANG_USE_PCH),-include-pch $(CLANGOUTDIR)/clang.pch -DPCH_LEVEL=$(gb_ENABLE_PCH)) \ -fPIC -c -o $(2) -MMD -MT $(2) -MP -MF $(3) -include $(3) @@ -294,7 +315,25 @@ $(CLANGOUTDIR)/sources-shared.txt: touch $@ endif +ifneq ($(LO_CLANG_USE_PCH),) +# the PCH for plugin sources themselves + +ifeq ($(OS),WNT) +# TODO +else +$(CLANGOUTDIR)/clang.pch: $(CLANGINDIR)/precompiled_clang.hxx \ + $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp + $(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),PCH,1) + $(QUIET)$(COMPILER_PLUGINS_CXX) -x c++-header $(CLANGDEFS) $(CLANGCXXFLAGS) $(CLANGWERROR) \ + $(CLANGINCLUDES) -I$(BUILDDIR)/config_host -I$(CLANGINDIR) -DPCH_LEVEL=$(gb_ENABLE_PCH) \ + -fPIC $< -o $@ -MMD -MT $@ -MP -MF $(CLANGOUTDIR)/clang.pch.d +endif +-include $(CLANGOUTDIR)/clang.pch.d + +endif + ifdef LO_CLANG_USE_ANALYZER_PCH +# the PCH for usage in sharedvisitor/analyzer # these are from the invocation in analyzer.cxx LO_CLANG_ANALYZER_PCH_CXXFLAGS := -I$(BUILDDIR)/config_host $(CLANGTOOLDEFS) diff --git a/compilerplugins/clang/precompiled_clang.hxx b/compilerplugins/clang/precompiled_clang.hxx new file mode 100644 index 000000000000..926580353883 --- /dev/null +++ b/compilerplugins/clang/precompiled_clang.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * Based on LLVM/Clang. + * + * This file is distributed under the University of Illinois Open Source + * License. See LICENSE.TXT for details. + * + */ + +// This file is generated manually. Is it based on the output of +// cat *.cxx *.hxx | grep '#include' | grep 'clang/' | sort -u + +#if PCH_LEVEL >= 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#if PCH_LEVEL >= 2 +// These are included by everything anyway. +#include "plugin.hxx" +#include "check.hxx" +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */