@@ -68,14 +68,18 @@ def CK_FloatToBoolean : I32EnumAttrCase<"float_to_bool", 10>;
68
68
def CK_BooleanToIntegral : I32EnumAttrCase<"bool_to_int", 11>;
69
69
def CK_IntegralToFloat : I32EnumAttrCase<"int_to_float", 12>;
70
70
def CK_BooleanToFloat : I32EnumAttrCase<"bool_to_float", 13>;
71
+ def CK_IntegralToComplex : I32EnumAttrCase<"int_to_complex", 14>;
72
+ def CK_FloatToComplex : I32EnumAttrCase<"float_to_complex", 15>;
73
+ def CK_ComplexCast : I32EnumAttrCase<"complex", 16>;
71
74
72
75
def CastKind : I32EnumAttr<
73
76
"CastKind",
74
77
"cast kind",
75
78
[CK_IntegralToBoolean, CK_ArrayToPointerDecay, CK_IntegralCast,
76
79
CK_BitCast, CK_FloatingCast, CK_PtrToBoolean, CK_FloatToIntegral,
77
80
CK_IntegralToPointer, CK_PointerToIntegral, CK_FloatToBoolean,
78
- CK_BooleanToIntegral, CK_IntegralToFloat, CK_BooleanToFloat]> {
81
+ CK_BooleanToIntegral, CK_IntegralToFloat, CK_BooleanToFloat,
82
+ CK_IntegralToComplex, CK_FloatToComplex, CK_ComplexCast]> {
79
83
let cppNamespace = "::mlir::cir";
80
84
}
81
85
@@ -97,6 +101,8 @@ def CastOp : CIR_Op<"cast", [Pure]> {
97
101
- `ptr_to_bool`
98
102
- `bool_to_int`
99
103
- `bool_to_float`
104
+ - `int_to_complex`
105
+ - `float_to_complex`
100
106
101
107
This is effectively a subset of the rules from
102
108
`llvm-project/clang/include/clang/AST/OperationKinds.def`; but note that some
@@ -823,6 +829,7 @@ def UnaryOpKind_Dec : I32EnumAttrCase<"Dec", 2, "dec">;
823
829
def UnaryOpKind_Plus : I32EnumAttrCase<"Plus", 3, "plus">;
824
830
def UnaryOpKind_Minus : I32EnumAttrCase<"Minus", 4, "minus">;
825
831
def UnaryOpKind_Not : I32EnumAttrCase<"Not", 5, "not">;
832
+ def UnaryOpKind_Conjugate : I32EnumAttrCase<"Conjugate", 6, "conjugate">;
826
833
827
834
def UnaryOpKind : I32EnumAttr<
828
835
"UnaryOpKind",
@@ -832,6 +839,7 @@ def UnaryOpKind : I32EnumAttr<
832
839
UnaryOpKind_Plus,
833
840
UnaryOpKind_Minus,
834
841
UnaryOpKind_Not,
842
+ UnaryOpKind_Conjugate,
835
843
]> {
836
844
let cppNamespace = "::mlir::cir";
837
845
}
@@ -995,6 +1003,98 @@ def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
995
1003
let hasVerifier = 0;
996
1004
}
997
1005
1006
+ //===----------------------------------------------------------------------===//
1007
+ // ComplexCreateOp
1008
+ //===----------------------------------------------------------------------===//
1009
+
1010
+ def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
1011
+ let summary = "Create a new complex value from its real and imaginary parts";
1012
+ let description = [{
1013
+ The `cir.complex.create` operation takes two operands of the same type and
1014
+ returns a value of `!cir.complex` type. The real and imaginary part of the
1015
+ returned complex value is specified by the operands.
1016
+
1017
+ The element type of the returned complex value is the same as the type of
1018
+ the operand. The type of the two operands must be either an integer type or
1019
+ a floating-point type.
1020
+
1021
+ Example:
1022
+
1023
+ ```mlir
1024
+ !u32i = !cir.int<u, 32>
1025
+ !complex = !cir.complex<!u32i>
1026
+
1027
+ %0 = cir.const(#cir.int<1> : !u32i) : !u32i
1028
+ %1 = cir.const(#cir.int<2> : !u32i) : !u32i
1029
+ %2 = cir.complex.create(%0 : !u32i, %1) : !complex
1030
+ ```
1031
+ }];
1032
+
1033
+ let results = (outs CIR_ComplexType:$result);
1034
+ let arguments = (ins CIR_AnyType:$real, CIR_AnyType:$imag);
1035
+
1036
+ let assemblyFormat = [{
1037
+ `(` $real `:` qualified(type($real)) `,` $imag `)`
1038
+ `:` type($result) attr-dict
1039
+ }];
1040
+
1041
+ let hasVerifier = 1;
1042
+ }
1043
+
1044
+ //===----------------------------------------------------------------------===//
1045
+ // ComplexRealOp and ComplexImagOp
1046
+ //===----------------------------------------------------------------------===//
1047
+
1048
+ def ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
1049
+ let summary = "Extract the real part of a complex value";
1050
+ let description = [{
1051
+ `cir.complex.real` operation takes an operand of complex type and returns
1052
+ the real part of it.
1053
+
1054
+ Example:
1055
+
1056
+ ```mlir
1057
+ !complex = !cir.complex<!cir.float>
1058
+ %0 = cir.const(#cir.complex<#cir.fp<1.0>, #cir.fp<2.0>> : !complex) : !complex
1059
+ %1 = cir.complex.real(%0 : !complex) : !cir.float
1060
+ ```
1061
+ }];
1062
+
1063
+ let results = (outs CIR_AnyType:$result);
1064
+ let arguments = (ins CIR_ComplexType:$operand);
1065
+
1066
+ let assemblyFormat = [{
1067
+ `(` $operand `:` qualified(type($operand)) `)` `:` type($result) attr-dict
1068
+ }];
1069
+
1070
+ let hasVerifier = 1;
1071
+ }
1072
+
1073
+ def ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
1074
+ let summary = "Extract the imaginary part of a complex value";
1075
+ let description = [{
1076
+ `cir.complex.imag` operation takes an operand of complex type and returns
1077
+ the imaginary part of it.
1078
+
1079
+ Example:
1080
+
1081
+ ```mlir
1082
+ !complex = !cir.complex<!cir.float>
1083
+ %0 = cir.const(#cir.complex<#cir.fp<1.0>, #cir.fp<2.0>> : !complex) : !complex
1084
+ %1 = cir.complex.imag(%0 : !complex) : !cir.float
1085
+ ```
1086
+ }];
1087
+
1088
+ let results = (outs CIR_AnyType:$result);
1089
+ let arguments = (ins CIR_ComplexType:$operand);
1090
+
1091
+ let assemblyFormat = [{
1092
+ `(` $operand `:` qualified(type($operand)) `)` `:` type($result) attr-dict
1093
+ }];
1094
+
1095
+ let hasVerifier = 1;
1096
+ }
1097
+
998
1098
//===----------------------------------------------------------------------===//
999
1099
// BitsOp
1000
1100
//===----------------------------------------------------------------------===//
0 commit comments