[Mlir-commits] [mlir] [MLIR] add C-API bindings for complex dialect (PR #173228)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Mon Dec 22 02:27:03 PST 2025
Sergio =?utf-8?q?Sánchez_Ramírez?=,
Sergio =?utf-8?q?Sánchez_Ramírez?=,
Sergio =?utf-8?q?Sánchez_Ramírez?=,
Sergio =?utf-8?q?Sánchez_Ramírez?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/173228 at github.com>
================
@@ -0,0 +1,43 @@
+//===- Complex.cpp - C Interface for Complex dialect ----------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir-c/Dialect/Complex.h"
+#include "mlir-c/IR.h"
+#include "mlir-c/Support.h"
+#include "mlir/CAPI/Registration.h"
+
+MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Complex, complex,
+ mlir::complex::ComplexDialect)
+
+bool mlirAttributeIsAComplex(MlirAttribute attr) {
+ return llvm::isa<ComplexAttr>(unwrap(attr));
+}
+
+MlirAttribute mlirComplexAttrDoubleGet(MlirContext ctx, MlirType type,
+ double real, double imag) {
+ return wrap(
+ complex::NumberAttr::get(cast<ComplexType>(unwrap(type)), real, imag));
+}
+
+MlirAttribute mlirComplexAttrDoubleGetChecked(MlirLocation loc, MlirType type,
+ double real, double imag) {
+ return wrap(complex::NumberAttr::getChecked(
+ unwrap(loc), cast<ComplexType>(unwrap(type)), real, imag));
+}
+
+double mlirComplexAttrGetRealDouble(MlirAttribute attr) {
+ return llvm::cast<complex::NumberAttr>(unwrap(attr)).getRealAsDouble();
+}
+
+double mlirComplexAttrGetImagDouble(MlirAttribute attr) {
+ return llvm::cast<complex::NumberAttr>(unwrap(attr)).getImagAsDouble();
----------------
ftynse wrote:
```suggestion
return cast<complex::NumberAttr>(unwrap(attr)).getRealAsDouble();
}
double mlirComplexAttrGetImagDouble(MlirAttribute attr) {
return cast<complex::NumberAttr>(unwrap(attr)).getImagAsDouble();
```
https://github.com/llvm/llvm-project/pull/173228
More information about the Mlir-commits
mailing list