@@ -17,6 +17,7 @@ include "mlir/IR/BuiltinAttributeInterfaces.td"
1717include "mlir/IR/EnumAttr.td"
1818
1919include "clang/CIR/Dialect/IR/CIRDialect.td"
20+ include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
2021
2122//===----------------------------------------------------------------------===//
2223// CIR Attrs
@@ -276,6 +277,50 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
276277 }];
277278}
278279
280+ //===----------------------------------------------------------------------===//
281+ // ConstComplexAttr
282+ //===----------------------------------------------------------------------===//
283+
284+ def ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex",
285+ [TypedAttrInterface]> {
286+ let summary = "An attribute that contains a constant complex value";
287+ let description = [{
288+ The `#cir.const_complex` attribute contains a constant value of complex
289+ number type. The `real` parameter gives the real part of the complex number
290+ and the `imag` parameter gives the imaginary part of the complex number.
291+
292+ The `real` and `imag` parameters must both reference the same type and must
293+ be either IntAttr or FPAttr.
294+
295+ ```mlir
296+ %ci = #cir.const_complex<#cir.int<1> : !s32i, #cir.int<2> : !s32i>
297+ : !cir.complex<!s32i>
298+ %cf = #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float,
299+ #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
300+ ```
301+ }];
302+
303+ let parameters = (ins
304+ AttributeSelfTypeParameter<"", "cir::ComplexType">:$type,
305+ CIR_AnyIntOrFloatAttr:$real,
306+ CIR_AnyIntOrFloatAttr:$imag
307+ );
308+
309+ let builders = [
310+ AttrBuilderWithInferredContext<(ins "cir::ComplexType":$type,
311+ "mlir::TypedAttr":$real,
312+ "mlir::TypedAttr":$imag), [{
313+ return $_get(type.getContext(), type, real, imag);
314+ }]>,
315+ ];
316+
317+ let genVerifyDecl = 1;
318+
319+ let assemblyFormat = [{
320+ `<` qualified($real) `,` qualified($imag) `>`
321+ }];
322+ }
323+
279324//===----------------------------------------------------------------------===//
280325// VisibilityAttr
281326//===----------------------------------------------------------------------===//
0 commit comments