r189676 - Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.

Samuel Benzaquen sbenza at google.com
Fri Aug 30 08:09:52 PDT 2013


Author: sbenza
Date: Fri Aug 30 10:09:52 2013
New Revision: 189676

URL: http://llvm.org/viewvc/llvm-project?rev=189676&view=rev
Log:
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.

Summary:
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
This change reduces the number of sections in Registry.cpp.o by a little over 10%.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1557

Modified:
    cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
    cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h
    cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
    cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=189676&r1=189675&r2=189676&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Aug 30 10:09:52 2013
@@ -1231,8 +1231,6 @@ AnyOfVariadicOperator(const ast_type_tra
 template<typename T>
 BindableMatcher<T> makeAllOfComposite(
     ArrayRef<const Matcher<T> *> InnerMatchers) {
-  if (InnerMatchers.empty())
-    return BindableMatcher<T>(new TrueMatcher<T>);
   return BindableMatcher<T>(new VariadicOperatorMatcherInterface<T>(
       AllOfVariadicOperator, InnerMatchers));
 }

Modified: cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h?rev=189676&r1=189675&r2=189676&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h Fri Aug 30 10:09:52 2013
@@ -227,17 +227,6 @@ public:
   const VariantMatcher &getMatcher() const;
   void setMatcher(const VariantMatcher &Matcher);
 
-  /// \brief Shortcut functions.
-  template <class T>
-  bool hasTypedMatcher() const {
-    return isMatcher() && getMatcher().hasTypedMatcher<T>();
-  }
-
-  template <class T>
-  ast_matchers::internal::Matcher<T> getTypedMatcher() const {
-    return getMatcher().getTypedMatcher<T>();
-  }
-
   /// \brief String representation of the type of the value.
   std::string getTypeAsString() const;
 

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=189676&r1=189675&r2=189676&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h Fri Aug 30 10:09:52 2013
@@ -61,10 +61,10 @@ template <class T> struct ArgTypeTraits<
             ">").str();
   }
   static bool is(const VariantValue &Value) {
-    return Value.hasTypedMatcher<T>();
+    return Value.isMatcher() && Value.getMatcher().hasTypedMatcher<T>();
   }
   static ast_matchers::internal::Matcher<T> get(const VariantValue &Value) {
-    return Value.getTypedMatcher<T>();
+    return Value.getMatcher().getTypedMatcher<T>();
   }
 };
 
@@ -94,23 +94,20 @@ public:
 /// function into a MatcherCreateCallback.
 /// The marshaller is in charge of taking the VariantValue arguments, checking
 /// their types, unpacking them and calling the underlying function.
