From d2cac94bf572b95c17b57916dd540beb95c092d7 Mon Sep 17 00:00:00 2001 From: Samuel Benzaquen Date: Thu, 28 Aug 2014 15:49:06 +0000 Subject: [PATCH] Cache the memoization data for DynTypedNodes. Summary: Cache the memoization data for DynTypedNodes. It is free to do so on create(), but expensive to determine dynamically. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5101 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216671 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTTypeTraits.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/clang/AST/ASTTypeTraits.h b/include/clang/AST/ASTTypeTraits.h index 98cab648d5..0eff94c191 100644 --- a/include/clang/AST/ASTTypeTraits.h +++ b/include/clang/AST/ASTTypeTraits.h @@ -189,7 +189,7 @@ public: /// Note that this is not supported by all AST nodes. For AST nodes /// that don't have a pointer-defined identity inside the AST, this /// method returns NULL. - const void *getMemoizationData() const; + const void *getMemoizationData() const { return MemoizationData; } /// \brief Prints the node to the given output stream. void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const; @@ -242,6 +242,7 @@ private: static DynTypedNode create(const BaseT &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); + Result.MemoizationData = &Node; new (Result.Storage.buffer) const BaseT * (&Node); return Result; } @@ -257,6 +258,7 @@ private: static DynTypedNode create(const T &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); + Result.MemoizationData = &Node; new (Result.Storage.buffer) const T * (&Node); return Result; } @@ -272,12 +274,14 @@ private: static DynTypedNode create(const T &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); + Result.MemoizationData = nullptr; new (Result.Storage.buffer) T(Node); return Result; } }; ASTNodeKind NodeKind; + const void *MemoizationData; /// \brief Stores the data of the node. /// @@ -345,19 +349,6 @@ template struct DynTypedNode::BaseConverter { } }; -inline const void *DynTypedNode::getMemoizationData() const { - if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) { - return BaseConverter::get(NodeKind, Storage.buffer); - } else if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) { - return BaseConverter::get(NodeKind, Storage.buffer); - } else if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) { - return BaseConverter::get(NodeKind, Storage.buffer); - } else if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) { - return BaseConverter::get(NodeKind, Storage.buffer); - } - return nullptr; -} - } // end namespace ast_type_traits } // end namespace clang -- 2.50.1