|
10 | 10 | #define ARITH_OPS |
11 | 11 |
|
12 | 12 | include "mlir/Dialect/Arith/IR/ArithBase.td" |
| 13 | +include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.td" |
13 | 14 | include "mlir/Interfaces/CastInterfaces.td" |
14 | 15 | include "mlir/Interfaces/InferIntRangeInterface.td" |
15 | 16 | include "mlir/Interfaces/InferTypeOpInterface.td" |
16 | 17 | include "mlir/Interfaces/SideEffectInterfaces.td" |
17 | 18 | include "mlir/Interfaces/VectorInterfaces.td" |
18 | 19 | include "mlir/IR/BuiltinAttributeInterfaces.td" |
19 | 20 | include "mlir/IR/OpAsmInterface.td" |
| 21 | +include "mlir/IR/EnumAttr.td" |
| 22 | + |
| 23 | +def Arith_FastMathAttr : |
| 24 | + EnumAttr<Arith_Dialect, FastMathFlags, "fastmath"> { |
| 25 | + let assemblyFormat = "`<` $value `>`"; |
| 26 | +} |
20 | 27 |
|
21 | 28 | // Base class for Arith dialect ops. Ops in this dialect have no side |
22 | 29 | // effects and can be applied element-wise to vectors and tensors. |
@@ -58,15 +65,27 @@ class Arith_IntBinaryOp<string mnemonic, list<Trait> traits = []> : |
58 | 65 |
|
59 | 66 | // Base class for floating point unary operations. |
60 | 67 | class Arith_FloatUnaryOp<string mnemonic, list<Trait> traits = []> : |
61 | | - Arith_UnaryOp<mnemonic, traits>, |
62 | | - Arguments<(ins FloatLike:$operand)>, |
63 | | - Results<(outs FloatLike:$result)>; |
| 68 | + Arith_UnaryOp<mnemonic, |
| 69 | + !listconcat([DeclareOpInterfaceMethods<ArithFastMathInterface>], |
| 70 | + traits)>, |
| 71 | + Arguments<(ins FloatLike:$operand, |
| 72 | + DefaultValuedAttr<Arith_FastMathAttr, "FastMathFlags::none">:$fastmath)>, |
| 73 | + Results<(outs FloatLike:$result)> { |
| 74 | + let assemblyFormat = [{ $operand custom<ArithFastMathAttr>($fastmath) |
| 75 | + attr-dict `:` type($result) }]; |
| 76 | +} |
64 | 77 |
|
65 | 78 | // Base class for floating point binary operations. |
66 | 79 | class Arith_FloatBinaryOp<string mnemonic, list<Trait> traits = []> : |
67 | | - Arith_BinaryOp<mnemonic, traits>, |
68 | | - Arguments<(ins FloatLike:$lhs, FloatLike:$rhs)>, |
69 | | - Results<(outs FloatLike:$result)>; |
| 80 | + Arith_BinaryOp<mnemonic, |
| 81 | + !listconcat([DeclareOpInterfaceMethods<ArithFastMathInterface>], |
| 82 | + traits)>, |
| 83 | + Arguments<(ins FloatLike:$lhs, FloatLike:$rhs, |
| 84 | + DefaultValuedAttr<Arith_FastMathAttr, "FastMathFlags::none">:$fastmath)>, |
| 85 | + Results<(outs FloatLike:$result)> { |
| 86 | + let assemblyFormat = [{ $lhs `,` $rhs `` custom<ArithFastMathAttr>($fastmath) |
| 87 | + attr-dict `:` type($result) }]; |
| 88 | +} |
70 | 89 |
|
71 | 90 | // Base class for arithmetic cast operations. Requires a single operand and |
72 | 91 | // result. If either is a shaped type, then the other must be of the same shape. |
|
0 commit comments