MLIR 22.0.0git
Complex.cpp
Go to the documentation of this file.
1//===- Complex.cpp - C Interface for Complex dialect ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "mlir-c/IR.h"
11#include "mlir-c/Support.h"
14
15using namespace mlir;
16
18 mlir::complex::ComplexDialect)
19
20bool mlirAttributeIsAComplex(MlirAttribute attr) {
21 return isa<complex::NumberAttr>(unwrap(attr));
22}
23
24MlirAttribute mlirComplexAttrDoubleGet(MlirContext ctx, MlirType type,
25 double real, double imag) {
26 return wrap(
27 complex::NumberAttr::get(cast<ComplexType>(unwrap(type)), real, imag));
28}
29
30MlirAttribute mlirComplexAttrDoubleGetChecked(MlirLocation loc, MlirType type,
31 double real, double imag) {
32 return wrap(complex::NumberAttr::getChecked(
33 unwrap(loc), cast<ComplexType>(unwrap(type)), real, imag));
34}
35
36double mlirComplexAttrGetRealDouble(MlirAttribute attr) {
37 return cast<complex::NumberAttr>(unwrap(attr)).getReal().convertToDouble();
38}
39
40double mlirComplexAttrGetImagDouble(MlirAttribute attr) {
41 return cast<complex::NumberAttr>(unwrap(attr)).getImag().convertToDouble();
42}
43
44MlirTypeID mlirComplexAttrGetTypeID(void) {
45 return wrap(complex::NumberAttr::getTypeID());
46}
double mlirComplexAttrGetImagDouble(MlirAttribute attr)
Returns the imaginaryvalue stored in the given complex attribute, interpreting the value as double.
Definition Complex.cpp:40
MlirAttribute mlirComplexAttrDoubleGetChecked(MlirLocation loc, MlirType type, double real, double imag)
Same as "mlirComplexAttrDoubleGet", but if the type is not valid for a construction of a ComplexAttr,...
Definition Complex.cpp:30
double mlirComplexAttrGetRealDouble(MlirAttribute attr)
Returns the real value stored in the given complex attribute, interpreting the value as double.
Definition Complex.cpp:36
MlirAttribute mlirComplexAttrDoubleGet(MlirContext ctx, MlirType type, double real, double imag)
Creates a complex attribute in the given context with the given double real and imaginary values and ...
Definition Complex.cpp:24
MlirTypeID mlirComplexAttrGetTypeID(void)
Returns the typeID of a Complex attribute.
Definition Complex.cpp:44
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
MLIR_CAPI_EXPORTED bool mlirAttributeIsAComplex(MlirAttribute attr)
Checks whether the given attribute is a complex attribute.
Include the generated interface declarations.