llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-sparse

@llvm/pr-subscribers-mlir-spirv

Author: Matthias Springer (matthias-springer)

<details>
<summary>Changes</summary>

The 1:N dialect conversion driver has been deprecated. Use the regular dialect 
conversion driver instead. This commit deletes the 1:N dialect conversion 
driver.

For details, see 
https://discourse.llvm.org/t/rfc-merging-1-1-and-1-n-dialect-conversions/82513.

I plan to merge this PR in April 2025.

Depends on #<!-- -->116524.


---

Patch is 99.66 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/121389.diff


24 Files Affected:

- (removed) mlir/include/mlir/Dialect/Func/Transforms/OneToNFuncConversions.h 
(-26) 
- (modified) mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h (-10) 
- (modified) mlir/include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h (-1) 
- (modified) mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.h (-1) 
- (modified) mlir/include/mlir/Transforms/DialectConversion.h (-20) 
- (removed) mlir/include/mlir/Transforms/OneToNTypeConversion.h (-290) 
- (modified) mlir/lib/Dialect/Func/Transforms/CMakeLists.txt (-1) 
- (removed) mlir/lib/Dialect/Func/Transforms/OneToNFuncConversions.cpp (-87) 
- (modified) mlir/lib/Dialect/SCF/Transforms/CMakeLists.txt (-1) 
- (removed) mlir/lib/Dialect/SCF/Transforms/OneToNTypeConversion.cpp (-215) 
- (modified) mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp (+4-3) 
- (modified) mlir/lib/Transforms/Utils/CMakeLists.txt (-1) 
- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (-11) 
- (removed) mlir/lib/Transforms/Utils/OneToNTypeConversion.cpp (-458) 
- (removed) 
mlir/test/Conversion/OneToNTypeConversion/one-to-n-type-conversion.mlir (-140) 
- (removed) 
mlir/test/Conversion/OneToNTypeConversion/scf-structural-one-to-n-type-conversion.mlir
 (-183) 
