[Libreoffice-commits] core.git: compilerplugins/clang solenv/clang-format

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 3 10:27:22 UTC 2020


 compilerplugins/clang/pluginhandler.cxx             |    6 +
 compilerplugins/clang/sharedvisitor/dummyplugin.hxx |   73 ++++++++++++++++++++
 compilerplugins/clang/sharedvisitor/generator.cxx   |   10 ++
 compilerplugins/clang/unusedmember.cxx              |    4 -
 compilerplugins/clang/vclwidgets.cxx                |    4 -
 solenv/clang-format/blacklist                       |    1 
 6 files changed, 89 insertions(+), 9 deletions(-)

New commits:
commit 81bd3b4a85c7ae6e642969596701bbed645752ff
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Jan 27 22:25:13 2020 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Feb 3 11:26:43 2020 +0100

    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 at collabora.com>

diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index 492561fb3a3e..54dba3e3bcc0 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -146,7 +146,11 @@ void PluginHandler::createPlugins( std::set< std::string > rewriters )
         const char* name = plugins[i].optionName;
         // When in unit-test mode, ignore plugins whose names don't match the filename of the test,
         // so that we only generate warnings for the plugin that we want to test.
-        if (unitTestMode && mainFileName.find(plugins[ i ].optionName) == StringRef::npos)
+        // Sharedvisitor plugins still need to remain enabled, they don't do anything on their own,
+        // but sharing-capable plugins need them to actually work (if compiled so) and they register
+        // with them in the code below.
+        if (unitTestMode && mainFileName.find(plugins[ i ].optionName) == StringRef::npos
+            && !plugins[ i ].isSharedPlugin)
             continue;
         if( rewriters.erase( name ) != 0 )
             plugins[ i ].object = plugins[ i ].create( InstantiationData { name, *this, compiler, &rewriter } );
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"
diff --git a/compilerplugins/clang/unusedmember.cxx b/compilerplugins/clang/unusedmember.cxx
index bf1166c14db5..bcd9a8593a68 100644
--- a/compilerplugins/clang/unusedmember.cxx
+++ b/compilerplugins/clang/unusedmember.cxx
@@ -15,8 +15,6 @@
 // all; the used heuristics were enough to not require any explicit [[maybe_unused]] decorations
 // across the existing code base.
 
-#ifndef LO_CLANG_SHARED_PLUGINS
-
 #include <cassert>
 #include <set>
 
@@ -451,6 +449,4 @@ private:
 loplugin::Plugin::Registration<UnusedMember> unusedmember("unusedmember");
 }
 
-#endif
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx
index bd8e83fc8897..9d37b5ce9153 100644
--- a/compilerplugins/clang/vclwidgets.cxx
+++ b/compilerplugins/clang/vclwidgets.cxx
@@ -7,8 +7,6 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef LO_CLANG_SHARED_PLUGINS
-
 #include <memory>
 #include <string>
 #include <iostream>
@@ -870,6 +868,4 @@ loplugin::Plugin::Registration< VCLWidgets > vclwidgets("vclwidgets");
 
 }
 
-#endif // LO_CLANG_SHARED_PLUGINS
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index e69df4d693de..cdfd51d72104 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -1713,6 +1713,7 @@ compilerplugins/clang/sallogareas.cxx
 compilerplugins/clang/salunicodeliteral.cxx
 compilerplugins/clang/sfxpoolitem.cxx
 compilerplugins/clang/sharedvisitor/analyzer.cxx
+compilerplugins/clang/sharedvisitor/dummyplugin.hxx
 compilerplugins/clang/sharedvisitor/generator.cxx
 compilerplugins/clang/simplifybool.cxx
 compilerplugins/clang/singlevalfields.cxx


More information about the Libreoffice-commits mailing list