summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-10-15 10:04:54 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-10-15 16:02:40 +0200
commit1c8b2b6da13636b07d47e157b2ddac445966ddf4 (patch)
tree823e2adb5db894a9d2af5bc317aebec0e81e57e5 /compilerplugins
parenta5496f4441450bec4dfb7468642d72c758a725a8 (diff)
use PCH for clang plugin source too, if enabled
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 <l.lunak@collabora.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/.gitignore2
-rw-r--r--compilerplugins/Makefile-clang.mk41
-rw-r--r--compilerplugins/clang/precompiled_clang.hxx54
3 files changed, 96 insertions, 1 deletions
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 <clang/AST/ASTConsumer.h>
+#include <clang/AST/ASTContext.h>
+#include <clang/AST/Attr.h>
+#include <clang/AST/Comment.h>
+#include <clang/AST/CXXInheritance.h>
+#include <clang/AST/DeclBase.h>
+#include <clang/AST/DeclCXX.h>
+#include <clang/AST/Decl.h>
+#include <clang/AST/DeclTemplate.h>
+#include <clang/AST/ExprCXX.h>
+#include <clang/AST/Expr.h>
+#include <clang/AST/RecursiveASTVisitor.h>
+#include <clang/AST/StmtVisitor.h>
+#include <clang/AST/Type.h>
+#include <clang/Basic/FileManager.h>
+#include <clang/Basic/OperatorKinds.h>
+#include <clang/Basic/SourceManager.h>
+#include <clang/Frontend/CompilerInstance.h>
+#include <clang/Frontend/FrontendAction.h>
+#include <clang/Frontend/FrontendActions.h>
+#include <clang/Frontend/FrontendPluginRegistry.h>
+#include <clang/Lex/Lexer.h>
+#include <clang/Lex/PPCallbacks.h>
+#include <clang/Lex/Preprocessor.h>
+#include <clang/Rewrite/Core/Rewriter.h>
+#include <clang/Sema/SemaDiagnostic.h>
+#include <clang/Sema/Sema.h>
+#include <clang/Sema/SemaInternal.h>
+#include <clang/Tooling/CommonOptionsParser.h>
+#include <clang/Tooling/Refactoring.h>
+#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: */