[Mlir-commits] [mlir] b20d7d0 - [MLIR][IR] Convert `DialectFoldInterface` to ODS (#180833)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Feb 12 01:41:13 PST 2026


Author: AidinT
Date: 2026-02-12T10:41:07+01:00
New Revision: b20d7d0278059735bb8eb538ac51e13b58895c1a

URL: https://github.com/llvm/llvm-project/commit/b20d7d0278059735bb8eb538ac51e13b58895c1a
DIFF: https://github.com/llvm/llvm-project/commit/b20d7d0278059735bb8eb538ac51e13b58895c1a.diff

LOG: [MLIR][IR] Convert `DialectFoldInterface` to ODS (#180833)

This PR converts `DialectFoldInterface` to ODS.

Added: 
    mlir/include/mlir/Interfaces/DialectFoldInterface.td

Modified: 
    mlir/include/mlir/Interfaces/CMakeLists.txt
    mlir/include/mlir/Interfaces/FoldInterfaces.h
    mlir/lib/IR/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Interfaces/CMakeLists.txt b/mlir/include/mlir/Interfaces/CMakeLists.txt
index eb96a68861116..7a35654998ba5 100644
--- a/mlir/include/mlir/Interfaces/CMakeLists.txt
+++ b/mlir/include/mlir/Interfaces/CMakeLists.txt
@@ -37,6 +37,11 @@ mlir_tablegen(DataLayoutTypeInterface.h.inc -gen-type-interface-decls)
 mlir_tablegen(DataLayoutTypeInterface.cpp.inc -gen-type-interface-defs)
 add_mlir_generic_tablegen_target(MLIRDataLayoutInterfacesIncGen)
 
+set(LLVM_TARGET_DEFINITIONS DialectFoldInterface.td)
+mlir_tablegen(DialectFoldInterface.h.inc -gen-dialect-interface-decls)
+add_mlir_generic_tablegen_target(MLIRDialectFoldInterfaceIncGen)
+
+
 add_mlir_doc(DataLayoutInterfaces
   DataLayoutAttrInterface
   Interfaces/

diff  --git a/mlir/include/mlir/Interfaces/DialectFoldInterface.td b/mlir/include/mlir/Interfaces/DialectFoldInterface.td
new file mode 100644
index 0000000000000..138be794f605c
--- /dev/null
+++ b/mlir/include/mlir/Interfaces/DialectFoldInterface.td
@@ -0,0 +1,46 @@
+#ifndef MLIR_INTERFACES_DIALECTFOLDINTERFACE
+#define MLIR_INTERFACES_DIALECTFOLDINTERFACE
+
+include "mlir/IR/Interfaces.td"
+
+def DialectFoldInterface : DialectInterface<"DialectFoldInterface"> {
+  let description = [{
+    Define a fold interface to allow for dialects to control specific aspects
+    of the folding behavior for operations they define.
+  }];
+  let cppNamespace = "::mlir";
+
+  let methods = [
+    InterfaceMethod<[{
+        Registered fallback fold for the dialect. Like the fold hook of each
+        operation, it attempts to fold the operation with the specified constant
+        operand values - the elements in "operands" will correspond directly to
+        the operands of the operation, but may be null if non-constant.  If
+        folding is successful, this fills in the `results` vector.  If not, this
+        returns failure and `results` is unspecified.
+      }],
+      "::mlir::LogicalResult", "fold",
+      (ins "::mlir::Operation *":$op, "::mlir::ArrayRef<Attribute>":$operands,
+           "::mlir::SmallVectorImpl<OpFoldResult> &":$results),
+      [{
+        return failure();
+      }]
+    >,
+    InterfaceMethod<[{
+        Registered hook to check if the given region, which is attached to an
+        operation that is *not* isolated from above, should be used when
+        materializing constants. The folder will generally materialize constants
+        into the top-level isolated region, this allows for materializing into a
+        lower level ancestor region if it is more profitable/correct.
+      }],
+      "bool", "shouldMaterializeInto",
+      (ins "::mlir::Region *":$region),
+      [{
+        return false;
+      }]
+    > 
+  ];
+}
+
+
+#endif

diff  --git a/mlir/include/mlir/Interfaces/FoldInterfaces.h b/mlir/include/mlir/Interfaces/FoldInterfaces.h
index b3d116101149f..5a4247d848d18 100644
--- a/mlir/include/mlir/Interfaces/FoldInterfaces.h
+++ b/mlir/include/mlir/Interfaces/FoldInterfaces.h
@@ -16,33 +16,8 @@ namespace mlir {
 class Attribute;
 class OpFoldResult;
 class Region;
-
-/// Define a fold interface to allow for dialects to control specific aspects
-/// of the folding behavior for operations they define.
-class DialectFoldInterface
-    : public DialectInterface::Base<DialectFoldInterface> {
-public:
-  DialectFoldInterface(Dialect *dialect) : Base(dialect) {}
-
-  /// Registered fallback fold for the dialect. Like the fold hook of each
-  /// operation, it attempts to fold the operation with the specified constant
-  /// operand values - the elements in "operands" will correspond directly to
-  /// the operands of the operation, but may be null if non-constant.  If
-  /// folding is successful, this fills in the `results` vector.  If not, this
-  /// returns failure and `results` is unspecified.
-  virtual LogicalResult fold(Operation *op, ArrayRef<Attribute> operands,
-                             SmallVectorImpl<OpFoldResult> &results) const {
-    return failure();
-  }
-
-  /// Registered hook to check if the given region, which is attached to an
-  /// operation that is *not* isolated from above, should be used when
-  /// materializing constants. The folder will generally materialize constants
-  /// into the top-level isolated region, this allows for materializing into a
-  /// lower level ancestor region if it is more profitable/correct.
-  virtual bool shouldMaterializeInto(Region *region) const { return false; }
-};
-
 } // namespace mlir
 
+#include "mlir/Interfaces/DialectFoldInterface.h.inc"
+
 #endif // MLIR_INTERFACES_FOLDINTERFACES_H_

diff  --git a/mlir/lib/IR/CMakeLists.txt b/mlir/lib/IR/CMakeLists.txt
index 632b06e4378f2..6cadc3131ccd4 100644
--- a/mlir/lib/IR/CMakeLists.txt
+++ b/mlir/lib/IR/CMakeLists.txt
@@ -63,6 +63,7 @@ add_mlir_library(MLIRIR
   MLIRCallInterfacesIncGen
   MLIRCastInterfacesIncGen
   MLIRDataLayoutInterfacesIncGen
+  MLIRDialectFoldInterfaceIncGen
   MLIROpAsmInterfaceIncGen
   MLIRQuantStorageTypeInterfaceIncGen
   MLIRRegionKindInterfaceIncGen


        


More information about the Mlir-commits mailing list