@@ -148,11 +148,10 @@ struct OwnershipFixupContext {
148
148
InstModCallbacks &callbacks;
149
149
DeadEndBlocks &deBlocks;
150
150
151
-
152
- // FIXME: remove these two vectors once BorrowedLifetimeExtender is used
153
- // everywhere.
154
- SmallVector<Operand *, 8 > transitiveBorrowedUses;
155
- SmallVector<PhiOperand, 8 > recursiveReborrows;
151
+ // Cache the use-points for the lifetime of an inner guaranteed value (which
152
+ // does not introduce a borrow scope) after checking validity. These will be
153
+ // used again to extend the lifetime of the replacement value.
154
+ SmallVector<Operand *, 8 > guaranteedUsePoints;
156
155
157
156
// / Extra state initialized by OwnershipRAUWFixupHelper::get() that we use
158
157
// / when RAUWing addresses. This ensures we do not need to recompute this
@@ -162,6 +161,8 @@ struct OwnershipFixupContext {
162
161
// / compute all transitive address uses of oldValue. If we find that we do
163
162
// / need this fixed up, then we will copy our interior pointer base value
164
163
// / and use this to seed that new lifetime.
164
+ // /
165
+ // / FIXME: shouldn't these already be covered by guaranteedUsePoints?
165
166
SmallVector<Operand *, 8 > allAddressUsesFromOldValue;
166
167
167
168
// / This is the interior pointer (e.g. ref_element_addr)
@@ -184,8 +185,7 @@ struct OwnershipFixupContext {
184
185
: callbacks(callbacks), deBlocks(deBlocks) {}
185
186
186
187
void clear () {
187
- transitiveBorrowedUses.clear ();
188
- recursiveReborrows.clear ();
188
+ guaranteedUsePoints.clear ();
189
189
extraAddressFixupInfo.allAddressUsesFromOldValue .clear ();
190
190
extraAddressFixupInfo.base = AccessBase ();
191
191
}
@@ -212,6 +212,8 @@ class OwnershipRAUWHelper {
212
212
private:
213
213
OwnershipFixupContext *ctx;
214
214
SILValue oldValue;
215
+ // newValue is the aspirational replacement. It might not be the actual
216
+ // replacement after SILCombine fixups (like type casting) and OSSA fixups.
215
217
SILValue newValue;
216
218
217
219
public:
@@ -253,21 +255,27 @@ class OwnershipRAUWHelper {
253
255
// / Perform OSSA fixup on newValue and return a fixed-up value based that can
254
256
// / be used to replace all uses of oldValue.
255
257
// /
256
- // / This is so that we can avoid creating "forwarding" transformation
257
- // / instructions before we know if we can perform the RAUW. Any such
258
- // / "forwarding" transformation must be performed upon \p newValue at \p
259
- // / oldValue's insertion point so that we can then here RAUW the transformed
260
- // / \p newValue.
258
+ // / This is only used by clients that must transform \p newValue, such as
259
+ // / adding type casts, before it can be used to replace \p oldValue.
260
+ // /
261
+ // / \p rewrittenNewValue is only passed when the client needs to regenerate
262
+ // / newValue after checking its RAUW validity, but before performing OSSA
263
+ // / fixup on it.
264
+ SILValue prepareReplacement (SILValue rewrittenNewValue = SILValue());
265
+
266
+ // / Perform the actual RAUW--replace all uses if \p oldValue.
267
+ // /
268
+ // / Precondition: \p replacementValue is either invalid or has the same type
269
+ // / as \p oldValue and is a valid OSSA replacement.
261
270
SILBasicBlock::iterator
262
- perform (SingleValueInstruction *maybeTransformedNewValue = nullptr );
271
+ perform (SILValue replacementValue = SILValue() );
263
272
264
273
private:
265
- SILBasicBlock::iterator replaceAddressUses (SingleValueInstruction *oldValue,
266
- SILValue newValue);
267
-
268
274
void invalidate () {
269
275
ctx = nullptr ;
270
276
}
277
+
278
+ SILValue getReplacementAddress ();
271
279
};
272
280
273
281
// / A utility composed ontop of OwnershipFixupContext that knows how to replace
0 commit comments