diff --git a/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td b/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td index 8b3ea0c84fb0..7e22ebfacfa0 100644 --- a/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td +++ b/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td @@ -29,6 +29,37 @@ class ComplexArithmeticOp traits = []> : let verifier = ?; } +// Base class for standard unary operations on complex numbers with a +// floating-point element type. These operations take one operand and return +// one result; the operand must be a complex number. +class ComplexUnaryOp traits = []> : + Complex_Op { + let arguments = (ins Complex:$complex); + let assemblyFormat = "$complex attr-dict `:` type($complex)"; + let verifier = ?; +} + +//===----------------------------------------------------------------------===// +// AbsOp +//===----------------------------------------------------------------------===// + +def AbsOp : ComplexUnaryOp<"abs", + [TypesMatchWith<"complex element type matches result type", + "complex", "result", + "$_self.cast().getElementType()">]> { + let summary = "computes absolute value of a complex number"; + let description = [{ + The `abs` op takes a single complex number and computes its absolute value. + + Example: + + ```mlir + %a = complex.abs %b : complex + ``` + }]; + let results = (outs AnyFloat:$result); +} + //===----------------------------------------------------------------------===// // AddOp //===----------------------------------------------------------------------===// @@ -46,32 +77,6 @@ def AddOp : ComplexArithmeticOp<"add"> { }]; } -//===----------------------------------------------------------------------===// -// AbsOp -//===----------------------------------------------------------------------===// - -def AbsOp : Complex_Op<"abs", - [NoSideEffect, - TypesMatchWith<"complex element type matches result type", - "complex", "result", - "$_self.cast().getElementType()">]> { - let summary = "computes absolute value of a complex number"; - let description = [{ - The `abs` op takes a single complex number and computes its absolute value. - - Example: - - ```mlir - %a = complex.abs %b : complex - ``` - }]; - - let arguments = (ins Complex:$complex); - let results = (outs AnyFloat:$result); - - let assemblyFormat = "$complex attr-dict `:` type($complex)"; -} - //===----------------------------------------------------------------------===// // CreateOp //===----------------------------------------------------------------------===// @@ -121,33 +126,6 @@ def DivOp : ComplexArithmeticOp<"div"> { }]; } -//===----------------------------------------------------------------------===// -// ImOp -//===----------------------------------------------------------------------===// - -def ImOp : Complex_Op<"im", - [NoSideEffect, - TypesMatchWith<"complex element type matches result type", - "complex", "imaginary", - "$_self.cast().getElementType()">]> { - let summary = "extracts the imaginary part of a complex number"; - let description = [{ - The `im` op takes a single complex number and extracts the imaginary part. - - Example: - - ```mlir - %a = complex.im %b : complex - ``` - }]; - - let arguments = (ins Complex:$complex); - let results = (outs AnyFloat:$imaginary); - - let assemblyFormat = "$complex attr-dict `:` type($complex)"; - let hasFolder = 1; -} - //===----------------------------------------------------------------------===// // EqualOp //===----------------------------------------------------------------------===// @@ -177,6 +155,29 @@ def EqualOp : Complex_Op<"eq", let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($lhs)"; } +//===----------------------------------------------------------------------===// +// ImOp +//===----------------------------------------------------------------------===// + +def ImOp : ComplexUnaryOp<"im", + [TypesMatchWith<"complex element type matches result type", + "complex", "imaginary", + "$_self.cast().getElementType()">]> { + let summary = "extracts the imaginary part of a complex number"; + let description = [{ + The `im` op takes a single complex number and extracts the imaginary part. + + Example: + + ```mlir + %a = complex.im %b : complex + ``` + }]; + + let results = (outs AnyFloat:$imaginary); + let hasFolder = 1; +} + //===----------------------------------------------------------------------===// // MulOp //===----------------------------------------------------------------------===// @@ -226,9 +227,8 @@ def NotEqualOp : Complex_Op<"neq", // ReOp //===----------------------------------------------------------------------===// -def ReOp : Complex_Op<"re", - [NoSideEffect, - TypesMatchWith<"complex element type matches result type", +def ReOp : ComplexUnaryOp<"re", + [TypesMatchWith<"complex element type matches result type", "complex", "real", "$_self.cast().getElementType()">]> { let summary = "extracts the real part of a complex number"; @@ -242,10 +242,7 @@ def ReOp : Complex_Op<"re", ``` }]; - let arguments = (ins Complex:$complex); let results = (outs AnyFloat:$real); - - let assemblyFormat = "$complex attr-dict `:` type($complex)"; let hasFolder = 1; }