NFC: Add header blocks to DialectConversion.h to improve readability.
PiperOrigin-RevId: 257903383
diff --git a/include/mlir/Transforms/DialectConversion.h b/include/mlir/Transforms/DialectConversion.h
index fd2a540..33ae17d 100644
--- a/include/mlir/Transforms/DialectConversion.h
+++ b/include/mlir/Transforms/DialectConversion.h
@@ -36,76 +36,9 @@
class Type;
class Value;
-/// Base class for the conversion patterns that require type changes. Specific
-/// conversions must derive this class and implement least one `rewrite` method.
-/// NOTE: These conversion patterns can only be used with the 'apply*' methods
-/// below.
-class ConversionPattern : public RewritePattern {
-public:
- /// Construct an ConversionPattern. `rootName` must correspond to the
- /// canonical name of the first operation matched by the pattern.
- ConversionPattern(StringRef rootName, PatternBenefit benefit,
- MLIRContext *ctx)
- : RewritePattern(rootName, benefit, ctx) {}
-
- /// Hook for derived classes to implement rewriting. `op` is the (first)
- /// operation matched by the pattern, `operands` is a list of rewritten values
- /// that are passed to this operation, `rewriter` can be used to emit the new
- /// operations. This function must be reimplemented if the
- /// ConversionPattern ever needs to replace an operation that does not
- /// have successors. This function should not fail. If some specific cases of
- /// the operation are not supported, these cases should not be matched.
- virtual void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const {
- llvm_unreachable("unimplemented rewrite");
- }
-
- /// Hook for derived classes to implement rewriting. `op` is the (first)
- /// operation matched by the pattern, `properOperands` is a list of rewritten
- /// values that are passed to the operation itself, `destinations` is a list
- /// of (potentially rewritten) successor blocks, `operands` is a list of lists
- /// of rewritten values passed to each of the successors, co-indexed with
- /// `destinations`, `rewriter` can be used to emit the new operations. It must
- /// be reimplemented if the ConversionPattern ever needs to replace a
- /// terminator operation that has successors. This function should not fail
- /// the pass. If some specific cases of the operation are not supported,
- /// these cases should not be matched.
- virtual void rewrite(Operation *op, ArrayRef<Value *> properOperands,
- ArrayRef<Block *> destinations,
- ArrayRef<ArrayRef<Value *>> operands,
- PatternRewriter &rewriter) const {
- llvm_unreachable("unimplemented rewrite for terminators");
- }
-
- /// Hook for derived classes to implement combined matching and rewriting.
- virtual PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> properOperands,
- ArrayRef<Block *> destinations,
- ArrayRef<ArrayRef<Value *>> operands,
- PatternRewriter &rewriter) const {
- if (!match(op))
- return matchFailure();
- rewrite(op, properOperands, destinations, operands, rewriter);
- return matchSuccess();
- }
-
- /// Hook for derived classes to implement combined matching and rewriting.
- virtual PatternMatchResult matchAndRewrite(Operation *op,
- ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const {
- if (!match(op))
- return matchFailure();
- rewrite(op, operands, rewriter);
- return matchSuccess();
- }
-
- /// Attempt to match and rewrite the IR root at the specified operation.
- PatternMatchResult matchAndRewrite(Operation *op,
- PatternRewriter &rewriter) const final;
-
-private:
- using RewritePattern::rewrite;
-};
+//===----------------------------------------------------------------------===//
+// Type Conversion
+//===----------------------------------------------------------------------===//
/// Base class for type conversion interface. Specific converters must
/// derive this class and implement the pure virtual functions.
@@ -231,6 +164,85 @@
}
};
+//===----------------------------------------------------------------------===//
+// Conversion Patterns
+//===----------------------------------------------------------------------===//
+
+/// Base class for the conversion patterns that require type changes. Specific
+/// conversions must derive this class and implement least one `rewrite` method.
+/// NOTE: These conversion patterns can only be used with the 'apply*' methods
+/// below.
+class ConversionPattern : public RewritePattern {
+public:
+ /// Construct an ConversionPattern. `rootName` must correspond to the
+ /// canonical name of the first operation matched by the pattern.
+ ConversionPattern(StringRef rootName, PatternBenefit benefit,
+ MLIRContext *ctx)
+ : RewritePattern(rootName, benefit, ctx) {}
+
+ /// Hook for derived classes to implement rewriting. `op` is the (first)
+ /// operation matched by the pattern, `operands` is a list of rewritten values
+ /// that are passed to this operation, `rewriter` can be used to emit the new
+ /// operations. This function must be reimplemented if the
+ /// ConversionPattern ever needs to replace an operation that does not
+ /// have successors. This function should not fail. If some specific cases of
+ /// the operation are not supported, these cases should not be matched.
+ virtual void rewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const {
+ llvm_unreachable("unimplemented rewrite");
+ }
+
+ /// Hook for derived classes to implement rewriting. `op` is the (first)
+ /// operation matched by the pattern, `properOperands` is a list of rewritten
+ /// values that are passed to the operation itself, `destinations` is a list
+ /// of (potentially rewritten) successor blocks, `operands` is a list of lists
+ /// of rewritten values passed to each of the successors, co-indexed with
+ /// `destinations`, `rewriter` can be used to emit the new operations. It must
+ /// be reimplemented if the ConversionPattern ever needs to replace a
+ /// terminator operation that has successors. This function should not fail
+ /// the pass. If some specific cases of the operation are not supported,
+ /// these cases should not be matched.
+ virtual void rewrite(Operation *op, ArrayRef<Value *> properOperands,
+ ArrayRef<Block *> destinations,
+ ArrayRef<ArrayRef<Value *>> operands,
+ PatternRewriter &rewriter) const {
+ llvm_unreachable("unimplemented rewrite for terminators");
+ }
+
+ /// Hook for derived classes to implement combined matching and rewriting.
+ virtual PatternMatchResult
+ matchAndRewrite(Operation *op, ArrayRef<Value *> properOperands,
+ ArrayRef<Block *> destinations,
+ ArrayRef<ArrayRef<Value *>> operands,
+ PatternRewriter &rewriter) const {
+ if (!match(op))
+ return matchFailure();
+ rewrite(op, properOperands, destinations, operands, rewriter);
+ return matchSuccess();
+ }
+
+ /// Hook for derived classes to implement combined matching and rewriting.
+ virtual PatternMatchResult matchAndRewrite(Operation *op,
+ ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const {
+ if (!match(op))
+ return matchFailure();
+ rewrite(op, operands, rewriter);
+ return matchSuccess();
+ }
+
+ /// Attempt to match and rewrite the IR root at the specified operation.
+ PatternMatchResult matchAndRewrite(Operation *op,
+ PatternRewriter &rewriter) const final;
+
+private:
+ using RewritePattern::rewrite;
+};
+
+//===----------------------------------------------------------------------===//
+// ConversionTarget
+//===----------------------------------------------------------------------===//
+
/// This class describes a specific conversion target.
class ConversionTarget {
public:
@@ -335,6 +347,10 @@
MLIRContext &ctx;
};
+//===----------------------------------------------------------------------===//
+// Conversion Application
+//===----------------------------------------------------------------------===//
+
/// Convert the given module with the provided conversion patterns and type
/// conversion object. This function returns failure if a type conversion
/// failed.
diff --git a/lib/Transforms/DialectConversion.cpp b/lib/Transforms/DialectConversion.cpp
index 7809499..fad5a60 100644
--- a/lib/Transforms/DialectConversion.cpp
+++ b/lib/Transforms/DialectConversion.cpp
@@ -531,7 +531,7 @@
} // end anonymous namespace
//===----------------------------------------------------------------------===//
-// ConversionPattern
+// Conversion Patterns
//===----------------------------------------------------------------------===//
/// Attempt to match and rewrite the IR root at the specified operation.
@@ -984,7 +984,7 @@
}
//===----------------------------------------------------------------------===//
-// TypeConverter
+// Type Conversion
//===----------------------------------------------------------------------===//
/// Append new result types to the signature conversion.
@@ -1121,7 +1121,7 @@
}
//===----------------------------------------------------------------------===//
-// applyConversionPatterns
+// Conversion Application
//===----------------------------------------------------------------------===//
/// Convert the given module with the provided conversion patterns and type