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

Maksim Levental llvmlistbot at llvm.org
Fri Sep 25 20:22:29 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.
----------------
makslevental wrote:

i don't think this is gonna ever fly? adding a TypeID to an impl class?

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


More information about the Mlir-commits mailing list