r222131 - Remove VariadicOperatorMatcherInterface as it is redundant with logic from DynTypedMatcher.
Samuel Benzaquen
sbenza at google.com
Mon Nov 17 06:55:50 PST 2014
Author: sbenza
Date: Mon Nov 17 08:55:49 2014
New Revision: 222131
URL: http://llvm.org/viewvc/llvm-project?rev=222131&view=rev
Log:
Remove VariadicOperatorMatcherInterface as it is redundant with logic from DynTypedMatcher.
Summary:
The generic variadic matcher is faster (one less virtual function call
per match) and doesn't require template instantiations which reduces
compile time and binary size.
Registry.cpp.o generates ~14% less symbols and compiles ~7.5% faster.
The change also speeds up our clang-tidy benchmark by ~2%.
Reviewers: klimek
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D6278
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
cfe/trunk/lib/ASTMatchers/Dynamic/VariantValue.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=222131&r1=222130&r2=222131&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Mon Nov 17 08:55:49 2014
@@ -1121,36 +1121,11 @@ private:
/// \brief VariadicOperatorMatcher related types.
/// @{
-/// \brief Function signature for any variadic operator. It takes the inner
-/// matchers as an array of DynTypedMatcher.
-typedef bool (*VariadicOperatorFunction)(
- const ast_type_traits::DynTypedNode DynNode, ASTMatchFinder *Finder,
- BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers);
-
-/// \brief \c MatcherInterface<T> implementation for an variadic operator.
-template <typename T>
-class VariadicOperatorMatcherInterface : public MatcherInterface<T> {
-public:
- VariadicOperatorMatcherInterface(VariadicOperatorFunction Func,
- std::vector<DynTypedMatcher> InnerMatchers)
- : Func(Func), InnerMatchers(std::move(InnerMatchers)) {}
-
- bool matches(const T &Node, ASTMatchFinder *Finder,
- BoundNodesTreeBuilder *Builder) const override {
- return Func(ast_type_traits::DynTypedNode::create(Node), Finder, Builder,
- InnerMatchers);
- }
-
-private:
- const VariadicOperatorFunction Func;
- const std::vector<DynTypedMatcher> InnerMatchers;
-};
-
/// \brief "No argument" placeholder to use as template paratemers.
struct VariadicOperatorNoArg {};
-/// \brief Polymorphic matcher object that uses a \c VariadicOperatorFunction
-/// operator.
+/// \brief Polymorphic matcher object that uses a \c
+/// DynTypedMatcher::VariadicOperatorFunction operator.
///
/// Input matchers can have any type (including other polymorphic matcher
/// types), and the actual Matcher<T> is generated on demand with an implicit
@@ -1165,7 +1140,8 @@ template <typename P1, typename P2 = Var
typename P9 = VariadicOperatorNoArg>
class VariadicOperatorMatcher {
public:
- VariadicOperatorMatcher(VariadicOperatorFunction Func, const P1 &Param1,
+ VariadicOperatorMatcher(DynTypedMatcher::VariadicOperatorFunction Func,
+ const P1 &Param1,
const P2 &Param2 = VariadicOperatorNoArg(),
const P3 &Param3 = VariadicOperatorNoArg(),
const P4 &Param4 = VariadicOperatorNoArg(),
@@ -1189,9 +1165,8 @@ public:
addMatcher<T>(Param7, Matchers);
addMatcher<T>(Param8, Matchers);
addMatcher<T>(Param9, Matchers);
- // FIXME: Use DynTypedMatcher::constructVariadic() instead.
- return Matcher<T>(
- new VariadicOperatorMatcherInterface<T>(Func, std::move(Matchers)));
+ return DynTypedMatcher::constructVariadic(Func, std::move(Matchers))
+ .template unconditionalConvertTo<T>();
}
private:
@@ -1206,7 +1181,7 @@ private:
static void addMatcher(VariadicOperatorNoArg,
std::vector<DynTypedMatcher> &Matchers) {}
- const VariadicOperatorFunction Func;
+ const DynTypedMatcher::VariadicOperatorFunction Func;
const P1 Param1;
const P2 Param2;
const P3 Param3;
@@ -1224,7 +1199,7 @@ private:
/// It supports 1-9 argument overloaded operator(). More can be added if needed.
template <unsigned MinCount, unsigned MaxCount>
struct VariadicOperatorMatcherFunc {
- VariadicOperatorFunction Func;
+ DynTypedMatcher::VariadicOperatorFunction Func;
template <unsigned Count, typename T>
struct EnableIfValidArity
@@ -1350,9 +1325,9 @@ BindableMatcher<T> makeAllOfComposite(
for (const auto *InnerMatcher : InnerMatchers) {
DynMatchers.push_back(*InnerMatcher);
}
- // FIXME: Use DynTypedMatcher::constructVariadic() instead.
- return BindableMatcher<T>(new VariadicOperatorMatcherInterface<T>(
- AllOfVariadicOperator, std::move(DynMatchers)));
+ return BindableMatcher<T>(DynTypedMatcher::constructVariadic(
+ AllOfVariadicOperator, std::move(DynMatchers))
+ .template unconditionalConvertTo<T>());
}
/// \brief Creates a Matcher<T> that matches if
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=222131&r1=222130&r2=222131&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/Dynamic/VariantValue.h Mon Nov 17 08:55:49 2014
@@ -106,9 +106,9 @@ class VariantMatcher {
/// \brief Constructs a variadic typed matcher from \p InnerMatchers.
/// Will try to convert each inner matcher to the destination type and
/// return llvm::None if it fails to do so.
- llvm::Optional<DynTypedMatcher> constructVariadicOperator(
- ast_matchers::internal::VariadicOperatorFunction Func,
- ArrayRef<VariantMatcher> InnerMatchers) const;
+ llvm::Optional<DynTypedMatcher>
+ constructVariadicOperator(DynTypedMatcher::VariadicOperatorFunction Func,
+ ArrayRef<VariantMatcher> InnerMatchers) const;
protected:
~MatcherOps() {}
@@ -147,9 +147,9 @@ public:
/// \brief Creates a 'variadic' operator matcher.
///
/// It will bind to the appropriate type on getTypedMatcher<T>().
- static VariantMatcher VariadicOperatorMatcher(
- ast_matchers::internal::VariadicOperatorFunction Func,
- std::vector<VariantMatcher> Args);
+ static VariantMatcher
+ VariadicOperatorMatcher(DynTypedMatcher::VariadicOperatorFunction Func,
+ std::vector<VariantMatcher> Args);
/// \brief Makes the matcher the "null" matcher.
void reset();
Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=222131&r1=222130&r2=222131&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Mon Nov 17 08:55:49 2014
@@ -32,7 +32,7 @@ namespace {
class VariadicMatcher : public DynMatcherInterface {
public:
- VariadicMatcher(VariadicOperatorFunction Func,
+ VariadicMatcher(DynTypedMatcher::VariadicOperatorFunction Func,
std::vector<DynTypedMatcher> InnerMatchers)
: Func(Func), InnerMatchers(std::move(InnerMatchers)) {}
@@ -43,7 +43,7 @@ class VariadicMatcher : public DynMatche
}
private:
- VariadicOperatorFunction Func;
+ DynTypedMatcher::VariadicOperatorFunction Func;
std::vector<DynTypedMatcher> InnerMatchers;
};
@@ -86,7 +86,8 @@ static llvm::ManagedStatic<TrueMatcherIm
} // namespace
DynTypedMatcher DynTypedMatcher::constructVariadic(
- VariadicOperatorFunction Func, std::vector<DynTypedMatcher> InnerMatchers) {
+ DynTypedMatcher::VariadicOperatorFunction Func,
+ std::vector<DynTypedMatcher> InnerMatchers) {
assert(InnerMatchers.size() > 0 && "Array must not be empty.");
assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(),
[&InnerMatchers](const DynTypedMatcher &M) {
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=222131&r1=222130&r2=222131&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h Mon Nov 17 08:55:49 2014
@@ -556,7 +556,7 @@ private:
/// \brief Variadic operator marshaller function.
class VariadicOperatorMatcherDescriptor : public MatcherDescriptor {
public:
- typedef ast_matchers::internal::VariadicOperatorFunction VarFunc;
+ typedef DynTypedMatcher::VariadicOperatorFunction VarFunc;
VariadicOperatorMatcherDescriptor(unsigned MinCount, unsigned MaxCount,
VarFunc Func, StringRef MatcherName)
: MinCount(MinCount), MaxCount(MaxCount), Func(Func),
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/VariantValue.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/VariantValue.cpp?rev=222131&r1=222130&r2=222131&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/VariantValue.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/VariantValue.cpp Mon Nov 17 08:55:49 2014
@@ -58,7 +58,7 @@ VariantMatcher::MatcherOps::canConstruct
llvm::Optional<DynTypedMatcher>
VariantMatcher::MatcherOps::constructVariadicOperator(
- ast_matchers::internal::VariadicOperatorFunction Func,
+ DynTypedMatcher::VariadicOperatorFunction Func,
ArrayRef<VariantMatcher> InnerMatchers) const {
std::vector<DynTypedMatcher> DynMatchers;
for (const auto &InnerMatcher : InnerMatchers) {
@@ -176,7 +176,7 @@ public:
class VariantMatcher::VariadicOpPayload : public VariantMatcher::Payload {
public:
- VariadicOpPayload(ast_matchers::internal::VariadicOperatorFunction Func,
+ VariadicOpPayload(DynTypedMatcher::VariadicOperatorFunction Func,
std::vector<VariantMatcher> Args)
: Func(Func), Args(std::move(Args)) {}
@@ -209,7 +209,7 @@ public:
}
private:
- const ast_matchers::internal::VariadicOperatorFunction Func;
+ const DynTypedMatcher::VariadicOperatorFunction Func;
const std::vector<VariantMatcher> Args;
};
@@ -225,7 +225,7 @@ VariantMatcher::PolymorphicMatcher(std::
}
VariantMatcher VariantMatcher::VariadicOperatorMatcher(
- ast_matchers::internal::VariadicOperatorFunction Func,
+ DynTypedMatcher::VariadicOperatorFunction Func,
std::vector<VariantMatcher> Args) {
return VariantMatcher(new VariadicOpPayload(Func, std::move(Args)));
}
More information about the cfe-commits
mailing list