Skip to content

Commit 89f0f5d

Browse files
authored
Merge pull request #32842 from atrick/strip-access-casts
Teach stripCasts (and getUnderlyingObject) about begin_access.
2 parents ad5eda1 + 3766962 commit 89f0f5d

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050

5151
namespace swift {
5252

53-
/// Get the base address of a formal access by stripping access markers and
54-
/// borrows.
53+
/// Get the base address of a formal access by stripping access markers.
5554
///
5655
/// If \p v is an address, then the returned value is also an address
5756
/// (pointer-to-address is not stripped).

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ SILValue swift::stripCastsWithoutMarkDependence(SILValue V) {
127127
V = stripSinglePredecessorArgs(V);
128128

129129
auto K = V->getKind();
130-
if (isRCIdentityPreservingCast(K) ||
131-
K == ValueKind::UncheckedTrivialBitCastInst ||
132-
K == ValueKind::EndCOWMutationInst) {
130+
if (isRCIdentityPreservingCast(K)
131+
|| K == ValueKind::UncheckedTrivialBitCastInst
132+
|| K == ValueKind::BeginAccessInst
133+
|| K == ValueKind::EndCOWMutationInst) {
133134
V = cast<SingleValueInstruction>(V)->getOperand(0);
134135
continue;
135136
}
@@ -145,7 +146,8 @@ SILValue swift::stripCasts(SILValue v) {
145146
auto k = v->getKind();
146147
if (isRCIdentityPreservingCast(k)
147148
|| k == ValueKind::UncheckedTrivialBitCastInst
148-
|| k == ValueKind::MarkDependenceInst) {
149+
|| k == ValueKind::MarkDependenceInst
150+
|| k == ValueKind::BeginAccessInst) {
149151
v = cast<SingleValueInstruction>(v)->getOperand(0);
150152
continue;
151153
}

lib/SIL/Utils/Projection.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,13 @@ Optional<ProjectionPath> ProjectionPath::getProjectionPath(SILValue Start,
371371

372372
auto Iter = End;
373373
while (Start != Iter) {
374-
// end_cow_mutation is not a projection, but we want to "see through" it.
375-
if (!isa<EndCOWMutationInst>(Iter)) {
374+
// end_cow_mutation and begin_access are not projections, but we need to be
375+
// able to form valid ProjectionPaths across them, otherwise optimization
376+
// passes like RLE/DSE cannot recognize their locations.
377+
//
378+
// TODO: migrate users to getProjectionPath to the AccessPath utility to
379+
// avoid this hack.
380+
if (!isa<EndCOWMutationInst>(Iter) && !isa<BeginAccessInst>(Iter)) {
376381
Projection AP(Iter);
377382
if (!AP.isValid())
378383
break;

test/SILOptimizer/escape_analysis.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ bb0(%0 : $*SomeData):
19381938
// CHECK: to set_deallocating %0 : $IntWrapper
19391939
// CHECK: NoEscape: %3 = ref_element_addr %0 : $IntWrapper, #IntWrapper.property
19401940
// CHECK: to set_deallocating %0 : $IntWrapper
1941-
// CHECK: MayEscape: %4 = begin_access [modify] [dynamic] [no_nested_conflict] %3 : $*Int64
1941+
// CHECK: NoEscape: %4 = begin_access [modify] [dynamic] [no_nested_conflict] %3 : $*Int64
19421942
// CHECK: to set_deallocating %0 : $IntWrapper
19431943
sil @testEndAccess : $@convention(thin) () -> () {
19441944
bb0:

0 commit comments

Comments
 (0)