diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -211,7 +211,7 @@ mutable SmallVector Types; mutable llvm::FoldingSet ExtQualNodes; mutable llvm::FoldingSet ComplexTypes; - mutable llvm::FoldingSet PointerTypes; + mutable llvm::FoldingSet PointerTypes{GeneralTypesLog2InitSize}; mutable llvm::FoldingSet AdjustedTypes; mutable llvm::FoldingSet BlockPointerTypes; mutable llvm::FoldingSet LValueReferenceTypes; @@ -243,9 +243,10 @@ SubstTemplateTypeParmPackTypes; mutable llvm::ContextualFoldingSet TemplateSpecializationTypes; - mutable llvm::FoldingSet ParenTypes; + mutable llvm::FoldingSet ParenTypes{GeneralTypesLog2InitSize}; mutable llvm::FoldingSet UsingTypes; - mutable llvm::FoldingSet ElaboratedTypes; + mutable llvm::FoldingSet ElaboratedTypes{ + GeneralTypesLog2InitSize}; mutable llvm::FoldingSet DependentNameTypes; mutable llvm::ContextualFoldingSet @@ -466,6 +467,10 @@ }; llvm::DenseMap ModuleInitializers; + static constexpr unsigned ConstantArrayTypesLog2InitSize = 8; + static constexpr unsigned GeneralTypesLog2InitSize = 9; + static constexpr unsigned FunctionProtoTypesLog2InitSize = 12; + ASTContext &this_() { return *this; } public: diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -973,7 +973,8 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, SelectorTable &sels, Builtin::Context &builtins, TranslationUnitKind TUKind) - : ConstantArrayTypes(this_()), FunctionProtoTypes(this_()), + : ConstantArrayTypes(this_(), ConstantArrayTypesLog2InitSize), + FunctionProtoTypes(this_(), FunctionProtoTypesLog2InitSize), TemplateSpecializationTypes(this_()), DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()), SubstTemplateTemplateParmPacks(this_()), diff --git a/clang/lib/CodeGen/CodeGenTypes.h b/clang/lib/CodeGen/CodeGenTypes.h --- a/clang/lib/CodeGen/CodeGenTypes.h +++ b/clang/lib/CodeGen/CodeGenTypes.h @@ -76,7 +76,7 @@ llvm::DenseMap RecordDeclTypes; /// Hold memoized CGFunctionInfo results. - llvm::FoldingSet FunctionInfos; + llvm::FoldingSet FunctionInfos{FunctionInfosLog2InitSize}; /// This set keeps track of records that we're currently converting /// to an IR type. For example, when converting: @@ -98,6 +98,7 @@ llvm::SmallSet RecordsWithOpaqueMemberPointers; + static constexpr unsigned FunctionInfosLog2InitSize = 9; /// Helper for ConvertType. llvm::Type *ConvertFunctionTypeInternal(QualType FT);