getResults().replaceAllUsesWith(std::forward<ValuesT>(values));
}
+ /// Replace uses of results of this operation with the provided `values` if
+ /// the given callback returns true.
+ template <typename ValuesT>
+ void replaceUsesWithIf(ValuesT &&values,
+ function_ref<bool(OpOperand &)> shouldReplace) {
+ getResults().replaceUsesWithIf(std::forward<ValuesT>(values),
+ shouldReplace);
+ }
+
/// Destroys this operation and its subclass data.
void destroy();
/// Replace all uses of results of this range with results of 'op'.
void replaceAllUsesWith(Operation *op);
+ /// Replace uses of results of this range with the provided 'values' if the
+ /// given callback returns true. The size of `values` must match the size of
+ /// this range.
+ template <typename ValuesT>
+ std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
+ replaceUsesWithIf(ValuesT &&values,
+ function_ref<bool(OpOperand &)> shouldReplace) {
+ assert(static_cast<size_t>(std::distance(values.begin(), values.end())) ==
+ size() &&
+ "expected 'values' to correspond 1-1 with the number of results");
+
+ for (auto it : llvm::zip(*this, values))
+ std::get<0>(it).replaceUsesWithIf(std::get<1>(it), shouldReplace);
+ }
+
+ /// Replace uses of results of this range with results of `op` if the given
+ /// callback returns true.
+ void replaceUsesWithIf(Operation *op,
+ function_ref<bool(OpOperand &)> shouldReplace);
+
//===--------------------------------------------------------------------===//
// Users
//===--------------------------------------------------------------------===//
replaceAllUsesWith(op->getResults());
}
+void ResultRange::replaceUsesWithIf(
+ Operation *op, function_ref<bool(OpOperand &)> shouldReplace) {
+ replaceUsesWithIf(op->getResults(), shouldReplace);
+}
+
//===----------------------------------------------------------------------===//
// ValueRange
} else {
// When the region does not have SSA dominance, we need to check if we
// have visited a use before replacing any use.
- for (auto it : llvm::zip(op->getResults(), existing->getResults())) {
- std::get<0>(it).replaceUsesWithIf(
- std::get<1>(it), [&](OpOperand &operand) {
- return !knownValues.count(operand.getOwner());
- });
- }
+ op->replaceUsesWithIf(existing->getResults(), [&](OpOperand &operand) {
+ return !knownValues.count(operand.getOwner());
+ });
// There may be some remaining uses of the operation.
if (op->use_empty())