diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-01-27 22:25:13 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-02-03 11:26:43 +0100 |
commit | 81bd3b4a85c7ae6e642969596701bbed645752ff (patch) | |
tree | 28229b7825a8b6a2a760f34d44070ddebc1345bc /compilerplugins/clang/sharedvisitor | |
parent | loplugin:constantparam (diff) | |
download | core-81bd3b4a85c7ae6e642969596701bbed645752ff.tar.gz core-81bd3b4a85c7ae6e642969596701bbed645752ff.zip |
significantly reduce build time of sharedvisitor.cxx
In the sharedvisitor.cxx mode all plugins need just one shared
RecursiveASTVisitor template instance, but as long as they use another
instance each as the base class, Clang still instantiates those templates
and then spends a lot of time optimizing each of them, even though they
should never get used.
So when compiling using sharedvisitor.cxx simply use dummy base classes
that do not do anything. As an additional check they abort() if any
of the functions get called, this needed removing vclwidgets and
unusedmember from shared plugins, because they call TraverseStmt(),
maybe this can get handled somehow later.
Change-Id: Ic5a350da2c3ba31521f71077b1776b1ee8f06dea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87561
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'compilerplugins/clang/sharedvisitor')
-rw-r--r-- | compilerplugins/clang/sharedvisitor/dummyplugin.hxx | 73 | ||||
-rw-r--r-- | compilerplugins/clang/sharedvisitor/generator.cxx | 10 |
2 files changed, 83 insertions, 0 deletions
diff --git a/compilerplugins/clang/sharedvisitor/dummyplugin.hxx b/compilerplugins/clang/sharedvisitor/dummyplugin.hxx new file mode 100644 index 000000000000..7ea085c752de --- /dev/null +++ b/compilerplugins/clang/sharedvisitor/dummyplugin.hxx @@ -0,0 +1,73 @@ +/* -*- 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. + * + */ + +#ifndef DUMMYPLUGIN_H +#define DUMMYPLUGIN_H + +#include "../plugin.hxx" + +using namespace clang; +using namespace llvm; + +namespace loplugin +{ + +// These classes are used as base classes when building with LO_CLANG_SHARED_PLUGINS. +// Since plugin classes in that case should use just one shared RecursiveASTVisitor, +// sharedvisitor/generator.cxx will make these to be the base classes used, so that +// compiling the code doesn't spend a several minutes optimizing instances +// of RecursiveASTVisitor that will never get used. + +template<typename T> +class DummyRecursiveASTVisitor +{ +public: + // These need to be reimplemented, because plugins contain calls to them, + // but they should actually never get called in the shared-visitor mode. + // This could be autogenerated too, but it's probably simpler to just extend + // manually as needed. + bool TraverseDecl( Decl* ) { abort(); } + bool TraverseLinkageSpecDecl( LinkageSpecDecl* ) { abort(); } + bool TraverseStmt( Stmt* ) { abort(); } + bool TraverseUnaryLNot( UnaryOperator* ) { abort(); } + bool TraverseBinLAnd( BinaryOperator* ) { abort(); } + bool TraverseCXXCatchStmt( CXXCatchStmt* ) { abort(); } + bool TraverseCXXDestructorDecl( CXXDestructorDecl* ) { abort(); } + bool TraverseFunctionDecl( FunctionDecl* ) { abort(); } + bool TraverseSwitchStmt( SwitchStmt* ) { abort(); } + bool TraverseImplicitCastExpr( ImplicitCastExpr* ) { abort(); } + bool TraverseCStyleCastExpr( CStyleCastExpr* ) { abort(); } + bool TraverseCXXStaticCastExpr( CXXStaticCastExpr* ) { abort(); } + bool TraverseCXXFunctionalCastExpr( CXXFunctionalCastExpr* ) { abort(); } + bool TraverseFriendDecl( FriendDecl* ) { abort(); } + bool TraverseTypeLoc( TypeLoc ) { abort(); } + bool TraverseAlignedAttr( AlignedAttr* ) { abort(); } +}; + +template<typename Derived> +class DummyFilteringPlugin : public DummyRecursiveASTVisitor<Derived>, public Plugin +{ +public: + explicit DummyFilteringPlugin( const InstantiationData& data ) : Plugin(data) {} +}; + +template<typename Derived> +class DummyFilteringRewritePlugin : public DummyRecursiveASTVisitor<Derived>, public RewritePlugin +{ +public: + explicit DummyFilteringRewritePlugin( const InstantiationData& data ) : RewritePlugin(data) {} +}; + +} // namespace + +#endif // DUMMYPLUGIN_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/sharedvisitor/generator.cxx b/compilerplugins/clang/sharedvisitor/generator.cxx index e62b27fd6422..b94083aaa304 100644 --- a/compilerplugins/clang/sharedvisitor/generator.cxx +++ b/compilerplugins/clang/sharedvisitor/generator.cxx @@ -102,12 +102,22 @@ void generate() "#include <clang/AST/RecursiveASTVisitor.h>\n" "\n" "#include \"plugin.hxx\"\n" +"#include \"sharedvisitor/dummyplugin.hxx\"\n" "\n"; output << "#undef LO_CLANG_SHARED_PLUGINS // to get sources of individual plugins\n"; + output << "// make use of the dummy base classes\n"; + output << "#define RecursiveASTVisitor DummyRecursiveASTVisitor\n"; + output << "#define FilteringPlugin DummyFilteringPlugin\n"; + output << "#define FilteringRewritePlugin DummyFilteringRewritePlugin\n"; + output << "\n"; for( const auto& pluginGroup : plugins ) for( const PluginInfo& plugin : pluginGroup ) output << "#include \"" << plugin.lowercaseName << ".cxx\"" << endl; + output << "\n"; + output << "#undef RecursiveASTVisitor\n"; + output << "#undef FilteringPlugin\n"; + output << "#undef FilteringRewritePlugin\n"; output << "\n" |