@@ -226,6 +226,39 @@ struct InstModCallbacks {
226
226
}
227
227
}
228
228
229
+ // / Replace all uses of the results of \p oldInst pairwise with new uses of
230
+ // / the results of \p newInst.
231
+ // /
232
+ // / If \p setUseValueFunc is not set to a value, we just call inline
233
+ // / SILInstruction::replaceAllUsesPairwiseWith(...) to ensure we only pay a
234
+ // / cost if we actually set setUseValueFunc.
235
+ void replaceAllInstUsesPairwiseWith (SILInstruction *oldInst, SILInstruction *newInst) {
236
+ wereAnyCallbacksInvoked = true ;
237
+
238
+ // If setUseValueFunc is not set, just call RAUW directly. RAUW in this case
239
+ // is equivalent to what we do below. We just enable better
240
+ // performance. This ensures that the default InstModCallback is really
241
+ // fast.
242
+ if (!setUseValueFunc)
243
+ return oldInst->replaceAllUsesPairwiseWith (newInst);
244
+
245
+ auto results = oldInst->getResults ();
246
+
247
+ // If we don't have any results, fast-path out without asking the other
248
+ // instruction for its results.
249
+ if (results.empty ()) {
250
+ assert (newInst->getResults ().empty ());
251
+ return ;
252
+ }
253
+
254
+ // Replace values with the corresponding values of the other instruction.
255
+ auto otherResults = newInst->getResults ();
256
+ assert (results.size () == otherResults.size ());
257
+ for (auto i : indices (results)) {
258
+ replaceValueUsesWith (results[i], otherResults[i]);
259
+ }
260
+ }
261
+
229
262
void eraseAndRAUWSingleValueInst (SingleValueInstruction *oldInst,
230
263
SILValue newValue) {
231
264
wereAnyCallbacksInvoked = true ;
0 commit comments