Skip to content

Commit 54594aa

Browse files
authored
Merge pull request swiftlang#38588 from gottesmm/pr-4df438ed25c634317f69e0e66bd4e92c1638f380
2 parents 13f0429 + fa54b11 commit 54594aa

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

include/swift/SILOptimizer/Utils/InstModCallbacks.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,39 @@ struct InstModCallbacks {
226226
}
227227
}
228228

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+
229262
void eraseAndRAUWSingleValueInst(SingleValueInstruction *oldInst,
230263
SILValue newValue) {
231264
wereAnyCallbacksInvoked = true;

0 commit comments

Comments
 (0)