summaryrefslogtreecommitdiffstats
path: root/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2014-10-09 19:28:18 +0000
committerSamuel Benzaquen <sbenza@google.com>2014-10-09 19:28:18 +0000
commit96039d727b3dfb190f23027aa62ec1718255ffa7 (patch)
treef704a2afa6ad3b33eae5e80926beb1f381cdbc16 /clang/lib/ASTMatchers/ASTMatchersInternal.cpp
parent33860a8f09f75797226d1fee1a5af19dc49b6906 (diff)
downloadbcm5719-llvm-96039d727b3dfb190f23027aa62ec1718255ffa7.tar.gz
bcm5719-llvm-96039d727b3dfb190f23027aa62ec1718255ffa7.zip
Special case 0 and 1 matcher in makeAllOfComposite().
Summary: Remove unnecessary wrapping for the 0 and 1 matcher cases of makeAllOfComposite(). We don't need a variadic wrapper for those cases. Refactor TrueMatcher to take advandage of the new conversions between DynTypedMatcher and Matcher<T>. Also, make it a singleton. This change improves our clang-tidy related benchmarks by ~12%. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5675 llvm-svn: 219431
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchersInternal.cpp')
-rw-r--r--clang/lib/ASTMatchers/ASTMatchersInternal.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index ec60f0d9498..f6fd5ba2a3f 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -13,6 +13,7 @@
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "llvm/Support/ManagedStatic.h"
namespace clang {
namespace ast_matchers {
@@ -64,6 +65,25 @@ class IdDynMatcher : public DynMatcherInterface {
const IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher;
};
+/// \brief A matcher that always returns true.
+///
+/// We only ever need one instance of this matcher, so we create a global one
+/// and reuse it to reduce the overhead of the matcher and increase the chance
+/// of cache hits.
+struct TrueMatcherImpl {
+ TrueMatcherImpl() : Instance(new Impl) {}
+ const IntrusiveRefCntPtr<DynMatcherInterface> Instance;
+
+ class Impl : public DynMatcherInterface {
+ public:
+ bool dynMatches(const ast_type_traits::DynTypedNode &, ASTMatchFinder *,
+ BoundNodesTreeBuilder *) const override {
+ return true;
+ }
+ };
+};
+static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance;
+
} // namespace
DynTypedMatcher DynTypedMatcher::constructVariadic(
@@ -83,6 +103,11 @@ DynTypedMatcher DynTypedMatcher::constructVariadic(
return Result;
}
+DynTypedMatcher DynTypedMatcher::trueMatcher(
+ ast_type_traits::ASTNodeKind NodeKind) {
+ return DynTypedMatcher(NodeKind, NodeKind, TrueMatcherInstance->Instance);
+}
+
DynTypedMatcher DynTypedMatcher::dynCastTo(
const ast_type_traits::ASTNodeKind Kind) const {
auto Copy = *this;
OpenPOWER on IntegriCloud