[Mlir-commits] [mlir] [MLIR][Python] Support dynamic traits in python-defined dialects (PR #179705)
Rolf Morel
llvmlistbot at llvm.org
Mon Feb 9 06:45:13 PST 2026
================
@@ -0,0 +1,76 @@
+//===-- mlir-c/ExtensibleDialect.h - Extensible dialect APIs -----*- C -*-====//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
+// Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This header provides APIs for extensible dialects.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_C_EXTENSIBLEDIALECT_H
+#define MLIR_C_EXTENSIBLEDIALECT_H
+
+#include "mlir-c/IR.h"
+#include "mlir-c/Support.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//===----------------------------------------------------------------------===//
+/// Opaque type declarations (see mlir-c/IR.h for more details).
+//===----------------------------------------------------------------------===//
+
+#define DEFINE_C_API_STRUCT(name, storage) \
+ struct name { \
+ storage *ptr; \
+ }; \
+ typedef struct name name
+
+DEFINE_C_API_STRUCT(MlirDynamicOpTrait, void);
+
+/// Attach a dynamic op trait to the given operation name.
+/// Note that the operation name must be modeled by dynamic dialect and must be
+/// registered.
+/// The ownership of the trait will be transferred to the operation name
+/// after this call.
+MLIR_CAPI_EXPORTED bool
+mlirDynamicOpTraitAttach(MlirDynamicOpTrait dynamicOpTrait,
+ MlirStringRef opName, MlirContext context);
+
+/// Get the dynamic op trait that indicates the operation is a terminator.
+MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitGetIsTerminator(void);
----------------
rolfmorel wrote:
```suggestion
MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitIsTerminatorCreate(void);
```
> [functions that create a new object have the name mlirXCreate<...>, for example, mlirOperationCreate;](https://mlir.llvm.org/docs/CAPI/#naming-convention-and-ownership-model:~:text=functions%20that%20create%20a%20new%20object%20have%20the%20name%20mlirXCreate%3C%2E%2E%2E%3E%2C%20for%20example%2C%20mlirOperationCreate%3B)
The implementation uses `new`, right? (Based on the name, I thought that maybe a Singleton pattern was being applied.)
https://github.com/llvm/llvm-project/pull/179705
More information about the Mlir-commits
mailing list