@@ -1210,12 +1210,64 @@ def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
1210
1210
let hasVerifier = 1;
1211
1211
}
1212
1212
1213
+ //===----------------------------------------------------------------------===//
1214
+ // ComplexRealOp and ComplexImagOp
1215
+ //===----------------------------------------------------------------------===//
1216
+
1217
+ def ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
1218
+ let summary = "Extract the real part of a complex value";
1219
+ let description = [{
1220
+ `cir.complex.real` operation takes an operand of `!cir.complex` type and
1221
+ yields the real part of it.
1222
+
1223
+ Example:
1224
+
1225
+ ```mlir
1226
+ %1 = cir.complex.real %0 : !cir.complex<!cir.float> -> !cir.float
1227
+ ```
1228
+ }];
1229
+
1230
+ let results = (outs CIR_AnyIntOrFloat:$result);
1231
+ let arguments = (ins CIR_ComplexType:$operand);
1232
+
1233
+ let assemblyFormat = [{
1234
+ $operand `:` qualified(type($operand)) `->` qualified(type($result))
1235
+ attr-dict
1236
+ }];
1237
+
1238
+ let hasVerifier = 1;
1239
+ }
1240
+
1241
+ def ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
1242
+ let summary = "Extract the imaginary part of a complex value";
1243
+ let description = [{
1244
+ `cir.complex.imag` operation takes an operand of `!cir.complex` type and
1245
+ yields the imaginary part of it.
1246
+
1247
+ Example:
1248
+
1249
+ ```mlir
1250
+ %1 = cir.complex.imag %0 : !cir.complex<!cir.float> -> !cir.float
1251
+ ```
1252
+ }];
1253
+
1254
+ let results = (outs CIR_AnyIntOrFloat:$result);
1255
+ let arguments = (ins CIR_ComplexType:$operand);
1256
+
1257
+ let assemblyFormat = [{
1258
+ $operand `:` qualified(type($operand)) `->` qualified(type($result))
1259
+ attr-dict
1260
+ }];
1261
+
1262
+ let hasVerifier = 1;
1263
+ }
1264
+
1213
1265
//===----------------------------------------------------------------------===//
1214
1266
// ComplexRealPtrOp and ComplexImagPtrOp
1215
1267
//===----------------------------------------------------------------------===//
1216
1268
1217
1269
def ComplexRealPtrOp : CIR_Op<"complex.real_ptr", [Pure]> {
1218
- let summary = "Extract the real part of a complex value";
1270
+ let summary = "Derive a pointer to the real part of a complex value";
1219
1271
let description = [{
1220
1272
`cir.complex.real_ptr` operation takes a pointer operand that points to a
1221
1273
complex value of type `!cir.complex` and yields a pointer to the real part
@@ -1240,7 +1292,7 @@ def ComplexRealPtrOp : CIR_Op<"complex.real_ptr", [Pure]> {
1240
1292
}
1241
1293
1242
1294
def ComplexImagPtrOp : CIR_Op<"complex.imag_ptr", [Pure]> {
1243
- let summary = "Extract the imaginary part of a complex value";
1295
+ let summary = "Derive a pointer to the imaginary part of a complex value";
1244
1296
let description = [{
1245
1297
`cir.complex.imag_ptr` operation takes a pointer operand that points to a
1246
1298
complex value of type `!cir.complex` and yields a pointer to the imaginary
@@ -1264,6 +1316,68 @@ def ComplexImagPtrOp : CIR_Op<"complex.imag_ptr", [Pure]> {
1264
1316
let hasVerifier = 1;
1265
1317
}
1266
1318
1319
+ //===----------------------------------------------------------------------===//
1320
+ // ComplexBinOp
1321
+ //===----------------------------------------------------------------------===//
1322
+
1323
+ def ComplexBinOpKind : I32EnumAttr<
1324
+ "ComplexBinOpKind",
1325
+ "complex number binary operation kind",
1326
+ [BinOpKind_Mul, BinOpKind_Div]> {
1327
+ let cppNamespace = "::mlir::cir";
1328
+ }
1329
+
1330
+ def ComplexRangeKind_Full : I32EnumAttrCase<"Full", 1, "full">;
1331
+ def ComplexRangeKind_Improved : I32EnumAttrCase<"Improved", 2, "improved">;
1332
+ def ComplexRangeKind_Promoted : I32EnumAttrCase<"Promoted", 3, "promoted">;
1333
+ def ComplexRangeKind_Basic : I32EnumAttrCase<"Basic", 4, "basic">;
1334
+ def ComplexRangeKind_None : I32EnumAttrCase<"None", 5, "none">;
1335
+
1336
+ def ComplexRangeKind : I32EnumAttr<
1337
+ "ComplexRangeKind",
1338
+ "complex multiplication and division implementation",
1339
+ [ComplexRangeKind_Full, ComplexRangeKind_Improved,
1340
+ ComplexRangeKind_Promoted, ComplexRangeKind_Basic,
1341
+ ComplexRangeKind_None]> {
1342
+ let cppNamespace = "::mlir::cir";
1343
+ }
1344
+
1345
+ def ComplexBinOp : CIR_Op<"complex.binop",
1346
+ [Pure, SameTypeOperands, SameOperandsAndResultType]> {
1347
+ let summary = "Binary operations on operands of complex type";
1348
+ let description = [{
1349
+ The `cir.complex.binop` operation represents a binary operation on operands
1350
+ of C complex type (e.g. `float _Complex`). The operation can only represent
1351
+ binary multiplication or division on complex numbers; other binary
1352
+ operations, such as addition and subtraction, are represented by the
1353
+ `cir.binop` operation.
1354
+
1355
+ The operation requires two input operands and has one result. The types of
1356
+ all the operands and the result should be of the same `!cir.complex` type.
1357
+
1358
+ The operation also takes a `range` attribute that specifies the complex
1359
+ range of the binary operation.
1360
+
1361
+ Examples:
1362
+
1363
+ ```mlir
1364
+ %2 = cir.complex.binop add %0, %1 : !cir.complex<!cir.float>
1365
+ %2 = cir.complex.binop mul %0, %1 : !cir.complex<!cir.float>
1366
+ ```
1367
+ }];
1368
+
1369
+ let results = (outs CIR_ComplexType:$result);
1370
+ let arguments = (ins Arg<ComplexBinOpKind, "operation kind">:$kind,
1371
+ CIR_ComplexType:$lhs, CIR_ComplexType:$rhs,
1372
+ Arg<ComplexRangeKind, "complex range kind">:$range,
1373
+ UnitAttr:$promoted);
1374
+
1375
+ let assemblyFormat = [{
1376
+ $kind $lhs `,` $rhs `range` `(` $range `)` (`promoted` $promoted^)?
1377
+ `:` qualified(type($lhs)) attr-dict
1378
+ }];
1379
+ }
1380
+
1267
1381
//===----------------------------------------------------------------------===//
1268
1382
// BitsOp
1269
1383
//===----------------------------------------------------------------------===//
0 commit comments