[PATCH] D149518: [clang][NFC] Optimize clang::ASTNodeKind::isBaseOf
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 5 21:40:52 PDT 2023
PiotrZSL updated this revision to Diff 520031.
PiotrZSL added a comment.
Rebase without changes, just because some testcase in this baseline looks to fail.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149518/new/
https://reviews.llvm.org/D149518
Files:
clang/include/clang/AST/ASTTypeTraits.h
clang/lib/AST/ASTTypeTraits.cpp
Index: clang/lib/AST/ASTTypeTraits.cpp
===================================================================
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -56,10 +56,23 @@
{NKI_None, "ObjCProtocolLoc"},
};
+bool ASTNodeKind::isBaseOf(ASTNodeKind Other) const {
+ return isBaseOf(KindId, Other.KindId);
+}
+
bool ASTNodeKind::isBaseOf(ASTNodeKind Other, unsigned *Distance) const {
return isBaseOf(KindId, Other.KindId, Distance);
}
+bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived) {
+ if (Base == NKI_None || Derived == NKI_None)
+ return false;
+ while (Derived != Base && Derived != NKI_None) {
+ Derived = AllKindInfo[Derived].ParentId;
+ }
+ return Derived == Base;
+}
+
bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived,
unsigned *Distance) {
if (Base == NKI_None || Derived == NKI_None) return false;
@@ -96,7 +109,7 @@
ASTNodeKind ASTNodeKind::getMostDerivedCommonAncestor(ASTNodeKind Kind1,
ASTNodeKind Kind2) {
NodeKindId Parent = Kind1.KindId;
- while (!isBaseOf(Parent, Kind2.KindId, nullptr) && Parent != NKI_None) {
+ while (!isBaseOf(Parent, Kind2.KindId) && Parent != NKI_None) {
Parent = AllKindInfo[Parent].ParentId;
}
return ASTNodeKind(Parent);
Index: clang/include/clang/AST/ASTTypeTraits.h
===================================================================
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -77,10 +77,13 @@
/// Returns \c true only for the default \c ASTNodeKind()
constexpr bool isNone() const { return KindId == NKI_None; }
+ /// Returns \c true if \c this is a base kind of (or same as) \c Other.
+ bool isBaseOf(ASTNodeKind Other) const;
+
/// Returns \c true if \c this is a base kind of (or same as) \c Other.
/// \param Distance If non-null, used to return the distance between \c this
/// and \c Other in the class hierarchy.
- bool isBaseOf(ASTNodeKind Other, unsigned *Distance = nullptr) const;
+ bool isBaseOf(ASTNodeKind Other, unsigned *Distance) const;
/// String representation of the kind.
StringRef asStringRef() const;
@@ -166,6 +169,10 @@
/// Use getFromNodeKind<T>() to construct the kind.
constexpr ASTNodeKind(NodeKindId KindId) : KindId(KindId) {}
+ /// Returns \c true if \c Base is a base kind of (or same as) \c
+ /// Derived.
+ static bool isBaseOf(NodeKindId Base, NodeKindId Derived);
+
/// Returns \c true if \c Base is a base kind of (or same as) \c
/// Derived.
/// \param Distance If non-null, used to return the distance between \c Base
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149518.520031.patch
Type: text/x-patch
Size: 2691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230506/fbd71dff/attachment-0001.bin>
More information about the cfe-commits
mailing list