@@ -69,14 +69,18 @@ def CK_FloatToBoolean : I32EnumAttrCase<"float_to_bool", 10>;
69
69
def CK_BooleanToIntegral : I32EnumAttrCase<"bool_to_int", 11>;
70
70
def CK_IntegralToFloat : I32EnumAttrCase<"int_to_float", 12>;
71
71
def CK_BooleanToFloat : I32EnumAttrCase<"bool_to_float", 13>;
72
+ def CK_IntegralToComplex : I32EnumAttrCase<"int_to_complex", 14>;
73
+ def CK_FloatToComplex : I32EnumAttrCase<"float_to_complex", 15>;
74
+ def CK_ComplexCast : I32EnumAttrCase<"complex", 16>;
72
75
73
76
def CastKind : I32EnumAttr<
74
77
"CastKind",
75
78
"cast kind",
76
79
[CK_IntegralToBoolean, CK_ArrayToPointerDecay, CK_IntegralCast,
77
80
CK_BitCast, CK_FloatingCast, CK_PtrToBoolean, CK_FloatToIntegral,
78
81
CK_IntegralToPointer, CK_PointerToIntegral, CK_FloatToBoolean,
79
- CK_BooleanToIntegral, CK_IntegralToFloat, CK_BooleanToFloat]> {
82
+ CK_BooleanToIntegral, CK_IntegralToFloat, CK_BooleanToFloat,
83
+ CK_IntegralToComplex, CK_FloatToComplex, CK_ComplexCast]> {
80
84
let cppNamespace = "::mlir::cir";
81
85
}
82
86
@@ -98,6 +102,8 @@ def CastOp : CIR_Op<"cast", [Pure]> {
98
102
- `ptr_to_bool`
99
103
- `bool_to_int`
100
104
- `bool_to_float`
105
+ - `int_to_complex`
106
+ - `float_to_complex`
101
107
102
108
This is effectively a subset of the rules from
103
109
`llvm-project/clang/include/clang/AST/OperationKinds.def`; but note that some
@@ -920,6 +926,7 @@ def UnaryOpKind_Dec : I32EnumAttrCase<"Dec", 2, "dec">;
920
926
def UnaryOpKind_Plus : I32EnumAttrCase<"Plus", 3, "plus">;
921
927
def UnaryOpKind_Minus : I32EnumAttrCase<"Minus", 4, "minus">;
922
928
def UnaryOpKind_Not : I32EnumAttrCase<"Not", 5, "not">;
929
+ def UnaryOpKind_Conjugate : I32EnumAttrCase<"Conjugate", 6, "conjugate">;
923
930
924
931
def UnaryOpKind : I32EnumAttr<
925
932
"UnaryOpKind",
@@ -929,6 +936,7 @@ def UnaryOpKind : I32EnumAttr<
929
936
UnaryOpKind_Plus,
930
937
UnaryOpKind_Minus,
931
938
UnaryOpKind_Not,
939
+ UnaryOpKind_Conjugate,
932
940
]> {
933
941
let cppNamespace = "::mlir::cir";
934
942
}
@@ -1154,6 +1162,98 @@ def BinOpOverflowOp : CIR_Op<"binop.overflow", [Pure, SameTypeOperands]> {
1154
1162
];
1155
1163
}
1156
1164
1165
+ //===----------------------------------------------------------------------===//
1166
+ // ComplexCreateOp
1167
+ //===----------------------------------------------------------------------===//
1168
+
1169
+ def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
1170
+ let summary = "Create a new complex value from its real and imaginary parts";
1171
+ let description = [{
1172
+ The `cir.complex.create` operation takes two operands of the same type and
1173
+ returns a value of `!cir.complex` type. The real and imaginary part of the
1174
+ returned complex value is specified by the operands.
1175
+
1176
+ The element type of the returned complex value is the same as the type of
1177
+ the operand. The type of the two operands must be either an integer type or
1178
+ a floating-point type.
1179
+
1180
+ Example:
1181
+
1182
+ ```mlir
1183
+ !u32i = !cir.int<u, 32>
1184
+ !complex = !cir.complex<!u32i>
1185
+
1186
+ %0 = cir.const(#cir.int<1> : !u32i) : !u32i
1187
+ %1 = cir.const(#cir.int<2> : !u32i) : !u32i
1188
+ %2 = cir.complex.create(%0 : !u32i, %1) : !complex
1189
+ ```
1190
+ }];
1191
+
1192
+ let results = (outs CIR_ComplexType:$result);
1193
+ let arguments = (ins CIR_AnyType:$real, CIR_AnyType:$imag);
1194
+
1195
+ let assemblyFormat = [{
1196
+ `(` $real `:` qualified(type($real)) `,` $imag `)`
1197
+ `:` type($result) attr-dict
1198
+ }];
1199
+
1200
+ let hasVerifier = 1;
1201
+ }
1202
+
1203
+ //===----------------------------------------------------------------------===//
1204
+ // ComplexRealOp and ComplexImagOp
1205
+ //===----------------------------------------------------------------------===//
1206
+
1207
+ def ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
1208
+ let summary = "Extract the real part of a complex value";
1209
+ let description = [{
1210
+ `cir.complex.real` operation takes an operand of complex type and returns
1211
+ the real part of it.
1212
+
1213
+ Example:
1214
+
1215
+ ```mlir
1216
+ !complex = !cir.complex<!cir.float>
1217
+ %0 = cir.const(#cir.complex<#cir.fp<1.0>, #cir.fp<2.0>> : !complex) : !complex
1218
+ %1 = cir.complex.real(%0 : !complex) : !cir.float
1219
+ ```
1220
+ }];
1221
+
1222
+ let results = (outs CIR_AnyType:$result);
1223
+ let arguments = (ins CIR_ComplexType:$operand);
1224
+
1225
+ let assemblyFormat = [{
1226
+ `(` $operand `:` qualified(type($operand)) `)` `:` type($result) attr-dict
1227
+ }];
1228
+
1229
+ let hasVerifier = 1;
1230
+ }
1231
+
1232
+ def ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
1233
+ let summary = "Extract the imaginary part of a complex value";
1234
+ let description = [{
1235
+ `cir.complex.imag` operation takes an operand of complex type and returns
1236
+ the imaginary part of it.
1237
+
1238
+ Example:
1239
+
1240
+ ```mlir
1241
+ !complex = !cir.complex<!cir.float>
1242
+ %0 = cir.const(#cir.complex<#cir.fp<1.0>, #cir.fp<2.0>> : !complex) : !complex
1243
+ %1 = cir.complex.imag(%0 : !complex) : !cir.float
1244
+ ```
1245
+ }];
1246
+
1247
+ let results = (outs CIR_AnyType:$result);
1248
+ let arguments = (ins CIR_ComplexType:$operand);
1249
+
1250
+ let assemblyFormat = [{
1251
+ `(` $operand `:` qualified(type($operand)) `)` `:` type($result) attr-dict
1252
+ }];
1253
+
1254
+ let hasVerifier = 1;
1255
+ }
1256
+
1157
1257
//===----------------------------------------------------------------------===//
1158
1258
// BitsOp
1159
1259
//===----------------------------------------------------------------------===//
0 commit comments