- (modified) mlir/test/Transforms/decompose-call-graph-types.mlir (-53) 
- (modified) mlir/test/lib/Conversion/CMakeLists.txt (-1) 
- (removed) mlir/test/lib/Conversion/OneToNTypeConversion/CMakeLists.txt (-21) 
- (removed) 
mlir/test/lib/Conversion/OneToNTypeConversion/TestOneToNTypeConversionPass.cpp 
(-261) 
- (modified) mlir/tools/mlir-opt/CMakeLists.txt (-1) 
- (modified) mlir/tools/mlir-opt/mlir-opt.cpp (-2) 
- (modified) utils/bazel/llvm-project-overlay/mlir/BUILD.bazel (-2) 
- (modified) utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel (-17) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/OneToNFuncConversions.h 
b/mlir/include/mlir/Dialect/Func/Transforms/OneToNFuncConversions.h
deleted file mode 100644
index c9e407daf9bf8c..00000000000000
--- a/mlir/include/mlir/Dialect/Func/Transforms/OneToNFuncConversions.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//===- OneToNTypeFuncConversions.h - 1:N type conv. for Func ----*- C++ 
-*-===//
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_DIALECT_FUNC_TRANSFORMS_ONETONTYPEFUNCCONVERSIONS_H
-#define MLIR_DIALECT_FUNC_TRANSFORMS_ONETONTYPEFUNCCONVERSIONS_H
-
-namespace mlir {
-class TypeConverter;
-class RewritePatternSet;
-} // namespace mlir
-
-namespace mlir {
-
-// Populates the provided pattern set with patterns that do 1:N type 
conversions
-// on func ops. This is intended to be used with 
`applyPartialOneToNConversion`.
-void populateFuncTypeConversionPatterns(const TypeConverter &typeConverter,
-                                        RewritePatternSet &patterns);
-
-} // namespace mlir
-
-#endif // MLIR_DIALECT_FUNC_TRANSFORMS_ONETONTYPEFUNCCONVERSIONS_H
diff --git a/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h 
b/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
index 9c1479d28c305f..00c8a5c0c517b7 100644
--- a/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
+++ b/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
@@ -63,16 +63,6 @@ void populateSCFStructuralTypeConversions(const 
TypeConverter &typeConverter,
 void populateSCFStructuralTypeConversionTarget(
     const TypeConverter &typeConverter, ConversionTarget &target);
 
-/// Populates the provided pattern set with patterns that do 1:N type
-/// conversions on (some) SCF ops. This is intended to be used with
-/// applyPartialOneToNConversion.
-/// FIXME: The 1:N dialect conversion is deprecated and will be removed soon.
-/// 1:N support has been added to the regular dialect conversion driver.
-LLVM_DEPRECATED("Use populateSCFStructuralTypeConversions() instead",
-                "populateSCFStructuralTypeConversions")
-void populateSCFStructuralOneToNTypeConversions(
-    const TypeConverter &typeConverter, RewritePatternSet &patterns);
-
 /// Populate patterns for SCF software pipelining transformation. See the
 /// ForLoopPipeliningPattern for the transformation details.
 void populateSCFLoopPipeliningPatterns(RewritePatternSet &patterns,
diff --git a/mlir/include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h 
b/mlir/include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h
index bed4d66ccd6cbe..3d22ec918f4c5f 100644
--- a/mlir/include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h
+++ b/mlir/include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h
@@ -20,7 +20,6 @@
 #include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
 #include "mlir/Transforms/DialectConversion.h"
 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
-#include "mlir/Transforms/OneToNTypeConversion.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/LogicalResult.h"
 
diff --git a/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.h
index 2e9c297f20182a..acd347c530d58b 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.h
@@ -16,7 +16,6 @@
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/Pass/Pass.h"
 #include "mlir/Transforms/DialectConversion.h"
-#include "mlir/Transforms/OneToNTypeConversion.h"
 
 
//===----------------------------------------------------------------------===//
 // Include the generated pass header (which needs some early definitions).
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h 
b/mlir/include/mlir/Transforms/DialectConversion.h
index 9a6975dcf8dfae..7e5389a83855a5 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -45,13 +45,11 @@ class TypeConverter {
   // Copy the registered conversions, but not the caches
   TypeConverter(const TypeConverter &other)
       : conversions(other.conversions),
-        argumentMaterializations(other.argumentMaterializations),
         sourceMaterializations(other.sourceMaterializations),
         targetMaterializations(other.targetMaterializations),
         typeAttributeConversions(other.typeAttributeConversions) {}
   TypeConverter &operator=(const TypeConverter &other) {
     conversions = other.conversions;
-    argumentMaterializations = other.argumentMaterializations;
     sourceMaterializations = other.sourceMaterializations;
     targetMaterializations = other.targetMaterializations;
     typeAttributeConversions = other.typeAttributeConversions;
@@ -177,21 +175,6 @@ class TypeConverter {
   /// can be a TypeRange; in that case, the function must return a
   /// SmallVector<Value>.
 
-  /// This method registers a materialization that will be called when
-  /// converting (potentially multiple) block arguments that were the result of
-  /// a signature conversion of a single block argument, to a single SSA value
-  /// with the old block argument type.
-  ///
-  /// Note: Argument materializations are used only with the 1:N dialect
-  /// conversion driver. The 1:N dialect conversion driver will be removed soon
-  /// and so will be argument materializations.
-  template <typename FnT, typename T = typename llvm::function_traits<
-                              std::decay_t<FnT>>::template arg_t<1>>
-  void addArgumentMaterialization(FnT &&callback) {
-    argumentMaterializations.emplace_back(
-        wrapMaterialization<T>(std::forward<FnT>(callback)));
-  }
-
   /// This method registers a materialization that will be called when
   /// converting a replacement value back to its original source type.
   /// This is used when some uses of the original value persist beyond the main
@@ -319,8 +302,6 @@ class TypeConverter {
   /// generating a cast sequence of some kind. See the respective
   /// `add*Materialization` for more information on the context for these
   /// methods.
-  Value materializeArgumentConversion(OpBuilder &builder, Location loc,
-                                      Type resultType, ValueRange inputs) 
const;
   Value materializeSourceConversion(OpBuilder &builder, Location loc,
                                     Type resultType, ValueRange inputs) const;
   Value materializeTargetConversion(OpBuilder &builder, Location loc,
@@ -507,7 +488,6 @@ class TypeConverter {
   SmallVector<ConversionCallbackFn, 4> conversions;
 
   /// The list of registered materialization functions.
-  SmallVector<MaterializationCallbackFn, 2> argumentMaterializations;
   SmallVector<MaterializationCallbackFn, 2> sourceMaterializations;
   SmallVector<TargetMaterializationCallbackFn, 2> targetMaterializations;
 
diff --git a/mlir/include/mlir/Transforms/OneToNTypeConversion.h 
b/mlir/include/mlir/Transforms/OneToNTypeConversion.h
deleted file mode 100644
index 9c74bf916d971b..00000000000000
--- a/mlir/include/mlir/Transforms/OneToNTypeConversion.h
+++ /dev/null
@@ -1,290 +0,0 @@
-//===-- OneToNTypeConversion.h - Utils for 1:N type conversion --*- C++ 
-*-===//
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Note: The 1:N dialect conversion is deprecated and will be removed soon.
-// 1:N support has been added to the regular dialect conversion driver.
-//
-// This file provides utils for implementing (poor-man's) dialect conversion
-// passes with 1:N type conversions.
-//
-// The main function, `applyPartialOneToNConversion`, first applies a set of
-// `RewritePattern`s, which produce unrealized casts to convert the operands 
and
-// results from and to the source types, and then replaces all newly added
-// unrealized casts by user-provided materializations. For this to work, the
-// main function requires a special `TypeConverter`, a special
-// `PatternRewriter`, and special RewritePattern`s, which extend their
-// respective base classes for 1:N type converions.
-//
-// Note that this is much more simple-minded than the "real" dialect 
conversion,
-// which checks for legality before applying patterns and does probably many
-// other additional things. Ideally, some of the extensions here could be
-// integrated there.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_TRANSFORMS_ONETONTYPECONVERSION_H
-#define MLIR_TRANSFORMS_ONETONTYPECONVERSION_H
-
-#include "mlir/IR/PatternMatch.h"
-#include "mlir/Transforms/DialectConversion.h"
-#include "llvm/ADT/SmallVector.h"
-
-namespace mlir {
-
-/// Stores a 1:N mapping of types and provides several useful accessors. This
-/// class extends `SignatureConversion`, which already supports 1:N type
-/// mappings but lacks some accessors into the mapping as well as access to the
-/// original types.
-class OneToNTypeMapping : public TypeConverter::SignatureConversion {
-public:
-  OneToNTypeMapping(TypeRange originalTypes)
-      : TypeConverter::SignatureConversion(originalTypes.size()),
-        originalTypes(originalTypes) {}
-
-  using TypeConverter::SignatureConversion::getConvertedTypes;
-
-  /// Returns the list of types that corresponds to the original type at the
-  /// given index.
-  TypeRange getConvertedTypes(unsigned originalTypeNo) const;
-
-  /// Returns the list of original types.
-  TypeRange getOriginalTypes() const { return originalTypes; }
-
-  /// Returns the slice of converted values that corresponds the original value
-  /// at the given index.
-  ValueRange getConvertedValues(ValueRange convertedValues,
-                                unsigned originalValueNo) const;
-
-  /// Fills the given result vector with as many copies of the location of the
-  /// original value as the number of values it is converted to.
-  void convertLocation(Value originalValue, unsigned originalValueNo,
-                       llvm::SmallVectorImpl<Location> &result) const;
-
-  /// Fills the given result vector with as many copies of the lociation of 
each
-  /// original value as the number of values they are respectively converted 
to.
-  void convertLocations(ValueRange originalValues,
-                        llvm::SmallVectorImpl<Location> &result) const;
-
-  /// Returns true iff at least one type conversion maps an input type to a 
type
-  /// that is different from itself.
-  bool hasNonIdentityConversion() const;
-
-private:
-  llvm::SmallVector<Type> originalTypes;
-};
-
-/// Extends the basic `RewritePattern` class with a type converter member and
-/// some accessors to it. This is useful for patterns that are not
-/// `ConversionPattern`s but still require access to a type converter.
-class RewritePatternWithConverter : public mlir::RewritePattern {
-public:
-  /// Construct a conversion pattern with the given converter, and forward the
-  /// remaining arguments to RewritePattern.
-  template <typename... Args>
-  RewritePatternWithConverter(const TypeConverter &typeConverter,
-                              Args &&...args)
-      : RewritePattern(std::forward<Args>(args)...),
-        typeConverter(&typeConverter) {}
-
-  /// Return the type converter held by this pattern, or nullptr if the pattern
-  /// does not require type conversion.
-  const TypeConverter *getTypeConverter() const { return typeConverter; }
-
-  template <typename ConverterTy>
-  std::enable_if_t<std::is_base_of<TypeConverter, ConverterTy>::value,
-                   const ConverterTy *>
-  getTypeConverter() const {
-    return static_cast<const ConverterTy *>(typeConverter);
-  }
-
-protected:
-  /// A type converter for use by this pattern.
-  const TypeConverter *const typeConverter;
-};
-
-/// Specialization of `PatternRewriter` that `OneToNConversionPattern`s use. 
The
-/// class provides additional rewrite methods that are specific to 1:N type
-/// conversions.
-class OneToNPatternRewriter : public PatternRewriter {
-public:
-  OneToNPatternRewriter(MLIRContext *context,
-                        OpBuilder::Listener *listener = nullptr)
-      : PatternRewriter(context, listener) {}
-
-  /// Replaces the results of the operation with the specified list of values
-  /// mapped back to the original types as specified in the provided type
-  /// mapping. That type mapping must match the replaced op (i.e., the original
-  /// types must be the same as the result types of the op) and the new values
-  /// (i.e., the converted types must be the same as the types of the new
-  /// values).
-  /// FIXME: The 1:N dialect conversion is deprecated and will be removed soon.
-  /// 1:N support has been added to the regular dialect conversion driver.
-  LLVM_DEPRECATED("Use replaceOpWithMultiple() instead",
-                  "replaceOpWithMultiple")
-  void replaceOp(Operation *op, ValueRange newValues,
-                 const OneToNTypeMapping &resultMapping);
-  using PatternRewriter::replaceOp;
-
-  /// Applies the given argument conversion to the given block. This consists 
of
-  /// replacing each original argument with N arguments as specified in the
-  /// argument conversion and inserting unrealized casts from the converted
-  /// values to the original types, which are then used in lieu of the original
-  /// ones. (Eventually, `applyPartialOneToNConversion` replaces these casts
-  /// with a user-provided argument materialization if necessary.) This is
-  /// similar to `ArgConverter::applySignatureConversion` but (1) handles 1:N
-  /// type conversion properly and probably (2) doesn't handle many other edge
-  /// cases.
-  Block *applySignatureConversion(Block *block,
-                                  OneToNTypeMapping &argumentConversion);
-};
-
-/// Base class for patterns with 1:N type conversions. Derived classes have to
-/// overwrite the `matchAndRewrite` overlaod that provides additional
-/// information for 1:N type conversions.
-class OneToNConversionPattern : public RewritePatternWithConverter {
-public:
-  using RewritePatternWithConverter::RewritePatternWithConverter;
-
-  /// This function has to be implemented by derived classes and is called from
-  /// the usual overloads. Like in "normal" `DialectConversion`, the function 
is
-  /// provided with the converted operands (which thus have target types). 
Since
-  /// 1:N conversions are supported, there is usually no 1:1 relationship
-  /// between the original and the converted operands. Instead, the provided
-  /// `operandMapping` can be used to access the converted operands that
-  /// correspond to a particular original operand. Similarly, `resultMapping`
-  /// is provided to help with assembling the result values, which may have 1:N
-  /// correspondences as well. In that case, the original op should be replaced
-  /// with the overload of `replaceOp` that takes the provided `resultMapping`
-  /// in order to deal with the mapping of converted result values to their
-  /// usages in the original types correctly.
-  virtual LogicalResult matchAndRewrite(Operation *op,
-                                        OneToNPatternRewriter &rewriter,
-                                        const OneToNTypeMapping 
&operandMapping,
-                                        const OneToNTypeMapping &resultMapping,
-                                        ValueRange convertedOperands) const = 
0;
-
-  LogicalResult matchAndRewrite(Operation *op,
-                                PatternRewriter &rewriter) const final;
-};
-
-/// This class is a wrapper around `OneToNConversionPattern` for matching
-/// against instances of a particular op class.
-template <typename SourceOp>
-class OneToNOpConversionPattern : public OneToNConversionPattern {
-public:
-  OneToNOpConversionPattern(const TypeConverter &typeConverter,
-                            MLIRContext *context, PatternBenefit benefit = 1,
-                            ArrayRef<StringRef> generatedNames = {})
-      : OneToNConversionPattern(typeConverter, SourceOp::getOperationName(),
-                                benefit, context, generatedNames) {}
-  /// Generic adaptor around the root op of this pattern using the converted
-  /// operands. Importantly, each operand is represented as a *range* of 
values,
-  /// namely the N values each original operand gets converted to. Concretely,
-  /// this makes the result type of the accessor functions of the adaptor class
-  /// be a `ValueRange`.
-  class OpAdaptor
-      : public SourceOp::template GenericAdaptor<ArrayRef<ValueRange>> {
-  public:
-    using RangeT = ArrayRef<ValueRange>;
-    using BaseT = typename SourceOp::template GenericAdaptor<RangeT>;
-    using Properties = typename SourceOp::template 
InferredProperties<SourceOp>;
-
-    OpAdaptor(const OneToNTypeMapping *operandMapping,
-              const OneToNTypeMapping *resultMapping,
-              const ValueRange *convertedOperands, RangeT values, SourceOp op)
-        : BaseT(values, op), operandMapping(operandMapping),
-          resultMapping(resultMapping), convertedOperands(convertedOperands) {}
-
-    /// Get the type mapping of the original operands to the converted 
operands.
-    const OneToNTypeMapping &getOperandMapping() const {
-      return *operandMapping;
-    }
-
-    /// Get the type mapping of the original results to the converted results.
-    const OneToNTypeMapping &getResultMapping() const { return *resultMapping; 
}
-
-    /// Get a flat range of all converted operands. Unlike `getOperands`, which
-    /// returns an `ArrayRef` with one `ValueRange` for each original operand,
-    /// this function returns a `ValueRange` that contains all converted
-    /// operands irrespectively of which operand they originated from.
-    ValueRange getFlatOperands() const { return *convertedOperands; }
-
-  private:
-    const OneToNTypeMapping *operandMapping;
-    const OneToNTypeMapping *resultMapping;
-    const ValueRange *convertedOperands;
-  };
-
-  using OneToNConversionPattern::matchAndRewrite;
-
-  /// Overload that derived classes have to override for their op type.
-  virtual LogicalResult
-  matchAndRewrite(SourceOp op, OpAdaptor adaptor,
-                  OneToNPatternRewriter &rewriter) const = 0;
-
-  LogicalResult matchAndRewrite(Operation *op, OneToNPatternRewriter &rewriter,
-                                const OneToNTypeMapping &operandMapping,
-                                const OneToNTypeMapping &resultMapping,
-                                ValueRange convertedOperands) const final {
-    // Wrap converted operands and type mappings into an adaptor.
-    SmallVector<ValueRange> valueRanges;
-    for (int64_t i = 0; i < op->getNumOperands(); i++) {
-      auto values = operandMapping.getConvertedValues(convertedOperands, i);
-      valueRanges.push_back(values);
-    }
-    OpAdaptor adaptor(&operandMapping, &resultMapping, &convertedOperands,
-                      valueRanges, cast<SourceOp>(op));
-
-    // Call overload implemented by the derived class.
-    return matchAndRewrite(cast<SourceOp>(op), adaptor, rewriter);
-  }
-};
-
-/// Applies the given set of patterns recursively on the given op and adds user
-/// materializations where necessary. The patterns are expected to be
-/// `OneToNConversionPattern`, which help converting the types of the operands
-/// and results of the matched ops. The provided type converter is used to
-/// convert the operands of matched ops from their original types to operands
-/// with different types. Unlike in `DialectConversion`, this supports 1:N type
-/// conversions. Those conversions at the "boundary" of the pattern 
application,
-/// where converted results are not consumed by replaced ops that expect the
-/// converted operands or vice versa, the function inserts user 
materializations
-/// from the type converter. Also unlike `DialectConversion`, there are no 
legal
-/// or illegal types; the function simply applies the given patterns and does
-/// not fail if some ops or types remain unconverted (i.e., the conversion is
-/// only "partial").
-/// FIXME: The 1:N dialect ...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/121389
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to