Skip to content

Commit 6d209bd

Browse files
authored
[NFC][clang] change remaining context-dependent type nodes to ContextualFoldingSet (llvm#67751)
With this change, we are avoiding storing one pointer per Type Node instance, for the cost of one extra pointer per ASTContext, which is negligible. After we introduced `ContextualFoldingSet` a long time ago, we never went back and updated these existing users. This patch corrects that.
1 parent 5064ca8 commit 6d209bd

File tree

4 files changed

+90
-111
lines changed

4 files changed

+90
-111
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,25 @@ class ASTContext : public RefCountedBase<ASTContext> {
195195
ConstantArrayTypes;
196196
mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
197197
mutable std::vector<VariableArrayType*> VariableArrayTypes;
198-
mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
199-
mutable llvm::FoldingSet<DependentSizedExtVectorType>
200-
DependentSizedExtVectorTypes;
201-
mutable llvm::FoldingSet<DependentAddressSpaceType>
198+
mutable llvm::ContextualFoldingSet<DependentSizedArrayType, ASTContext &>
199+
DependentSizedArrayTypes;
200+
mutable llvm::ContextualFoldingSet<DependentSizedExtVectorType, ASTContext &>
201+
DependentSizedExtVectorTypes;
202+
mutable llvm::ContextualFoldingSet<DependentAddressSpaceType, ASTContext &>
202203
DependentAddressSpaceTypes;
203204
mutable llvm::FoldingSet<VectorType> VectorTypes;
204-
mutable llvm::FoldingSet<DependentVectorType> DependentVectorTypes;
205+
mutable llvm::ContextualFoldingSet<DependentVectorType, ASTContext &>
206+
DependentVectorTypes;
205207
mutable llvm::FoldingSet<ConstantMatrixType> MatrixTypes;
206-
mutable llvm::FoldingSet<DependentSizedMatrixType> DependentSizedMatrixTypes;
208+
mutable llvm::ContextualFoldingSet<DependentSizedMatrixType, ASTContext &>
209+
DependentSizedMatrixTypes;
207210
mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
208211
mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
209212
FunctionProtoTypes;
210-
mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
211-
mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
213+
mutable llvm::ContextualFoldingSet<DependentTypeOfExprType, ASTContext &>
214+
DependentTypeOfExprTypes;
215+
mutable llvm::ContextualFoldingSet<DependentDecltypeType, ASTContext &>
216+
DependentDecltypeTypes;
212217
mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
213218
mutable llvm::FoldingSet<ObjCTypeParamType> ObjCTypeParamTypes;
214219
mutable llvm::FoldingSet<SubstTemplateTypeParmType>
@@ -238,7 +243,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
238243
mutable llvm::FoldingSet<AttributedType> AttributedTypes;
239244
mutable llvm::FoldingSet<PipeType> PipeTypes;
240245
mutable llvm::FoldingSet<BitIntType> BitIntTypes;
241-
mutable llvm::FoldingSet<DependentBitIntType> DependentBitIntTypes;
246+
mutable llvm::ContextualFoldingSet<DependentBitIntType, ASTContext &>
247+
DependentBitIntTypes;
242248
llvm::FoldingSet<BTFTagAttributedType> BTFTagAttributedTypes;
243249

244250
mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;

clang/include/clang/AST/Type.h

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,8 +3289,6 @@ class VariableArrayType : public ArrayType {
32893289
class DependentSizedArrayType : public ArrayType {
32903290
friend class ASTContext; // ASTContext creates these.
32913291

3292-
const ASTContext &Context;
3293-
32943292
/// An assignment expression that will instantiate to the
32953293
/// size of the array.
32963294
///
@@ -3301,8 +3299,8 @@ class DependentSizedArrayType : public ArrayType {
33013299
/// The range spanned by the left and right array brackets.
33023300
SourceRange Brackets;
33033301

3304-
DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
3305-
Expr *e, ArraySizeModifier sm, unsigned tq,
3302+
DependentSizedArrayType(QualType et, QualType can, Expr *e,
3303+
ArraySizeModifier sm, unsigned tq,
33063304
SourceRange brackets);
33073305

33083306
public:
@@ -3325,7 +3323,7 @@ class DependentSizedArrayType : public ArrayType {
33253323
return T->getTypeClass() == DependentSizedArray;
33263324
}
33273325

3328-
void Profile(llvm::FoldingSetNodeID &ID) {
3326+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
33293327
Profile(ID, Context, getElementType(),
33303328
getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
33313329
}
@@ -3349,14 +3347,12 @@ class DependentSizedArrayType : public ArrayType {
33493347
class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
33503348
friend class ASTContext;
33513349

3352-
const ASTContext &Context;
33533350
Expr *AddrSpaceExpr;
33543351
QualType PointeeType;
33553352
SourceLocation loc;
33563353

3357-
DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType,
3358-
QualType can, Expr *AddrSpaceExpr,
3359-
SourceLocation loc);
3354+
DependentAddressSpaceType(QualType PointeeType, QualType can,
3355+
Expr *AddrSpaceExpr, SourceLocation loc);
33603356

33613357
public:
33623358
Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
@@ -3370,7 +3366,7 @@ class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
33703366
return T->getTypeClass() == DependentAddressSpace;
33713367
}
33723368

3373-
void Profile(llvm::FoldingSetNodeID &ID) {
3369+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
33743370
Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
33753371
}
33763372

@@ -3391,16 +3387,15 @@ class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
33913387
class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
33923388
friend class ASTContext;
33933389

3394-
const ASTContext &Context;
33953390
Expr *SizeExpr;
33963391

33973392
/// The element type of the array.
33983393
QualType ElementType;
33993394

34003395
SourceLocation loc;
34013396

3402-
DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
3403-
QualType can, Expr *SizeExpr, SourceLocation loc);
3397+
DependentSizedExtVectorType(QualType ElementType, QualType can,
3398+
Expr *SizeExpr, SourceLocation loc);
34043399

34053400
public:
34063401
Expr *getSizeExpr() const { return SizeExpr; }
@@ -3414,7 +3409,7 @@ class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
34143409
return T->getTypeClass() == DependentSizedExtVector;
34153410
}
34163411

3417-
void Profile(llvm::FoldingSetNodeID &ID) {
3412+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
34183413
Profile(ID, Context, getElementType(), getSizeExpr());
34193414
}
34203415

@@ -3513,14 +3508,12 @@ class VectorType : public Type, public llvm::FoldingSetNode {
35133508
class DependentVectorType : public Type, public llvm::FoldingSetNode {
35143509
friend class ASTContext;
35153510

3516-
const ASTContext &Context;
35173511
QualType ElementType;
35183512
Expr *SizeExpr;
35193513
SourceLocation Loc;
35203514

3521-
DependentVectorType(const ASTContext &Context, QualType ElementType,
3522-
QualType CanonType, Expr *SizeExpr,
3523-
SourceLocation Loc, VectorType::VectorKind vecKind);
3515+
DependentVectorType(QualType ElementType, QualType CanonType, Expr *SizeExpr,
3516+
SourceLocation Loc, VectorType::VectorKind vecKind);
35243517

35253518
public:
35263519
Expr *getSizeExpr() const { return SizeExpr; }
@@ -3537,7 +3530,7 @@ class DependentVectorType : public Type, public llvm::FoldingSetNode {
35373530
return T->getTypeClass() == DependentVector;
35383531
}
35393532

3540-
void Profile(llvm::FoldingSetNodeID &ID) {
3533+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
35413534
Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
35423535
}
35433536

@@ -3719,15 +3712,13 @@ class ConstantMatrixType final : public MatrixType {
37193712
class DependentSizedMatrixType final : public MatrixType {
37203713
friend class ASTContext;
37213714

3722-
const ASTContext &Context;
37233715
Expr *RowExpr;
37243716
Expr *ColumnExpr;
37253717

37263718
SourceLocation loc;
37273719

3728-
DependentSizedMatrixType(const ASTContext &Context, QualType ElementType,
3729-
QualType CanonicalType, Expr *RowExpr,
3730-
Expr *ColumnExpr, SourceLocation loc);
3720+
DependentSizedMatrixType(QualType ElementType, QualType CanonicalType,
3721+
Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc);
37313722

37323723
public:
37333724
Expr *getRowExpr() const { return RowExpr; }
@@ -3738,7 +3729,7 @@ class DependentSizedMatrixType final : public MatrixType {
37383729
return T->getTypeClass() == DependentSizedMatrix;
37393730
}
37403731

3741-
void Profile(llvm::FoldingSetNodeID &ID) {
3732+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
37423733
Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr());
37433734
}
37443735

@@ -4749,15 +4740,12 @@ class TypeOfExprType : public Type {
47494740
/// This class is used internally by the ASTContext to manage
47504741
/// canonical, dependent types, only. Clients will only see instances
47514742
/// of this class via TypeOfExprType nodes.
4752-
class DependentTypeOfExprType
4753-
: public TypeOfExprType, public llvm::FoldingSetNode {
4754-
const ASTContext &Context;
4755-
4743+
class DependentTypeOfExprType : public TypeOfExprType,
4744+
public llvm::FoldingSetNode {
47564745
public:
4757-
DependentTypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind)
4758-
: TypeOfExprType(E, Kind), Context(Context) {}
4746+
DependentTypeOfExprType(Expr *E, TypeOfKind Kind) : TypeOfExprType(E, Kind) {}
47594747

4760-
void Profile(llvm::FoldingSetNodeID &ID) {
4748+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
47614749
Profile(ID, Context, getUnderlyingExpr(),
47624750
getKind() == TypeOfKind::Unqualified);
47634751
}
@@ -4833,12 +4821,10 @@ class DecltypeType : public Type {
48334821
/// canonical, dependent types, only. Clients will only see instances
48344822
/// of this class via DecltypeType nodes.
48354823
class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
4836-
const ASTContext &Context;
4837-
48384824
public:
4839-
DependentDecltypeType(const ASTContext &Context, Expr *E);
4825+
DependentDecltypeType(Expr *E, QualType UnderlyingTpe);
48404826

4841-
void Profile(llvm::FoldingSetNodeID &ID) {
4827+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
48424828
Profile(ID, Context, getUnderlyingExpr());
48434829
}
48444830

@@ -6657,12 +6643,10 @@ class BitIntType final : public Type, public llvm::FoldingSetNode {
66576643

66586644
class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
66596645
friend class ASTContext;
6660-
const ASTContext &Context;
66616646
llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned;
66626647

66636648
protected:
6664-
DependentBitIntType(const ASTContext &Context, bool IsUnsigned,
6665-
Expr *NumBits);
6649+
DependentBitIntType(bool IsUnsigned, Expr *NumBits);
66666650

66676651
public:
66686652
bool isUnsigned() const;
@@ -6672,7 +6656,7 @@ class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
66726656
bool isSugared() const { return false; }
66736657
QualType desugar() const { return QualType(this, 0); }
66746658

6675-
void Profile(llvm::FoldingSetNodeID &ID) {
6659+
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
66766660
Profile(ID, Context, isUnsigned(), getNumBitsExpr());
66776661
}
66786662
static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,

0 commit comments

Comments
 (0)