-template <typename FuncType>
 class FixedArgCountMatcherCreateCallback : public MatcherCreateCallback {
 public:
-  /// FIXME: Use void(*)() as FuncType on this interface to remove the template
-  /// argument of this class. The marshaller can cast the function pointer back
-  /// to the original type.
-  typedef VariantMatcher (*MarshallerType)(FuncType, StringRef,
-                                           const SourceRange &,
-                                           ArrayRef<ParserValue>,
-                                           Diagnostics *);
+  typedef VariantMatcher (*MarshallerType)(void (*Func)(),
+                                           StringRef MatcherName,
+                                           const SourceRange &NameRange,
+                                           ArrayRef<ParserValue> Args,
+                                           Diagnostics *Error);
 
   /// \param Marshaller Function to unpack the arguments and call \c Func
   /// \param Func Matcher construct function. This is the function that
   ///   compile-time matcher expressions would use to create the matcher.
-  FixedArgCountMatcherCreateCallback(MarshallerType Marshaller, FuncType Func,
+  FixedArgCountMatcherCreateCallback(MarshallerType Marshaller, void (*Func)(),
                                      StringRef MatcherName)
-      : Marshaller(Marshaller), Func(Func), MatcherName(MatcherName.str()) {}
+      : Marshaller(Marshaller), Func(Func), MatcherName(MatcherName) {}
 
   VariantMatcher run(const SourceRange &NameRange, ArrayRef<ParserValue> Args,
                      Diagnostics *Error) const {
@@ -119,7 +116,7 @@ public:
 
 private:
   const MarshallerType Marshaller;
-  const FuncType Func;
+  void (* const Func)();
   const std::string MatcherName;
 };
 
@@ -188,9 +185,7 @@ static void mergePolyMatchers(const Poly
 /// polymorphic matcher. For the former, we just construct the VariantMatcher.
 /// For the latter, we instantiate all the possible Matcher<T> of the poly
 /// matcher.
-template <typename T>
-static VariantMatcher
-outvalueToVariantMatcher(const ast_matchers::internal::Matcher<T> &Matcher) {
+static VariantMatcher outvalueToVariantMatcher(const DynTypedMatcher &Matcher) {
   return VariantMatcher::SingleMatcher(Matcher);
 }
 
@@ -207,38 +202,41 @@ static VariantMatcher outvalueToVariantM
 
 /// \brief 0-arg marshaller function.
 template <typename ReturnType>
-static VariantMatcher
-matcherMarshall0(ReturnType (*Func)(), StringRef MatcherName,
-                 const SourceRange &NameRange, ArrayRef<ParserValue> Args,
-                 Diagnostics *Error) {
+static VariantMatcher matcherMarshall0(void (*Func)(), StringRef MatcherName,
+                                       const SourceRange &NameRange,
+                                       ArrayRef<ParserValue> Args,
+                                       Diagnostics *Error) {
+  typedef ReturnType (*FuncType)();
   CHECK_ARG_COUNT(0);
-  return outvalueToVariantMatcher(Func());
+  return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)());
 }
 
 /// \brief 1-arg marshaller function.
 template <typename ReturnType, typename ArgType1>
-static VariantMatcher
-matcherMarshall1(ReturnType (*Func)(ArgType1), StringRef MatcherName,
-                 const SourceRange &NameRange, ArrayRef<ParserValue> Args,
-                 Diagnostics *Error) {
+static VariantMatcher matcherMarshall1(void (*Func)(), StringRef MatcherName,
+                                       const SourceRange &NameRange,
+                                       ArrayRef<ParserValue> Args,
+                                       Diagnostics *Error) {
+  typedef ReturnType (*FuncType)(ArgType1);
   CHECK_ARG_COUNT(1);
   CHECK_ARG_TYPE(0, ArgType1);
-  return outvalueToVariantMatcher(
-      Func(ArgTypeTraits<ArgType1>::get(Args[0].Value)));
+  return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)(
+      ArgTypeTraits<ArgType1>::get(Args[0].Value)));
 }
 
 /// \brief 2-arg marshaller function.
 template <typename ReturnType, typename ArgType1, typename ArgType2>
-static VariantMatcher
-matcherMarshall2(ReturnType (*Func)(ArgType1, ArgType2), StringRef MatcherName,
-                 const SourceRange &NameRange, ArrayRef<ParserValue> Args,
-                 Diagnostics *Error) {
+static VariantMatcher matcherMarshall2(void (*Func)(), StringRef MatcherName,
+                                       const SourceRange &NameRange,
+                                       ArrayRef<ParserValue> Args,
+                                       Diagnostics *Error) {
+  typedef ReturnType (*FuncType)(ArgType1, ArgType2);
   CHECK_ARG_COUNT(2);
   CHECK_ARG_TYPE(0, ArgType1);
   CHECK_ARG_TYPE(1, ArgType2);
-  return outvalueToVariantMatcher(
-      Func(ArgTypeTraits<ArgType1>::get(Args[0].Value),
-           ArgTypeTraits<ArgType2>::get(Args[1].Value)));
+  return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)(
+      ArgTypeTraits<ArgType1>::get(Args[0].Value),
+      ArgTypeTraits<ArgType2>::get(Args[1].Value)));
 }
 
 #undef CHECK_ARG_COUNT
@@ -385,16 +383,18 @@ private:
 template <typename ReturnType>
 MatcherCreateCallback *makeMatcherAutoMarshall(ReturnType (*Func)(),
                                                StringRef MatcherName) {
-  return new FixedArgCountMatcherCreateCallback<ReturnType (*)()>(
-      matcherMarshall0, Func, MatcherName);
+  return new FixedArgCountMatcherCreateCallback(
+      matcherMarshall0<ReturnType>, reinterpret_cast<void (*)()>(Func),
+      MatcherName);
 }
 
 /// \brief 1-arg overload
 template <typename ReturnType, typename ArgType1>
 MatcherCreateCallback *makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1),
                                                StringRef MatcherName) {
-  return new FixedArgCountMatcherCreateCallback<ReturnType (*)(ArgType1)>(
-      matcherMarshall1, Func, MatcherName);
+  return new FixedArgCountMatcherCreateCallback(
+      matcherMarshall1<ReturnType, ArgType1>,
+      reinterpret_cast<void (*)()>(Func), MatcherName);
 }
 
 /// \brief 2-arg overload
