[Mlir-commits] [mlir] [mlir][Transforms] Make 1:N function conversion pattern interface-based (PR #92395)

Matthias Springer llvmlistbot at llvm.org
Thu May 16 07:03:17 PDT 2024


================
@@ -412,4 +413,62 @@ applyPartialOneToNConversion(Operation *op, OneToNTypeConverter &typeConverter,
   return success();
 }
 
+namespace {
+class FunctionOpInterfaceSignatureConversion : public OneToNConversionPattern {
+public:
+  FunctionOpInterfaceSignatureConversion(StringRef functionLikeOpName,
+                                         MLIRContext *ctx,
+                                         TypeConverter &converter)
+      : OneToNConversionPattern(converter, functionLikeOpName, /*benefit=*/1,
+                                ctx) {}
+
+  LogicalResult matchAndRewrite(Operation *op, OneToNPatternRewriter &rewriter,
+                                const OneToNTypeMapping &operandMapping,
+                                const OneToNTypeMapping &resultMapping,
+                                ValueRange convertedOperands) const override {
+    auto funcOp = cast<FunctionOpInterface>(op);
----------------
matthias-springer wrote:

The pattern gets an operation name as a constructor arg and only such ops are matched. Using this pattern with ops that do not implement `FunctionOpInterface` is incorrect API usage. `cast` will fail in such a case (I think with a failed assertion internally).


https://github.com/llvm/llvm-project/pull/92395


More information about the Mlir-commits mailing list