[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.
This commit is contained in:
Nate Chandler
2025-06-03 15:07:43 -07:00
parent 974d179571
commit 33d5c8648b

View File

@@ -1688,6 +1688,22 @@ inline bool isAccessStorageCast(SingleValueInstruction *svi) {
return isAccessStorageTypeCast(svi) || isAccessStorageIdentityCast(svi);
}
// Strip access markers and casts that preserve the access storage.
//
// Compare to stripAccessAndIdentityCasts. This function strips cast that
// change the type.
inline SILValue stripAccessAndAccessStorageCasts(SILValue v) {
if (auto *bai = dyn_cast<BeginAccessInst>(v)) {
return stripAccessAndAccessStorageCasts(bai->getOperand());
}
if (auto *svi = dyn_cast<SingleValueInstruction>(v)) {
if (isAccessStorageCast(svi)) {
return stripAccessAndAccessStorageCasts(svi->getAllOperands()[0].get());
}
}
return v;
}
/// Abstract CRTP class for a visiting instructions that are part of the use-def
/// chain from an accessed address up to the storage base.
///