Skip to content

Commit 3aab1b0

Browse files
committed
[embedded] Use load_borrow/end_borrow in KeyPathProjector when in OSSA
1 parent 796554f commit 3aab1b0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/SILOptimizer/Utils/KeyPathProjector.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ class StoredPropertyProjector : public ComponentProjector {
120120
} else {
121121
// Accessing a class member -> reading the class
122122
parent->project(AccessType::Get, [&](SILValue parentValue) {
123-
SingleValueInstruction *Ref = builder.createLoad(loc, parentValue,
124-
LoadOwnershipQualifier::Unqualified);
123+
SingleValueInstruction *Borrow = nullptr;
124+
SingleValueInstruction *Ref;
125+
if (builder.hasOwnership()) {
126+
Ref = Borrow = builder.createLoadBorrow(loc, parentValue);
127+
} else {
128+
Ref = builder.createLoad(loc, parentValue, LoadOwnershipQualifier::Unqualified);
129+
}
125130

126131
// If we were previously accessing a class member, we're done now.
127132
insertEndAccess(beginAccess, builder);
@@ -135,6 +140,9 @@ class StoredPropertyProjector : public ComponentProjector {
135140
// decl or in a superclass of it. Just handle this to be on the safe
136141
// side.
137142
callback(SILValue());
143+
if (Borrow) {
144+
builder.createEndBorrow(loc, Borrow);
145+
}
138146
return;
139147
}
140148
Ref = builder.createUpcast(loc, Ref, superCl);
@@ -163,6 +171,10 @@ class StoredPropertyProjector : public ComponentProjector {
163171
if (beginAccess == addr) {
164172
insertEndAccess(beginAccess, builder);
165173
}
174+
175+
if (Borrow) {
176+
builder.createEndBorrow(loc, Borrow);
177+
}
166178
});
167179
}
168180
}

0 commit comments

Comments
 (0)