@@ -55,7 +55,7 @@ Alignment IRGenModule::getCappedAlignment(Alignment align) {
55
55
return std::min (align, Alignment (MaximumAlignment));
56
56
}
57
57
58
- llvm::DenseMap<TypeBase*, TypeCacheEntry > &
58
+ llvm::DenseMap<TypeBase *, const TypeInfo * > &
59
59
TypeConverter::Types_t::getCacheFor (bool isDependent, bool completelyFragile) {
60
60
if (completelyFragile) {
61
61
return (isDependent
@@ -1128,12 +1128,13 @@ GenericEnvironment *IRGenModule::getGenericEnvironment() {
1128
1128
1129
1129
// / Add a temporary forward declaration for a type. This will live
1130
1130
// / only until a proper mapping is added.
1131
- void TypeConverter::addForwardDecl (TypeBase *key, llvm::Type *type ) {
1131
+ void TypeConverter::addForwardDecl (TypeBase *key) {
1132
1132
assert (key->isCanonical ());
1133
1133
assert (!key->hasTypeParameter ());
1134
1134
auto &Cache = Types.getCacheFor (/* isDependent*/ false , CompletelyFragile);
1135
- assert (!Cache.count (key) && " entry already exists for type!" );
1136
- Cache.insert (std::make_pair (key, type));
1135
+ auto result = Cache.insert (std::make_pair (key, nullptr ));
1136
+ assert (result.second && " entry already exists for type!" );
1137
+ (void ) result;
1137
1138
}
1138
1139
1139
1140
const TypeInfo &IRGenModule::getWitnessTablePtrTypeInfo () {
@@ -1322,17 +1323,9 @@ llvm::Type *IRGenModule::getStorageType(SILType T) {
1322
1323
return getStorageTypeForLowered (T.getASTType ());
1323
1324
}
1324
1325
1325
- // / Get the storage type for the given type. Note that, unlike
1326
- // / fetching the type info and asking it for the storage type, this
1327
- // / operation will succeed for forward-declarations.
1326
+ // / Get the storage type for the given type.
1328
1327
llvm::Type *IRGenModule::getStorageTypeForLowered (CanType T) {
1329
- // TODO: we can avoid creating entries for some obvious cases here.
1330
- auto entry = Types.getTypeEntry (T);
1331
- if (auto ti = entry.dyn_cast <const TypeInfo*>()) {
1332
- return ti->getStorageType ();
1333
- } else {
1334
- return entry.get <llvm::Type*>();
1335
- }
1328
+ return Types.getTypeEntry (T)->getStorageType ();
1336
1329
}
1337
1330
1338
1331
// / Get the type information for the given type, which may not have
@@ -1370,9 +1363,7 @@ const TypeInfo &IRGenModule::getTypeInfoForLowered(CanType T) {
1370
1363
1371
1364
// /
1372
1365
const TypeInfo &TypeConverter::getCompleteTypeInfo (CanType T) {
1373
- auto entry = getTypeEntry (T);
1374
- assert (entry.is <const TypeInfo*>() && " getting TypeInfo recursively!" );
1375
- return *entry.get <const TypeInfo*>();
1366
+ return *getTypeEntry (T);
1376
1367
}
1377
1368
1378
1369
ArchetypeType *TypeConverter::getExemplarArchetype (ArchetypeType *t) {
@@ -1428,7 +1419,7 @@ void TypeConverter::popCompletelyFragile() {
1428
1419
CompletelyFragile = false ;
1429
1420
}
1430
1421
1431
- TypeCacheEntry TypeConverter::getTypeEntry (CanType canonicalTy) {
1422
+ const TypeInfo * TypeConverter::getTypeEntry (CanType canonicalTy) {
1432
1423
// Cache this entry in the dependent or independent cache appropriate to it.
1433
1424
auto &Cache = Types.getCacheFor (canonicalTy->hasTypeParameter (),
1434
1425
CompletelyFragile);
@@ -1467,22 +1458,12 @@ TypeCacheEntry TypeConverter::getTypeEntry(CanType canonicalTy) {
1467
1458
}
1468
1459
1469
1460
// Convert the type.
1470
- TypeCacheEntry convertedEntry = convertType (exemplarTy);
1471
- auto convertedTI = convertedEntry.dyn_cast <const TypeInfo*>();
1472
-
1473
- // If that gives us a forward declaration (which can happen with
1474
- // bound generic types), don't propagate that into the cache here,
1475
- // because we won't know how to clear it later.
1476
- if (!convertedTI) {
1477
- return convertedEntry;
1478
- }
1461
+ auto *convertedTI = convertType (exemplarTy);
1479
1462
1480
1463
// Cache the entry under the original type and the exemplar type, so that
1481
1464
// we can avoid relowering equivalent types.
1482
- auto insertEntry = [&](TypeCacheEntry &entry) {
1483
- assert (entry == TypeCacheEntry () ||
1484
- (entry.is <llvm::Type*>() &&
1485
- entry.get <llvm::Type*>() == convertedTI->getStorageType ()));
1465
+ auto insertEntry = [&](const TypeInfo *&entry) {
1466
+ assert (entry == nullptr );
1486
1467
entry = convertedTI;
1487
1468
};
1488
1469
insertEntry (Cache[canonicalTy.getPointer ()]);
@@ -1600,7 +1581,7 @@ convertPrimitiveBuiltin(IRGenModule &IGM, CanType canTy) {
1600
1581
}
1601
1582
}
1602
1583
1603
- TypeCacheEntry TypeConverter::convertType (CanType ty) {
1584
+ const TypeInfo * TypeConverter::convertType (CanType ty) {
1604
1585
PrettyStackTraceType stackTrace (IGM.Context , " converting" , ty);
1605
1586
1606
1587
switch (ty->getKind ()) {
@@ -1719,10 +1700,10 @@ TypeConverter::convert##Name##StorageType(Name##StorageType *refType) { \
1719
1700
}
1720
1701
#include " swift/AST/ReferenceStorage.def"
1721
1702
1722
- static void overwriteForwardDecl (llvm::DenseMap<TypeBase*, TypeCacheEntry > &cache,
1703
+ static void overwriteForwardDecl (llvm::DenseMap<TypeBase *, const TypeInfo * > &cache,
1723
1704
TypeBase *key, const TypeInfo *result) {
1724
1705
assert (cache.count (key) && " no forward declaration?" );
1725
- assert (cache[key]. is <llvm::Type*>() && " overwriting real entry!" );
1706
+ assert (cache[key] == nullptr && " overwriting real entry!" );
1726
1707
cache[key] = result;
1727
1708
}
1728
1709
@@ -1828,8 +1809,8 @@ static bool isIRTypeDependent(IRGenModule &IGM, NominalTypeDecl *decl) {
1828
1809
}
1829
1810
}
1830
1811
1831
- TypeCacheEntry TypeConverter::convertAnyNominalType (CanType type,
1832
- NominalTypeDecl *decl) {
1812
+ const TypeInfo * TypeConverter::convertAnyNominalType (CanType type,
1813
+ NominalTypeDecl *decl) {
1833
1814
// By "any", we don't mean existentials.
1834
1815
assert (!isa<ProtocolDecl>(decl));
1835
1816
@@ -1961,86 +1942,6 @@ IRGenModule::createNominalType(ProtocolCompositionType *type) {
1961
1942
return llvm::StructType::create (getLLVMContext (), StringRef (typeName));
1962
1943
}
1963
1944
1964
- // / Compute the explosion schema for the given type.
1965
- ExplosionSchema IRGenModule::getSchema (SILType type) {
1966
- ExplosionSchema schema;
1967
- getSchema (type, schema);
1968
- return schema;
1969
- }
1970
-
1971
- // / Compute the explosion schema for the given type.
1972
- void IRGenModule::getSchema (SILType type, ExplosionSchema &schema) {
1973
- // As an optimization, avoid actually building a TypeInfo for any
1974
- // obvious TupleTypes. This assumes that a TupleType's explosion
1975
- // schema is always the concatenation of its component's schemas.
1976
- if (CanTupleType tuple = type.getAs <TupleType>()) {
1977
- for (auto index : indices (tuple.getElementTypes ()))
1978
- getSchema (type.getTupleElementType (index), schema);
1979
- return ;
1980
- }
1981
-
1982
- // Okay, that didn't work; just do the general thing.
1983
- getTypeInfo (type).getSchema (schema);
1984
- }
1985
-
1986
- // / Compute the explosion schema for the given type.
1987
- unsigned IRGenModule::getExplosionSize (SILType type) {
1988
- // As an optimization, avoid actually building a TypeInfo for any
1989
- // obvious TupleTypes. This assumes that a TupleType's explosion
1990
- // schema is always the concatenation of its component's schemas.
1991
- if (auto tuple = type.getAs <TupleType>()) {
1992
- unsigned count = 0 ;
1993
- for (auto index : indices (tuple.getElementTypes ()))
1994
- count += getExplosionSize (type.getTupleElementType (index));
1995
- return count;
1996
- }
1997
-
1998
- // If the type isn't loadable, the explosion size is always 1.
1999
- auto *loadableTI = dyn_cast<LoadableTypeInfo>(&getTypeInfo (type));
2000
- if (!loadableTI) return 1 ;
2001
-
2002
- // Okay, that didn't work; just do the general thing.
2003
- return loadableTI->getExplosionSize ();
2004
- }
2005
-
2006
- // / Determine whether this type is a single value that is passed
2007
- // / indirectly at the given level.
2008
- llvm::PointerType *IRGenModule::isSingleIndirectValue (SILType type) {
2009
- if (auto archetype = type.getAs <ArchetypeType>()) {
2010
- if (!archetype->requiresClass ())
2011
- return OpaquePtrTy;
2012
- }
2013
-
2014
- ExplosionSchema schema;
2015
- getSchema (type, schema);
2016
- if (schema.size () == 1 && schema.begin ()->isAggregate ())
2017
- return schema.begin ()->getAggregateType ()->getPointerTo (0 );
2018
- return nullptr ;
2019
- }
2020
-
2021
- // / Determine whether this type is known to be POD.
2022
- bool IRGenModule::isPOD (SILType type, ResilienceExpansion expansion) {
2023
- if (type.is <ArchetypeType>()) return false ;
2024
- if (type.is <ClassType>()) return false ;
2025
- if (type.is <BoundGenericClassType>()) return false ;
2026
- if (auto tuple = type.getAs <TupleType>()) {
2027
- for (auto index : indices (tuple.getElementTypes ()))
2028
- if (!isPOD (type.getTupleElementType (index), expansion))
2029
- return false ;
2030
- return true ;
2031
- }
2032
- return getTypeInfo (type).isPOD (expansion);
2033
- }
2034
-
2035
- // / Determine whether this type is known to be empty.
2036
- bool IRGenModule::isKnownEmpty (SILType type, ResilienceExpansion expansion) {
2037
- if (auto tuple = type.getAs <TupleType>()) {
2038
- if (tuple->getNumElements () == 0 )
2039
- return true ;
2040
- }
2041
- return getTypeInfo (type).isKnownEmpty (expansion);
2042
- }
2043
-
2044
1945
SpareBitVector IRGenModule::getSpareBitsForType (llvm::Type *scalarTy, Size size) {
2045
1946
auto it = SpareBitsForTypes.find (scalarTy);
2046
1947
if (it != SpareBitsForTypes.end ())
@@ -2050,13 +1951,9 @@ SpareBitVector IRGenModule::getSpareBitsForType(llvm::Type *scalarTy, Size size)
2050
1951
" using a size that's smaller than LLVM's alloc size?" );
2051
1952
2052
1953
{
2053
- // FIXME: Currently we only implement spare bits for single-element
2054
- // primitive integer types.
2055
- while (auto structTy = dyn_cast<llvm::StructType>(scalarTy)) {
2056
- if (structTy->getNumElements () != 1 )
2057
- goto no_spare_bits;
2058
- scalarTy = structTy->getElementType (0 );
2059
- }
1954
+ // FIXME: Currently we only implement spare bits for primitive integer
1955
+ // types.
1956
+ assert (!isa<llvm::StructType>(scalarTy));
2060
1957
2061
1958
auto *intTy = dyn_cast<llvm::IntegerType>(scalarTy);
2062
1959
if (!intTy)
0 commit comments