https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/223939

This patch migrates OverflowBehaviorTypes in ASTContext from
llvm::FoldingSet to llvm::UniquingSet.

OverflowBehaviorType keys on a pair of QualType and
OverflowBehaviorKind.  Switching to UniquingSet allows us to look up
types with a typed key, eliminating FoldingSetNodeID serialization at
lookup sites and removing OverflowBehaviorType::Profile.

Assisted-by: Antigravity


>From 32392ff44f4e85d32661f905e7efee1efd08f344 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <[email protected]>
Date: Tue, 15 Sep 2026 10:34:21 -0700
Subject: [PATCH] [clang] Unique OverflowBehaviorTypes with a UniquingSet (NFC)

This patch migrates OverflowBehaviorTypes in ASTContext from
llvm::FoldingSet to llvm::UniquingSet.

OverflowBehaviorType keys on a pair of QualType and
OverflowBehaviorKind.  Switching to UniquingSet allows us to look up
types with a typed key, eliminating FoldingSetNodeID serialization at
lookup sites and removing OverflowBehaviorType::Profile.

Assisted-by: Antigravity
---
 clang/include/clang/AST/ASTContext.h |  2 +-
 clang/include/clang/AST/TypeBase.h   | 10 ++--------
 clang/lib/AST/ASTContext.cpp         |  8 +++-----
 3 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 8d48c2b7c2cba..2f7d39599c477 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -315,7 +315,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
   mutable llvm::ContextualFoldingSet<DependentBitIntType, ASTContext &>
       DependentBitIntTypes;
   mutable llvm::FoldingSet<BTFTagAttributedType> BTFTagAttributedTypes;
-  mutable llvm::FoldingSet<OverflowBehaviorType> OverflowBehaviorTypes;
+  mutable llvm::UniquingSet<OverflowBehaviorType> OverflowBehaviorTypes;
   mutable llvm::ContextualFoldingSet<HLSLAttributedResourceType, ASTContext &>
       HLSLAttributedResourceTypes;
   llvm::FoldingSet<HLSLInlineSpirvType> HLSLInlineSpirvTypes;
diff --git a/clang/include/clang/AST/TypeBase.h 
b/clang/include/clang/AST/TypeBase.h
index 3967f076112de..424a2afee84da 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -6822,14 +6822,8 @@ class OverflowBehaviorType : public Type, public 
llvm::FoldingSetNode {
 
   SplitQualType getSplitUnqualifiedType() const;
 
-  void Profile(llvm::FoldingSetNodeID &ID) {
-    Profile(ID, UnderlyingType, BehaviorKind);
-  }
-
-  static void Profile(llvm::FoldingSetNodeID &ID, QualType Underlying,
-                      OverflowBehaviorKind Kind) {
-    ID.AddPointer(Underlying.getAsOpaquePtr());
-    ID.AddInteger((int)Kind);
+  std::pair<QualType, OverflowBehaviorKind> getKey() const {
+    return {UnderlyingType, BehaviorKind};
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1e48613491943..ef3e6e87ec1fe 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5811,11 +5811,9 @@ QualType ASTContext::getOverflowBehaviorType(
   assert(!Underlying->isOverflowBehaviorType() &&
          "Cannot have underlying types that are themselves OBTs");
 
-  llvm::FoldingSetNodeID ID;
-  OverflowBehaviorType::Profile(ID, Underlying, Kind);
   llvm::FoldingSetInsertToken Token;
-
-  if (OverflowBehaviorType *OBT = OverflowBehaviorTypes.lookup(ID, Token)) {
+  if (OverflowBehaviorType *OBT =
+          OverflowBehaviorTypes.lookup({Underlying, Kind}, Token)) {
     return QualType(OBT, 0);
   }
 
@@ -5824,7 +5822,7 @@ QualType ASTContext::getOverflowBehaviorType(
     SplitQualType canonSplit = getCanonicalType(Underlying).split();
     Canonical = getOverflowBehaviorType(Kind, QualType(canonSplit.Ty, 0));
     Canonical = getQualifiedType(Canonical, canonSplit.Quals);
-    assert(!OverflowBehaviorTypes.lookup(ID, Token) &&
+    assert(!OverflowBehaviorTypes.lookup({Underlying, Kind}, Token) &&
            "Shouldn't be in the map");
   }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to