@@ -301,15 +301,22 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
301
301
// / Structure that captures data that is segregated into different
302
302
// / arenas.
303
303
struct Arena {
304
+ static_assert (alignof (TypeBase) >= 8 , " TypeBase not 8-byte aligned?" );
305
+ static_assert (alignof (TypeBase) > static_cast <unsigned >(
306
+ MetatypeRepresentation::Last_MetatypeRepresentation) + 1 ,
307
+ " Use std::pair for MetatypeTypes and ExistentialMetatypeTypes." );
308
+
304
309
llvm::DenseMap<Type, ErrorType *> ErrorTypesWithOriginal;
305
310
llvm::FoldingSet<TypeAliasType> TypeAliasTypes;
306
311
llvm::FoldingSet<TupleType> TupleTypes;
307
- llvm::DenseMap<std::pair<Type,char >, MetatypeType*> MetatypeTypes;
308
- llvm::DenseMap<std::pair<Type,char >,
312
+ llvm::DenseMap<llvm::PointerIntPair<TypeBase*, 3 , unsigned >,
313
+ MetatypeType*> MetatypeTypes;
314
+ llvm::DenseMap<llvm::PointerIntPair<TypeBase*, 3 , unsigned >,
309
315
ExistentialMetatypeType*> ExistentialMetatypeTypes;
310
316
llvm::DenseMap<Type, ArraySliceType*> ArraySliceTypes;
311
317
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
312
318
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
319
+ llvm::DenseMap<Type, ParenType*> SimpleParenTypes; // Most are simple
313
320
llvm::DenseMap<std::pair<Type, unsigned >, ParenType*> ParenTypes;
314
321
llvm::DenseMap<uintptr_t , ReferenceStorageType*> ReferenceStorageTypes;
315
322
llvm::DenseMap<Type, LValueType*> LValueTypes;
@@ -2088,6 +2095,7 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
2088
2095
llvm::capacity_in_bytes (ArraySliceTypes) +
2089
2096
llvm::capacity_in_bytes (DictionaryTypes) +
2090
2097
llvm::capacity_in_bytes (OptionalTypes) +
2098
+ llvm::capacity_in_bytes (SimpleParenTypes) +
2091
2099
llvm::capacity_in_bytes (ParenTypes) +
2092
2100
llvm::capacity_in_bytes (ReferenceStorageTypes) +
2093
2101
llvm::capacity_in_bytes (LValueTypes) +
@@ -3045,8 +3053,10 @@ ParenType *ParenType::get(const ASTContext &C, Type underlying,
3045
3053
3046
3054
auto properties = underlying->getRecursiveProperties ();
3047
3055
auto arena = getArena (properties);
3048
- ParenType *&Result =
3049
- C.getImpl ().getArena (arena).ParenTypes [{underlying, fl.toRaw ()}];
3056
+ auto flags = fl.toRaw ();
3057
+ ParenType *&Result = flags == 0
3058
+ ? C.getImpl ().getArena (arena).SimpleParenTypes [underlying]
3059
+ : C.getImpl ().getArena (arena).ParenTypes [{underlying, flags}];
3050
3060
if (Result == nullptr ) {
3051
3061
Result = new (C, arena) ParenType (underlying,
3052
3062
properties, fl);
@@ -3492,13 +3502,16 @@ MetatypeType *MetatypeType::get(Type T, Optional<MetatypeRepresentation> Repr,
3492
3502
auto properties = T->getRecursiveProperties ();
3493
3503
auto arena = getArena (properties);
3494
3504
3495
- char reprKey;
3505
+ unsigned reprKey;
3496
3506
if (Repr.hasValue ())
3497
- reprKey = static_cast <char >(*Repr) + 1 ;
3507
+ reprKey = static_cast <unsigned >(*Repr) + 1 ;
3498
3508
else
3499
3509
reprKey = 0 ;
3500
3510
3501
- MetatypeType *&Entry = Ctx.getImpl ().getArena (arena).MetatypeTypes [{T, reprKey}];
3511
+ auto pair = llvm::PointerIntPair<TypeBase*, 3 , unsigned >(T.getPointer (),
3512
+ reprKey);
3513
+
3514
+ MetatypeType *&Entry = Ctx.getImpl ().getArena (arena).MetatypeTypes [pair];
3502
3515
if (Entry) return Entry;
3503
3516
3504
3517
return Entry = new (Ctx, arena) MetatypeType (
@@ -3517,13 +3530,16 @@ ExistentialMetatypeType::get(Type T, Optional<MetatypeRepresentation> repr,
3517
3530
auto properties = T->getRecursiveProperties ();
3518
3531
auto arena = getArena (properties);
3519
3532
3520
- char reprKey;
3533
+ unsigned reprKey;
3521
3534
if (repr.hasValue ())
3522
- reprKey = static_cast <char >(*repr) + 1 ;
3535
+ reprKey = static_cast <unsigned >(*repr) + 1 ;
3523
3536
else
3524
3537
reprKey = 0 ;
3525
3538
3526
- auto &entry = ctx.getImpl ().getArena (arena).ExistentialMetatypeTypes [{T, reprKey}];
3539
+ auto pair = llvm::PointerIntPair<TypeBase*, 3 , unsigned >(T.getPointer (),
3540
+ reprKey);
3541
+
3542
+ auto &entry = ctx.getImpl ().getArena (arena).ExistentialMetatypeTypes [pair];
3527
3543
if (entry) return entry;
3528
3544
3529
3545
return entry = new (ctx, arena) ExistentialMetatypeType (
0 commit comments