Skip to content

Commit 3d8f714

Browse files
committed
Add a new api findUnreferenceableStorage to check if struct or its fields have unreferenceable storage
1 parent bd1b99b commit 3d8f714

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: include/swift/SILOptimizer/Utils/InstOptUtils.h

+4
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ bool specializeAppliesInFunction(SILFunction &F,
604604
/// types aggregated together at each level.
605605
SILValue createEmptyAndUndefValue(SILType ty, SILInstruction *insertionPoint,
606606
SILBuilderContext &ctx, bool noUndef = false);
607+
608+
/// Check if a struct or its fields can have unreferenceable storage.
609+
bool findUnreferenceableStorage(StructDecl *decl, SILType structType,
610+
SILFunction *func);
607611
} // end namespace swift
608612

609613
#endif // SWIFT_SILOPTIMIZER_UTILS_INSTOPTUTILS_H

Diff for: lib/SILOptimizer/Utils/InstOptUtils.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -2009,3 +2009,21 @@ SILValue swift::createEmptyAndUndefValue(SILType ty,
20092009
assert(!noUndef);
20102010
return SILUndef::get(insertionPoint->getFunction(), ty);
20112011
}
2012+
2013+
bool swift::findUnreferenceableStorage(StructDecl *decl, SILType structType,
2014+
SILFunction *func) {
2015+
if (decl->hasUnreferenceableStorage()) {
2016+
return true;
2017+
}
2018+
// Check if any fields have unreferenceable stoage
2019+
for (auto *field : decl->getStoredProperties()) {
2020+
TypeExpansionContext tec = *func;
2021+
auto fieldTy = structType.getFieldType(field, func->getModule(), tec);
2022+
if (auto *fieldStructDecl = fieldTy.getStructOrBoundGenericStruct()) {
2023+
if (findUnreferenceableStorage(fieldStructDecl, fieldTy, func)) {
2024+
return true;
2025+
}
2026+
}
2027+
}
2028+
return false;
2029+
}

0 commit comments

Comments
 (0)