Skip to content

Commit 17c33c3

Browse files
committed
Revert "[mlir][Transforms] Add support for ConversionPatternRewriter::replaceAllUsesWith (llvm#155244)"
This reverts commit 2929a29.
1 parent ae9f0c3 commit 17c33c3

File tree

8 files changed

+91
-194
lines changed

8 files changed

+91
-194
lines changed

flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,6 @@ class DoConcurrentConversion
444444
mlir::SymbolTable &moduleSymbolTable;
445445
};
446446

447-
/// A listener that forwards notifyOperationErased to the given callback.
448-
struct CallbackListener : public mlir::RewriterBase::Listener {
449-
CallbackListener(std::function<void(mlir::Operation *op)> onOperationErased)
450-
: onOperationErased(onOperationErased) {}
451-
452-
void notifyOperationErased(mlir::Operation *op) override {
453-
onOperationErased(op);
454-
}
455-
456-
std::function<void(mlir::Operation *op)> onOperationErased;
457-
};
458-
459447
class DoConcurrentConversionPass
460448
: public flangomp::impl::DoConcurrentConversionPassBase<
461449
DoConcurrentConversionPass> {
@@ -480,10 +468,6 @@ class DoConcurrentConversionPass
480468
}
481469

482470
llvm::DenseSet<fir::DoConcurrentOp> concurrentLoopsToSkip;
483-
CallbackListener callbackListener([&](mlir::Operation *op) {
484-
if (auto loop = mlir::dyn_cast<fir::DoConcurrentOp>(op))
485-
concurrentLoopsToSkip.erase(loop);
486-
});
487471
mlir::RewritePatternSet patterns(context);
488472
patterns.insert<DoConcurrentConversion>(
489473
context, mapTo == flangomp::DoConcurrentMappingKind::DCMK_Device,
@@ -496,11 +480,8 @@ class DoConcurrentConversionPass
496480
target.markUnknownOpDynamicallyLegal(
497481
[](mlir::Operation *) { return true; });
498482

499-
mlir::ConversionConfig config;
500-
config.allowPatternRollback = false;
501-
config.listener = &callbackListener;
502-
if (mlir::failed(mlir::applyFullConversion(module, target,
503-
std::move(patterns), config))) {
483+
if (mlir::failed(
484+
mlir::applyFullConversion(module, target, std::move(patterns)))) {
504485
signalPassFailure();
505486
}
506487
}

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ class RewriterBase : public OpBuilder {
633633

634634
/// Find uses of `from` and replace them with `to`. Also notify the listener
635635
/// about every in-place op modification (for every use that was replaced).
636-
virtual void replaceAllUsesWith(Value from, Value to) {
636+
void replaceAllUsesWith(Value from, Value to) {
637637
for (OpOperand &operand : llvm::make_early_inc_range(from.getUses())) {
638638
Operation *op = operand.getOwner();
639639
modifyOpInPlace(op, [&]() { operand.set(to); });

mlir/include/mlir/Transforms/DialectConversion.h

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -854,29 +854,15 @@ class ConversionPatternRewriter final : public PatternRewriter {
854854
Region *region, const TypeConverter &converter,
855855
TypeConverter::SignatureConversion *entryConversion = nullptr);
856856

857-
/// Replace all the uses of `from` with `to`. The type of `from` and `to` is
858-
/// allowed to differ. The conversion driver will try to reconcile all type
859-
/// mismatches that still exist at the end of the conversion with
860-
/// materializations. This function supports both 1:1 and 1:N replacements.
857+
/// Replace all the uses of the block argument `from` with `to`. This
858+
/// function supports both 1:1 and 1:N replacements.
861859
///
862-
/// Note: If `allowPatternRollback` is set to "true", this function behaves
863-
/// slightly different:
864-
///
865-
/// 1. All current and future uses of `from` are replaced. The same value must
866-
/// not be replaced multiple times. That's an API violation.
867-
/// 2. Uses are not replaced immediately but in a delayed fashion. Patterns
868-
/// may still see the original uses when inspecting IR.
869-
/// 3. Uses within the same block that appear before the defining operation
870-
/// of the replacement value are not replaced. This allows users to
871-
/// perform certain replaceAllUsesExcept-style replacements, even though
872-
/// such API is not directly supported.
873-
///
874-
/// Note: In an attempt to align the ConversionPatternRewriter and
875-
/// RewriterBase APIs, (3) may be removed in the future.
876-
void replaceAllUsesWith(Value from, ValueRange to);
877-
void replaceAllUsesWith(Value from, Value to) override {
878-
replaceAllUsesWith(from, ValueRange{to});
879-
}
860+
/// Note: If `allowPatternRollback` is set to "true", this function replaces
861+
/// all current and future uses of the block argument. This same block
862+
/// block argument must not be replaced multiple times. Uses are not replaced
863+
/// immediately but in a delayed fashion. Patterns may still see the original
864+
/// uses when inspecting IR.
865+
void replaceUsesOfBlockArgument(BlockArgument from, ValueRange to);
880866

881867
/// Return the converted value of 'key' with a type defined by the type
882868
/// converter of the currently executing pattern. Return nullptr in the case

mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static void restoreByValRefArgumentType(
284284
cast<TypeAttr>(byValRefAttr->getValue()).getValue());
285285

286286
Value valueArg = LLVM::LoadOp::create(rewriter, arg.getLoc(), resTy, arg);
287-
rewriter.replaceAllUsesWith(arg, valueArg);
287+
rewriter.replaceUsesOfBlockArgument(arg, valueArg);
288288
}
289289
}
290290

0 commit comments

Comments
 (0)