Skip to content

Commit 88eefa8

Browse files
[mlir][SCFToOpenMP] Use walk pattern driver (llvm#155242)
The lowering pattern uses various APIs that are not supported in a dialect conversion such as `Block::eraseArguments` and `RewriterBase::replaceAllUsesWith`. Switch to the more efficient and simpler walk pattern driver.
1 parent 156c112 commit 88eefa8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "mlir/Dialect/SCF/IR/SCF.h"
2323
#include "mlir/IR/SymbolTable.h"
2424
#include "mlir/Pass/Pass.h"
25-
#include "mlir/Transforms/DialectConversion.h"
25+
#include "mlir/Transforms/WalkPatternRewriteDriver.h"
2626

2727
namespace mlir {
2828
#define GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS
@@ -538,15 +538,18 @@ struct ParallelOpLowering : public OpRewritePattern<scf::ParallelOp> {
538538

539539
/// Applies the conversion patterns in the given function.
540540
static LogicalResult applyPatterns(ModuleOp module, unsigned numThreads) {
541-
ConversionTarget target(*module.getContext());
542-
target.addIllegalOp<scf::ReduceOp, scf::ReduceReturnOp, scf::ParallelOp>();
543-
target.addLegalDialect<omp::OpenMPDialect, LLVM::LLVMDialect,
544-
memref::MemRefDialect>();
545-
546541
RewritePatternSet patterns(module.getContext());
547542
patterns.add<ParallelOpLowering>(module.getContext(), numThreads);
548543
FrozenRewritePatternSet frozen(std::move(patterns));
549-
return applyPartialConversion(module, target, frozen);
544+
walkAndApplyPatterns(module, frozen);
545+
auto status = module.walk([](Operation *op) {
546+
if (isa<scf::ReduceOp, scf::ReduceReturnOp, scf::ParallelOp>(op)) {
547+
op->emitError("unconverted operation found");
548+
return WalkResult::interrupt();
549+
}
550+
return WalkResult::advance();
551+
});
552+
return failure(status.wasInterrupted());
550553
}
551554

552555
/// A pass converting SCF operations to OpenMP operations.

0 commit comments

Comments
 (0)