[Mlir-commits] [mlir] [MLIR][Python] Support canonicalization hooks for Python-defined ops (PR #224806)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 25 21:33:37 PDT 2026


================
@@ -226,3 +208,47 @@ MlirDialect
 mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef) {
   return wrap(unwrap(attrDef)->getDialect());
 }
+
+MlirDynamicOpDefinition mlirDynamicOpDefinitionLookup(MlirStringRef opName,
+                                                      MlirContext context) {
+  std::optional<RegisteredOperationName> opNameFound =
+      RegisteredOperationName::lookup(unwrap(opName), unwrap(context));
+  assert(opNameFound && "operation name must be registered in the context");
+
+  // The original getImpl() is protected, so we create a small helper struct
+  // here.
+  struct RegisteredOperationNameWithImpl : RegisteredOperationName {
+    Impl *getImpl() { return RegisteredOperationName::getImpl(); }
+  };
+  OperationName::Impl *impl =
+      static_cast<RegisteredOperationNameWithImpl &>(*opNameFound).getImpl();
+
+  // TODO: we should enable llvm-style RTTI for `OperationName::Impl` and check
+  // whether the `impl` is a `DynamicOpDefinition` here.
----------------
PragmaTwice wrote:

ahh it's because `DynamicOpDefinition` is a subclass of `OperationName::Impl`. if we can make it RTTI enabled (llvm-style or something else) we can then add a check here. currently we cannot distinguish between `DynamicOpDefinition` and other subclasses.

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


More information about the Mlir-commits mailing list