[Mlir-commits] [mlir] [mlir][CAPI] Add C API for creating dynamic dialects, ops, types, and attrs (PR #187239)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Mar 19 08:28:01 PDT 2026


================
@@ -31,12 +31,128 @@ extern "C" {
   };                                                                           \
   typedef struct name name
 
+DEFINE_C_API_STRUCT(MlirDynamicDialect, void);
+DEFINE_C_API_STRUCT(MlirDynamicOpDefinition, void);
 DEFINE_C_API_STRUCT(MlirDynamicOpTrait, void);
 DEFINE_C_API_STRUCT(MlirDynamicTypeDefinition, void);
 DEFINE_C_API_STRUCT(MlirDynamicAttrDefinition, void);
 
 #undef DEFINE_C_API_STRUCT
 
+//===----------------------------------------------------------------------===//
+/// Dynamic dialect creation
+//===----------------------------------------------------------------------===//
+
+/// Create a new dynamic dialect with the given name and register it with the
+/// context. If a dialect with the same name already exists, returns the
+/// existing one. The context takes ownership of the dialect. The returned
+/// handle is valid as long as the context is alive and must not be freed.
+MLIR_CAPI_EXPORTED MlirDynamicDialect
+mlirDynamicDialectCreate(MlirContext ctx, MlirStringRef name);
+
+/// Get the underlying MlirDialect from a MlirDynamicDialect.
+MLIR_CAPI_EXPORTED MlirDialect
+mlirDynamicDialectGetDialect(MlirDynamicDialect dialect);
----------------
PragmaTwice wrote:

```suggestion
MLIR_CAPI_EXPORTED MlirDialect
mlirDynamicDialectAsDialect(MlirDynamicDialect dialect);
```

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


More information about the Mlir-commits mailing list