@@ -402,8 +402,9 @@ template <typename ReturnType, typename
 MatcherCreateCallback *makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1,
                                                                   ArgType2),
                                                StringRef MatcherName) {
-  return new FixedArgCountMatcherCreateCallback<
-      ReturnType (*)(ArgType1, ArgType2)>(matcherMarshall2, Func, MatcherName);
+  return new FixedArgCountMatcherCreateCallback(
+      matcherMarshall2<ReturnType, ArgType1, ArgType2>,
+      reinterpret_cast<void (*)()>(Func), MatcherName);
 }
 
 /// \brief Variadic overload.

Modified: cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp?rev=189676&r1=189675&r2=189676&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp Fri Aug 30 10:09:52 2013
@@ -28,8 +28,6 @@ TEST(VariantValueTest, Unsigned) {
 
   EXPECT_FALSE(Value.isString());
   EXPECT_FALSE(Value.isMatcher());
-  EXPECT_FALSE(Value.hasTypedMatcher<Decl>());
-  EXPECT_FALSE(Value.hasTypedMatcher<UnaryOperator>());
 }
 
 TEST(VariantValueTest, String) {
@@ -51,24 +49,24 @@ TEST(VariantValueTest, DynTypedMatcher)
   EXPECT_FALSE(Value.isString());
 
   EXPECT_TRUE(Value.isMatcher());
-  EXPECT_FALSE(Value.hasTypedMatcher<Decl>());
-  EXPECT_TRUE(Value.hasTypedMatcher<UnaryOperator>());
+  EXPECT_FALSE(Value.getMatcher().hasTypedMatcher<Decl>());
+  EXPECT_TRUE(Value.getMatcher().hasTypedMatcher<UnaryOperator>());
   EXPECT_EQ("Matcher<Stmt>", Value.getTypeAsString());
 
   // Can only convert to compatible matchers.
   Value = VariantMatcher::SingleMatcher(recordDecl());
   EXPECT_TRUE(Value.isMatcher());
-  EXPECT_TRUE(Value.hasTypedMatcher<Decl>());
-  EXPECT_FALSE(Value.hasTypedMatcher<UnaryOperator>());
+  EXPECT_TRUE(Value.getMatcher().hasTypedMatcher<Decl>());
+  EXPECT_FALSE(Value.getMatcher().hasTypedMatcher<UnaryOperator>());
   EXPECT_EQ("Matcher<Decl>", Value.getTypeAsString());
 
   Value = VariantMatcher::SingleMatcher(ignoringImpCasts(expr()));
   EXPECT_TRUE(Value.isMatcher());
-  EXPECT_FALSE(Value.hasTypedMatcher<Decl>());
-  EXPECT_FALSE(Value.hasTypedMatcher<Stmt>());
-  EXPECT_TRUE(Value.hasTypedMatcher<Expr>());
-  EXPECT_TRUE(Value.hasTypedMatcher<IntegerLiteral>());
-  EXPECT_FALSE(Value.hasTypedMatcher<GotoStmt>());
+  EXPECT_FALSE(Value.getMatcher().hasTypedMatcher<Decl>());
+  EXPECT_FALSE(Value.getMatcher().hasTypedMatcher<Stmt>());
+  EXPECT_TRUE(Value.getMatcher().hasTypedMatcher<Expr>());
+  EXPECT_TRUE(Value.getMatcher().hasTypedMatcher<IntegerLiteral>());
+  EXPECT_FALSE(Value.getMatcher().hasTypedMatcher<GotoStmt>());
   EXPECT_EQ("Matcher<Expr>", Value.getTypeAsString());
 }
 
