https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/224221
This patch migrates NamespaceAndPrefixStorages in ASTContext from llvm::FoldingSet to llvm::UniquingSet. NamespaceAndPrefixStorage keys on a pair of const NamespaceBaseDecl * and NestedNameSpecifier. Switching to UniquingSet allows us to look up storages with a typed key, eliminating FoldingSetNodeID serialization at lookup sites and removing NamespaceAndPrefixStorage::Profile. Assisted-by: Antigravity >From fa0bc395065423efbbd6aa6fb870796d22ccfb82 Mon Sep 17 00:00:00 2001 From: Kazu Hirata <[email protected]> Date: Sun, 13 Sep 2026 18:07:30 -0700 Subject: [PATCH] [clang] Unique NamespaceAndPrefixStorages with a UniquingSet (NFC) This patch migrates NamespaceAndPrefixStorages in ASTContext from llvm::FoldingSet to llvm::UniquingSet. NamespaceAndPrefixStorage keys on a pair of const NamespaceBaseDecl * and NestedNameSpecifier. Switching to UniquingSet allows us to look up storages with a typed key, eliminating FoldingSetNodeID serialization at lookup sites and removing NamespaceAndPrefixStorage::Profile. Assisted-by: Antigravity --- clang/include/clang/AST/ASTContext.h | 2 +- clang/include/clang/AST/NestedNameSpecifierBase.h | 8 ++------ clang/lib/AST/NestedNameSpecifier.cpp | 5 +---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 2f7d39599c477..d01712c58c04e 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -345,7 +345,7 @@ class ASTContext : public RefCountedBase<ASTContext> { /// Internal storage for NestedNameSpecifiers. /// /// This set is managed by the NestedNameSpecifier class. - mutable llvm::FoldingSet<NamespaceAndPrefixStorage> + mutable llvm::UniquingSet<NamespaceAndPrefixStorage> NamespaceAndPrefixStorages; /// A cache mapping from RecordDecls to ASTRecordLayouts. diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h index 5d883246252a1..f5d11e589a0b1 100644 --- a/clang/include/clang/AST/NestedNameSpecifierBase.h +++ b/clang/include/clang/AST/NestedNameSpecifierBase.h @@ -265,12 +265,8 @@ struct alignas(8) NamespaceAndPrefixStorage : NamespaceAndPrefix, NamespaceAndPrefixStorage(const NamespaceBaseDecl *Namespace, NestedNameSpecifier Prefix) : NamespaceAndPrefix{Namespace, Prefix} {} - void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Namespace, Prefix); } - static void Profile(llvm::FoldingSetNodeID &ID, - const NamespaceBaseDecl *Namespace, - NestedNameSpecifier Prefix) { - ID.AddPointer(Namespace); - Prefix.Profile(ID); + std::pair<const NamespaceBaseDecl *, NestedNameSpecifier> getKey() const { + return {Namespace, Prefix}; } }; diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp index b668a61021800..1eca017a81e24 100644 --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -38,12 +38,9 @@ const NamespaceAndPrefixStorage * NestedNameSpecifier::MakeNamespaceAndPrefixStorage( const ASTContext &Ctx, const NamespaceBaseDecl *Namespace, NestedNameSpecifier Prefix) { - llvm::FoldingSetNodeID ID; - NamespaceAndPrefixStorage::Profile(ID, Namespace, Prefix); - llvm::FoldingSetInsertToken Token; NamespaceAndPrefixStorage *S = - Ctx.NamespaceAndPrefixStorages.lookup(ID, Token); + Ctx.NamespaceAndPrefixStorages.lookup({Namespace, Prefix}, Token); if (!S) { S = new (Ctx, alignof(NamespaceAndPrefixStorage)) NamespaceAndPrefixStorage(Namespace, Prefix); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
