Skip to content

Commit 33d5c86

Browse files
committed
[MemAccessUtils] Add to strip access storage casts
The new function stripAccessAndAccessStorageCasts is analogous to the existing function stripAccessAndIdentityCasts but differs in that the latter uses isAccessStorageIdentityCast whereas the new function uses isAccessStorageCast.
1 parent 974d179 commit 33d5c86

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,22 @@ inline bool isAccessStorageCast(SingleValueInstruction *svi) {
16881688
return isAccessStorageTypeCast(svi) || isAccessStorageIdentityCast(svi);
16891689
}
16901690

1691+
// Strip access markers and casts that preserve the access storage.
1692+
//
1693+
// Compare to stripAccessAndIdentityCasts. This function strips cast that
1694+
// change the type.
1695+
inline SILValue stripAccessAndAccessStorageCasts(SILValue v) {
1696+
if (auto *bai = dyn_cast<BeginAccessInst>(v)) {
1697+
return stripAccessAndAccessStorageCasts(bai->getOperand());
1698+
}
1699+
if (auto *svi = dyn_cast<SingleValueInstruction>(v)) {
1700+
if (isAccessStorageCast(svi)) {
1701+
return stripAccessAndAccessStorageCasts(svi->getAllOperands()[0].get());
1702+
}
1703+
}
1704+
return v;
1705+
}
1706+
16911707
/// Abstract CRTP class for a visiting instructions that are part of the use-def
16921708
/// chain from an accessed address up to the storage base.
16931709
///

0 commit comments

Comments
 (0)