mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: Add resilience expansion parameter to TypeConverter::countNumberOfFields()
This commit is contained in:
@@ -683,7 +683,9 @@ class TypeConverter {
|
|||||||
llvm::DenseMap<AnyFunctionRef, CaptureInfo> LoweredCaptures;
|
llvm::DenseMap<AnyFunctionRef, CaptureInfo> LoweredCaptures;
|
||||||
|
|
||||||
/// Cache of loadable SILType to number of (estimated) fields
|
/// Cache of loadable SILType to number of (estimated) fields
|
||||||
llvm::DenseMap<SILType, unsigned> TypeFields;
|
///
|
||||||
|
/// Second element is a ResilienceExpansion.
|
||||||
|
llvm::DenseMap<std::pair<SILType, unsigned>, unsigned> TypeFields;
|
||||||
|
|
||||||
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
|
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
|
||||||
|
|
||||||
@@ -739,7 +741,7 @@ public:
|
|||||||
static ProtocolDispatchStrategy getProtocolDispatchStrategy(ProtocolDecl *P);
|
static ProtocolDispatchStrategy getProtocolDispatchStrategy(ProtocolDecl *P);
|
||||||
|
|
||||||
/// Count the total number of fields inside the given SIL Type
|
/// Count the total number of fields inside the given SIL Type
|
||||||
unsigned countNumberOfFields(SILType Ty);
|
unsigned countNumberOfFields(SILType Ty, ResilienceExpansion expansion);
|
||||||
|
|
||||||
/// True if a protocol uses witness tables for dynamic dispatch.
|
/// True if a protocol uses witness tables for dynamic dispatch.
|
||||||
static bool protocolRequiresWitnessTable(ProtocolDecl *P) {
|
static bool protocolRequiresWitnessTable(ProtocolDecl *P) {
|
||||||
|
|||||||
@@ -2529,17 +2529,15 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
|
static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
|
||||||
SILType Ty) {
|
SILType Ty, ResilienceExpansion expansion) {
|
||||||
if (auto *structDecl = Ty.getStructOrBoundGenericStruct()) {
|
if (auto *structDecl = Ty.getStructOrBoundGenericStruct()) {
|
||||||
// FIXME: Expansion
|
assert(!structDecl->isResilient(Module.getSwiftModule(), expansion) &&
|
||||||
assert(!structDecl->isResilient(Module.getSwiftModule(),
|
|
||||||
ResilienceExpansion::Minimal) &&
|
|
||||||
" FSO should not be trying to explode resilient (ie address-only) "
|
" FSO should not be trying to explode resilient (ie address-only) "
|
||||||
"types at all");
|
"types at all");
|
||||||
for (auto *prop : structDecl->getStoredProperties()) {
|
for (auto *prop : structDecl->getStoredProperties()) {
|
||||||
SILType propTy = Ty.getFieldType(prop, Module);
|
SILType propTy = Ty.getFieldType(prop, Module);
|
||||||
unsigned fieldsCountBefore = fieldsCount;
|
unsigned fieldsCountBefore = fieldsCount;
|
||||||
countNumberOfInnerFields(fieldsCount, Module, propTy);
|
countNumberOfInnerFields(fieldsCount, Module, propTy, expansion);
|
||||||
if (fieldsCount == fieldsCountBefore) {
|
if (fieldsCount == fieldsCountBefore) {
|
||||||
// size of Struct(BigStructType) == size of BigStructType()
|
// size of Struct(BigStructType) == size of BigStructType()
|
||||||
// prevent counting its size as BigStructType()+1
|
// prevent counting its size as BigStructType()+1
|
||||||
@@ -2549,9 +2547,9 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto tupleTy = Ty.getAs<TupleType>()) {
|
if (auto tupleTy = Ty.getAs<TupleType>()) {
|
||||||
for (auto elt : tupleTy->getElementTypes()) {
|
for (auto elt : tupleTy.getElementTypes()) {
|
||||||
auto silElt = SILType::getPrimitiveObjectType(elt->getCanonicalType());
|
auto silElt = SILType::getPrimitiveObjectType(elt);
|
||||||
countNumberOfInnerFields(fieldsCount, Module, silElt);
|
countNumberOfInnerFields(fieldsCount, Module, silElt, expansion);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2559,9 +2557,7 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
|
|||||||
if (enumDecl->isIndirect()) {
|
if (enumDecl->isIndirect()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// FIXME: Expansion
|
assert(!enumDecl->isResilient(Module.getSwiftModule(), expansion) &&
|
||||||
assert(!enumDecl->isResilient(Module.getSwiftModule(),
|
|
||||||
ResilienceExpansion::Minimal) &&
|
|
||||||
" FSO should not be trying to explode resilient (ie address-only) "
|
" FSO should not be trying to explode resilient (ie address-only) "
|
||||||
"types at all");
|
"types at all");
|
||||||
unsigned fieldsCountBefore = fieldsCount;
|
unsigned fieldsCountBefore = fieldsCount;
|
||||||
@@ -2580,7 +2576,7 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
|
|||||||
// In case it is used by a pass that tries to explode enums.
|
// In case it is used by a pass that tries to explode enums.
|
||||||
auto payloadTy = Ty.getEnumElementType(elt, Module);
|
auto payloadTy = Ty.getEnumElementType(elt, Module);
|
||||||
fieldsCount = 0;
|
fieldsCount = 0;
|
||||||
countNumberOfInnerFields(fieldsCount, Module, payloadTy);
|
countNumberOfInnerFields(fieldsCount, Module, payloadTy, expansion);
|
||||||
if (fieldsCount > maxEnumCount) {
|
if (fieldsCount > maxEnumCount) {
|
||||||
maxEnumCount = fieldsCount;
|
maxEnumCount = fieldsCount;
|
||||||
}
|
}
|
||||||
@@ -2590,13 +2586,15 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TypeConverter::countNumberOfFields(SILType Ty) {
|
unsigned TypeConverter::countNumberOfFields(SILType Ty,
|
||||||
auto Iter = TypeFields.find(Ty);
|
ResilienceExpansion expansion) {
|
||||||
|
auto key = std::make_pair(Ty, unsigned(expansion));
|
||||||
|
auto Iter = TypeFields.find(key);
|
||||||
if (Iter != TypeFields.end()) {
|
if (Iter != TypeFields.end()) {
|
||||||
return std::max(Iter->second, 1U);
|
return std::max(Iter->second, 1U);
|
||||||
}
|
}
|
||||||
unsigned fieldsCount = 0;
|
unsigned fieldsCount = 0;
|
||||||
countNumberOfInnerFields(fieldsCount, M, Ty);
|
countNumberOfInnerFields(fieldsCount, M, Ty, expansion);
|
||||||
TypeFields[Ty] = fieldsCount;
|
TypeFields[key] = fieldsCount;
|
||||||
return std::max(fieldsCount, 1U);
|
return std::max(fieldsCount, 1U);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1509,7 +1509,10 @@ bool swift::shouldExpand(SILModule &Module, SILType Ty) {
|
|||||||
if (EnableExpandAll) {
|
if (EnableExpandAll) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
unsigned numFields = Module.Types.countNumberOfFields(Ty);
|
|
||||||
|
// FIXME: Expansion
|
||||||
|
unsigned numFields =
|
||||||
|
Module.Types.countNumberOfFields(Ty, ResilienceExpansion::Minimal);
|
||||||
if (numFields > 6) {
|
if (numFields > 6) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user