Author: Kazu Hirata Date: 2026-09-16T22:10:25-07:00 New Revision: 00d7ba164f6b4c1c33efa7072c142f9df25bcf4d
URL: https://github.com/llvm/llvm-project/commit/00d7ba164f6b4c1c33efa7072c142f9df25bcf4d DIFF: https://github.com/llvm/llvm-project/commit/00d7ba164f6b4c1c33efa7072c142f9df25bcf4d.diff LOG: [clang] Unique OverflowBehaviorTypes with a UniquingSet (NFC) (#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 Added: Modified: clang/include/clang/AST/ASTContext.h clang/include/clang/AST/TypeBase.h clang/lib/AST/ASTContext.cpp Removed: ################################################################################ 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
