Skip to content

[mlir][Transforms] Make ConversionPatternRewriter constructor private #82244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
return;
}

mlir::ConversionPatternRewriter builder(mlirModule.getContext());
mlir::IRRewriter builder(mlirModule.getContext());
unsigned oclcABIVERsion = codeGenOpts.CodeObjectVersion;
auto int32Type = builder.getI32Type();

Expand Down
10 changes: 9 additions & 1 deletion mlir/include/mlir/Transforms/DialectConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Block;
class ConversionPatternRewriter;
class MLIRContext;
class Operation;
struct OperationConverter;
class Type;
class Value;

Expand Down Expand Up @@ -657,7 +658,6 @@ struct ConversionPatternRewriterImpl;
/// hooks.
class ConversionPatternRewriter final : public PatternRewriter {
public:
explicit ConversionPatternRewriter(MLIRContext *ctx);
~ConversionPatternRewriter() override;

/// Apply a signature conversion to the entry block of the given region. This
Expand Down Expand Up @@ -764,6 +764,14 @@ class ConversionPatternRewriter final : public PatternRewriter {
detail::ConversionPatternRewriterImpl &getImpl();

private:
// Allow OperationConverter to construct new rewriters.
friend struct OperationConverter;

/// Conversion pattern rewriters must not be used outside of dialect
/// conversions. They apply some IR rewrites in a delayed fashion and could
/// bring the IR into an inconsistent state when used standalone.
explicit ConversionPatternRewriter(MLIRContext *ctx);

// Hide unsupported pattern rewriter API.
using OpBuilder::setListener;

Expand Down
18 changes: 11 additions & 7 deletions mlir/lib/Transforms/Utils/DialectConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,11 @@ class ReplaceOperationRewrite : public OperationRewrite {

void cleanup() override;

private:
friend struct OperationConverter;
const TypeConverter *getConverter() const { return converter; }

bool hasChangedResults() const { return changedResults; }

private:
/// An optional type converter that can be used to materialize conversions
/// between the new and old values if necessary.
const TypeConverter *converter;
Expand Down Expand Up @@ -2387,7 +2389,9 @@ enum OpConversionMode {
/// applied to the operations on success.
Analysis,
};
} // namespace

namespace mlir {
// This class converts operations to a given conversion target via a set of
// rewrite patterns. The conversion behaves differently depending on the
// conversion mode.
Expand Down Expand Up @@ -2447,7 +2451,7 @@ struct OperationConverter {
/// *not* to be legalizable to the target.
DenseSet<Operation *> *trackedOps;
};
} // namespace
} // namespace mlir

LogicalResult OperationConverter::convert(ConversionPatternRewriter &rewriter,
Operation *op) {
Expand Down Expand Up @@ -2539,7 +2543,7 @@ OperationConverter::finalize(ConversionPatternRewriter &rewriter) {
for (unsigned i = 0; i < rewriterImpl.rewrites.size(); ++i) {
auto *opReplacement =
dyn_cast<ReplaceOperationRewrite>(rewriterImpl.rewrites[i].get());
if (!opReplacement || !opReplacement->changedResults)
if (!opReplacement || !opReplacement->hasChangedResults())
continue;
Operation *op = opReplacement->getOperation();
for (OpResult result : op->getResults()) {
Expand All @@ -2563,9 +2567,9 @@ OperationConverter::finalize(ConversionPatternRewriter &rewriter) {

// Legalize this result.
rewriter.setInsertionPoint(op);
if (failed(legalizeChangedResultType(op, result, newValue,
opReplacement->converter, rewriter,
rewriterImpl, *inverseMapping)))
if (failed(legalizeChangedResultType(
op, result, newValue, opReplacement->getConverter(), rewriter,
rewriterImpl, *inverseMapping)))
return failure();
}
}
Expand Down