Skip to content

Commit ced5548

Browse files
committed
SIL: Add resilience expansion parameter to TypeConverter::countNumberOfFields()
1 parent 980fb7c commit ced5548

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ class TypeConverter {
683683
llvm::DenseMap<AnyFunctionRef, CaptureInfo> LoweredCaptures;
684684

685685
/// Cache of loadable SILType to number of (estimated) fields
686-
llvm::DenseMap<SILType, unsigned> TypeFields;
686+
///
687+
/// Second element is a ResilienceExpansion.
688+
llvm::DenseMap<std::pair<SILType, unsigned>, unsigned> TypeFields;
687689

688690
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
689691

@@ -739,7 +741,7 @@ class TypeConverter {
739741
static ProtocolDispatchStrategy getProtocolDispatchStrategy(ProtocolDecl *P);
740742

741743
/// Count the total number of fields inside the given SIL Type
742-
unsigned countNumberOfFields(SILType Ty);
744+
unsigned countNumberOfFields(SILType Ty, ResilienceExpansion expansion);
743745

744746
/// True if a protocol uses witness tables for dynamic dispatch.
745747
static bool protocolRequiresWitnessTable(ProtocolDecl *P) {

lib/SIL/TypeLowering.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,17 +2529,15 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
25292529
}
25302530

25312531
static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
2532-
SILType Ty) {
2532+
SILType Ty, ResilienceExpansion expansion) {
25332533
if (auto *structDecl = Ty.getStructOrBoundGenericStruct()) {
2534-
// FIXME: Expansion
2535-
assert(!structDecl->isResilient(Module.getSwiftModule(),
2536-
ResilienceExpansion::Minimal) &&
2534+
assert(!structDecl->isResilient(Module.getSwiftModule(), expansion) &&
25372535
" FSO should not be trying to explode resilient (ie address-only) "
25382536
"types at all");
25392537
for (auto *prop : structDecl->getStoredProperties()) {
25402538
SILType propTy = Ty.getFieldType(prop, Module);
25412539
unsigned fieldsCountBefore = fieldsCount;
2542-
countNumberOfInnerFields(fieldsCount, Module, propTy);
2540+
countNumberOfInnerFields(fieldsCount, Module, propTy, expansion);
25432541
if (fieldsCount == fieldsCountBefore) {
25442542
// size of Struct(BigStructType) == size of BigStructType()
25452543
// prevent counting its size as BigStructType()+1
@@ -2549,19 +2547,17 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
25492547
return;
25502548
}
25512549
if (auto tupleTy = Ty.getAs<TupleType>()) {
2552-
for (auto elt : tupleTy->getElementTypes()) {
2553-
auto silElt = SILType::getPrimitiveObjectType(elt->getCanonicalType());
2554-
countNumberOfInnerFields(fieldsCount, Module, silElt);
2550+
for (auto elt : tupleTy.getElementTypes()) {
2551+
auto silElt = SILType::getPrimitiveObjectType(elt);
2552+
countNumberOfInnerFields(fieldsCount, Module, silElt, expansion);
25552553
}
25562554
return;
25572555
}
25582556
if (auto *enumDecl = Ty.getEnumOrBoundGenericEnum()) {
25592557
if (enumDecl->isIndirect()) {
25602558
return;
25612559
}
2562-
// FIXME: Expansion
2563-
assert(!enumDecl->isResilient(Module.getSwiftModule(),
2564-
ResilienceExpansion::Minimal) &&
2560+
assert(!enumDecl->isResilient(Module.getSwiftModule(), expansion) &&
25652561
" FSO should not be trying to explode resilient (ie address-only) "
25662562
"types at all");
25672563
unsigned fieldsCountBefore = fieldsCount;
@@ -2580,7 +2576,7 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
25802576
// In case it is used by a pass that tries to explode enums.
25812577
auto payloadTy = Ty.getEnumElementType(elt, Module);
25822578
fieldsCount = 0;
2583-
countNumberOfInnerFields(fieldsCount, Module, payloadTy);
2579+
countNumberOfInnerFields(fieldsCount, Module, payloadTy, expansion);
25842580
if (fieldsCount > maxEnumCount) {
25852581
maxEnumCount = fieldsCount;
25862582
}
@@ -2590,13 +2586,15 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
25902586
}
25912587
}
25922588

2593-
unsigned TypeConverter::countNumberOfFields(SILType Ty) {
2594-
auto Iter = TypeFields.find(Ty);
2589+
unsigned TypeConverter::countNumberOfFields(SILType Ty,
2590+
ResilienceExpansion expansion) {
2591+
auto key = std::make_pair(Ty, unsigned(expansion));
2592+
auto Iter = TypeFields.find(key);
25952593
if (Iter != TypeFields.end()) {
25962594
return std::max(Iter->second, 1U);
25972595
}
25982596
unsigned fieldsCount = 0;
2599-
countNumberOfInnerFields(fieldsCount, M, Ty);
2600-
TypeFields[Ty] = fieldsCount;
2597+
countNumberOfInnerFields(fieldsCount, M, Ty, expansion);
2598+
TypeFields[key] = fieldsCount;
26012599
return std::max(fieldsCount, 1U);
26022600
}

lib/SILOptimizer/Utils/Local.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,10 @@ bool swift::shouldExpand(SILModule &Module, SILType Ty) {
15091509
if (EnableExpandAll) {
15101510
return true;
15111511
}
1512-
unsigned numFields = Module.Types.countNumberOfFields(Ty);
1512+
1513+
// FIXME: Expansion
1514+
unsigned numFields =
1515+
Module.Types.countNumberOfFields(Ty, ResilienceExpansion::Minimal);
15131516
if (numFields > 6) {
15141517
return false;
15151518
}

0 commit comments

Comments
 (0)