make clangplugin analyzer use internally a PCH to speed things up
This generally makes the sharedvisitor performance reasonable.
The only costly thing that remains is compiling the large sharedvisitor.cxx,
which with optimizations takes quite some time, but there's ccache for that.
Change-Id: Iffa5fc9df34cdb5edf1cde34fc558fd007ef8263
Reviewed-on: https://gerrit.libreoffice.org/78569
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <[email protected]>
diff --git a/compilerplugins/Makefile-clang.mk b/compilerplugins/Makefile-clang.mk
index 4fd3f77..c36bc6b 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -42,6 +42,9 @@
LO_CLANG_SHARED_PLUGINS=
endif
# Whether to use precompiled headers for the analyzer too. Does not apply to compiling sources.
LO_CLANG_USE_ANALYZER_PCH=1
# The uninteresting rest.
include $(SRCDIR)/solenv/gbuild/gbuild.mk
@@ -207,7 +210,9 @@
SHARED_SOURCES := $(shell grep -l "LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx)
SHARED_SOURCE_INFOS := $(foreach source,$(SHARED_SOURCES),$(patsubst $(CLANGINDIR)/%.cxx,$(CLANGOUTDIR)/sharedvisitor/%.plugininfo,$(source)))
$(CLANGOUTDIR)/sharedvisitor/%.plugininfo: $(CLANGINDIR)/%.cxx $(CLANGOUTDIR)/sharedvisitor/analyzer$(CLANG_EXE_EXT)
$(CLANGOUTDIR)/sharedvisitor/%.plugininfo: $(CLANGINDIR)/%.cxx \
$(CLANGOUTDIR)/sharedvisitor/analyzer$(CLANG_EXE_EXT) \
$(CLANGOUTDIR)/sharedvisitor/clang.pch
$(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),GEN,1)
$(QUIET)$(ICECREAM_RUN) $(CLANGOUTDIR)/sharedvisitor/analyzer$(CLANG_EXE_EXT) \
$(COMPILER_PLUGINS_TOOLING_ARGS:%=-arg=%) $< > $@
@@ -222,7 +227,8 @@
# Path to the clang system headers (no idea if there's a better way to get it).
CLANGTOOLDEFS = -DCLANGSYSINCLUDE=$(shell $(LLVMCONFIG) --libdir)/clang/$(shell $(LLVMCONFIG) --version | sed 's/svn//')/include
# -std=c++11 is in line with the default value for COMPILER_PLUGINS_CXX in configure.ac:
CLANGTOOLDEFS += -DSTDOPTION=\"$(or $(filter -std=%,$(COMPILER_PLUGINS_CXX)),-std=c++11)\"
CLANGSTDOPTION := $(or $(filter -std=%,$(COMPILER_PLUGINS_CXX)),-std=c++11)
CLANGTOOLDEFS += -DSTDOPTION=\"$(CLANGSTDOPTION)\"
ifneq ($(filter-out MACOSX WNT,$(OS)),)
ifneq ($(CLANGDIR),/usr)
# Help the generator find Clang shared libs, if Clang is built so and installed in a non-standard prefix.
@@ -235,6 +241,7 @@
$(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),GEN,1)
$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) $(CLANGTOOLDEFS) $(CLANGINCLUDES) \
-DCLANGDIR=$(CLANGDIR) -I$(BUILDDIR)/config_host \
-DLO_CLANG_USE_ANALYZER_PCH=$(LO_CLANG_USE_ANALYZER_PCH) \
-c $< -o $(CLANGOUTDIR)/sharedvisitor/analyzer.o -MMD -MT $@ -MP \
-MF $(CLANGOUTDIR)/sharedvisitor/analyzer.d
$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGCXXFLAGS) $(CLANGOUTDIR)/sharedvisitor/analyzer.o \
@@ -261,4 +268,20 @@
# TODO WNT version
endif
ifdef LO_CLANG_USE_ANALYZER_PCH
# these are from the invocation in analyzer.cxx
LO_CLANG_ANALYZER_PCH_CXXFLAGS := -I$(BUILDDIR)/config_host -I$(CLANGDIR)/include $(CLANGTOOLDEFS) $(CLANGSTDOPTION) \
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
$(CLANGOUTDIR)/sharedvisitor/clang.pch: $(CLANGINDIR)/sharedvisitor/precompiled_clang.hxx \
$(CLANGOUTDIR)/clang-timestamp \
| $(CLANGOUTDIR)/sharedvisitor
$(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),PCH,1)
$(QUIET)$(CLANGDIR)/bin/clang -x c++-header $(LO_CLANG_ANALYZER_PCH_CXXFLAGS) $< -o $@
else
$(CLANGOUTDIR)/sharedvisitor/clang.pch:
touch $@
endif
# vim: set noet sw=4 ts=4:
diff --git a/compilerplugins/clang/sharedvisitor/analyzer.cxx b/compilerplugins/clang/sharedvisitor/analyzer.cxx
index 171fc85..5b716f4 100644
--- a/compilerplugins/clang/sharedvisitor/analyzer.cxx
+++ b/compilerplugins/clang/sharedvisitor/analyzer.cxx
@@ -243,14 +243,19 @@
#define STRINGIFY(a) STRINGIFY2(a)
args.insert(
args.end(),
{
{ // These must match LO_CLANG_ANALYZER_PCH_CXXFLAGS in Makefile-clang.mk .
"-I" BUILDDIR "/config_host", // plugin sources use e.g. config_global.h
"-I" STRINGIFY(CLANGDIR) "/include", // clang's headers
"-I" STRINGIFY(CLANGSYSINCLUDE), // clang system headers
STDOPTION,
"-D__STDC_CONSTANT_MACROS", // Clang headers require these.
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-D__STDC_LIMIT_MACROS"
#ifdef LO_CLANG_USE_ANALYZER_PCH
,
"-include-pch", // use PCH with Clang headers to speed up parsing/analysing
BUILDDIR "/compilerplugins/clang/sharedvisitor/clang.pch"
#endif
});
for( ; i < argc; ++ i )
{
diff --git a/compilerplugins/clang/sharedvisitor/precompiled_clang.hxx b/compilerplugins/clang/sharedvisitor/precompiled_clang.hxx
new file mode 100644
index 0000000..3baf4b0
--- /dev/null
+++ b/compilerplugins/clang/sharedvisitor/precompiled_clang.hxx
@@ -0,0 +1,12 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Used by the analyzer to speed up processing plugin sources.
#include "../plugin.hxx"