diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-03-07 14:31:17 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-03-12 12:36:57 +0100 |
commit | adb08e892b37ea9e155abbdee4e0c9951a1d163b (patch) | |
tree | 065683917390d6aca4ff6d22e2f945e48718352e /compilerplugins/Makefile-clang.mk | |
parent | 3a15c034be9f557f350d0ba1f3a842151066eaae (diff) |
make (some) clang plugins share the same RecursiveASTVisitor
Each plugin currently uses its own recursive AST run, which adds up.
This patch adds another shared plugin which internally contains all
(suitable) plugins and dispatches to them from the same one recursive
run. This patch converts ~25 plugins and for starmath's accessibility.cxx
reduces clang build time from 5.43s to 5.14s (and it's 4.39s without any
plugins). As there are almost 50 more plugins to go, this can theoretically
result in 4.56s final time, although probably not all plugins can be
that easily converted, if at all.
This mostly requires very little change in many plugins (see e.g.
BadStatics), some even work without any functionality change (e.g.
CharRightShift). Traverse* calls require some changes but are often
not that difficult. WalkUp* probably can't be supported, although some
plugins can(?) possibly be adjusted to not rely on them. And of course
some plugins can be left as they are, using their own recursive run.
See description at the top of generator.cxx for description of how to
convert a plugin.
The sharedvisitor.cxx source is generated based on scanning relevant
plugin sources using a clang-based scanner/generator. The generated
source is intentionally included instead of getting always generated,
as the generating currently takes some time, so it should get updated
in git whenever a change in a plugin triggers a source change in it.
Change-Id: Ia0d2e3a5a464659503dbb4ed6c20b6cc89b4de01
Reviewed-on: https://gerrit.libreoffice.org/68026
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'compilerplugins/Makefile-clang.mk')
-rw-r--r-- | compilerplugins/Makefile-clang.mk | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/compilerplugins/Makefile-clang.mk b/compilerplugins/Makefile-clang.mk index 36784fbb4f14..af61c14e1664 100644 --- a/compilerplugins/Makefile-clang.mk +++ b/compilerplugins/Makefile-clang.mk @@ -22,6 +22,10 @@ else CLANGCXXFLAGS=-O2 -Wall -Wextra -Wundef -g endif +# Whether to make plugins use one shared ASTRecursiveVisitor (plugins run faster). +# By default enabled, disable if you work on an affected plugin (re-generating takes time). +LO_CLANG_SHARED_PLUGINS=1 + # The uninteresting rest. include $(SRCDIR)/solenv/gbuild/gbuild.mk @@ -50,6 +54,8 @@ else CLANGINCLUDES=$(if $(filter /usr,$(CLANGDIR)),,-isystem $(CLANGDIR)/include) endif +LLVMCONFIG=$(CLANGDIR)/bin/llvm-config + # Clang/LLVM libraries are intentionally not linked in, they are usually built as static libraries, which means the resulting # plugin would be big (even though the clang binary already includes it all) and it'd be necessary to explicitly specify # also all the dependency libraries. @@ -59,6 +65,10 @@ CLANGINDIR=$(SRCDIR)/compilerplugins/clang # plugin will cause cache misses with ccache. CLANGOUTDIR=$(BUILDDIR)/compilerplugins/obj +ifdef LO_CLANG_SHARED_PLUGINS +CLANGCXXFLAGS+=-DLO_CLANG_SHARED_PLUGINS +endif + QUIET=$(if $(verbose),,@) ifneq ($(ENABLE_WERROR),) @@ -72,8 +82,13 @@ endif compilerplugins: compilerplugins-build +ifdef LO_CLANG_SHARED_PLUGINS +# The shared source, intentionally put first in the list because it takes the longest to build. +CLANGSRC=sharedvisitor/sharedvisitor.cxx +endif # The list of source files, generated automatically (all files in clang/, but not subdirs). -CLANGSRC=$(foreach src,$(wildcard $(CLANGINDIR)/*.cxx), $(notdir $(src))) +CLANGSRC+=$(foreach src,$(wildcard $(CLANGINDIR)/*.cxx), $(notdir $(src))) + # Remember the sources and if they have changed, force plugin relinking. CLANGSRCCHANGED= \ $(shell mkdir -p $(CLANGOUTDIR) ; \ @@ -152,4 +167,35 @@ endif $(CLANGOUTDIR)/clang-timestamp: $(CLANGDIR)/bin/clang$(CLANG_EXE_EXT) $(QUIET)touch $@ + +ifdef LO_CLANG_SHARED_PLUGINS +# Update the shared visitor source if needed. It is intentionally included in the sources and generated only when +# needed, because the generating takes a while. +# If you want to remake the source with LO_CLANG_SHARED_PLUGINS disabled, run 'make LO_CLANG_SHARED_PLUGINS=1'. +$(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx: $(shell grep -l "LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx) +$(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx: $(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT) + $(call gb_Output_announce,$(subst $(SRCDIR)/,,$@),$(true),GEN,1) + $(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT) $(shell grep -l "LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx) \ + > $(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx + +CLANGTOOLLIBS = -lclangTooling -lclangDriver -lclangFrontend -lclangParse -lclangSema -lclangEdit -lclangAnalysis \ + -lclangAST -lclangLex -lclangSerialization -lclangBasic $(shell $(LLVMCONFIG) --ldflags --libs --system-libs) +# 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 + +$(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT): $(CLANGINDIR)/sharedvisitor/generator.cxx + $(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),GEN,1) + $(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) $(CLANGTOOLDEFS) $(CLANGINCLUDES) \ + -DCLANGDIR=$(CLANGDIR) -DBUILDDIR=$(BUILDDIR) -I$(BUILDDIR)/config_host \ + $< -o $@ -MMD -MT $@ -MP -MF $(CLANGOUTDIR)/sharedvisitor/generator.d $(CLANGTOOLLIBS) + +compilerplugins-build: $(CLANGOUTDIR)/sharedvisitor + +$(CLANGOUTDIR)/sharedvisitor: + mkdir -p $(CLANGOUTDIR)/sharedvisitor + +-include $(CLANGOUTDIR)/sharedvisitor/generator.d +# TODO WNT version +endif + # vim: set noet sw=4 ts=4: |