@@ -84,8 +82,8 @@ TEST(VariantValueTest, Assignment) {
   EXPECT_FALSE(Value.isUnsigned());
   EXPECT_FALSE(Value.isString());
   EXPECT_TRUE(Value.isMatcher());
-  EXPECT_TRUE(Value.hasTypedMatcher<Decl>());
-  EXPECT_FALSE(Value.hasTypedMatcher<UnaryOperator>());
+  EXPECT_TRUE(Value.getMatcher().hasTypedMatcher<Decl>());
+  EXPECT_FALSE(Value.getMatcher().hasTypedMatcher<UnaryOperator>());
   EXPECT_EQ("Matcher<Decl>", Value.getTypeAsString());
 
   Value = 17;
@@ -104,32 +102,39 @@ TEST(VariantValueTest, Assignment) {
 TEST(VariantValueTest, Matcher) {
   EXPECT_TRUE(matches("class X {};", VariantValue(VariantMatcher::SingleMatcher(
                                                       recordDecl(hasName("X"))))
+                                         .getMatcher()
                                          .getTypedMatcher<Decl>()));
-  EXPECT_TRUE(matches("int x;",
-                      VariantValue(VariantMatcher::SingleMatcher(varDecl()))
-                          .getTypedMatcher<Decl>()));
+  EXPECT_TRUE(
+      matches("int x;", VariantValue(VariantMatcher::SingleMatcher(varDecl()))
+                            .getMatcher()
+                            .getTypedMatcher<Decl>()));
   EXPECT_TRUE(
       matches("int foo() { return 1 + 1; }",
               VariantValue(VariantMatcher::SingleMatcher(functionDecl()))
+                  .getMatcher()
                   .getTypedMatcher<Decl>()));
   // Can't get the wrong matcher.
   EXPECT_FALSE(VariantValue(VariantMatcher::SingleMatcher(varDecl()))
+                   .getMatcher()
                    .hasTypedMatcher<Stmt>());
 #if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST && !defined(_MSC_VER)
   // Trying to get the wrong matcher fails an assertion in Matcher<T>.  We don't
   // do this test when building with MSVC because its debug C runtime prints the
   // assertion failure message as a wide string, which gtest doesn't understand.
   EXPECT_DEATH(VariantValue(VariantMatcher::SingleMatcher(varDecl()))
+                   .getMatcher()
                    .getTypedMatcher<Stmt>(),
                "hasTypedMatcher");
 #endif
 
   EXPECT_FALSE(matches(
       "int x;", VariantValue(VariantMatcher::SingleMatcher(functionDecl()))
+                    .getMatcher()
                     .getTypedMatcher<Decl>()));
   EXPECT_FALSE(
       matches("int foo() { return 1 + 1; }",
               VariantValue(VariantMatcher::SingleMatcher(declRefExpr()))
+                  .getMatcher()
                   .getTypedMatcher<Stmt>()));
 }
 





More information about the cfe-commits mailing list