xref: /llvm-project/mlir/include/mlir/Dialect/Arith/IR/ArithOpsInterfaces.td (revision 8827ff92b96d78ef455157574061d745df2909af)
1//===-- ArithOpsInterfaces.td - arith op interfaces ---*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the Arith interfaces definition file.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef ARITH_OPS_INTERFACES
14#define ARITH_OPS_INTERFACES
15
16include "mlir/IR/OpBase.td"
17
18def ArithFastMathInterface : OpInterface<"ArithFastMathInterface"> {
19  let description = [{
20    Access to operation fastmath flags.
21  }];
22
23  let cppNamespace = "::mlir::arith";
24
25  let methods = [
26    InterfaceMethod<
27      /*desc=*/        "Returns a FastMathFlagsAttr attribute for the operation",
28      /*returnType=*/  "FastMathFlagsAttr",
29      /*methodName=*/  "getFastMathFlagsAttr",
30      /*args=*/        (ins),
31      /*methodBody=*/  [{}],
32      /*defaultImpl=*/ [{
33        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
34        return op.getFastmathAttr();
35      }]
36      >,
37    StaticInterfaceMethod<
38      /*desc=*/        [{Returns the name of the FastMathFlagsAttr attribute
39                         for the operation}],
40      /*returnType=*/  "StringRef",
41      /*methodName=*/  "getFastMathAttrName",
42      /*args=*/        (ins),
43      /*methodBody=*/  [{}],
44      /*defaultImpl=*/ [{
45        return "fastmath";
46      }]
47      >
48
49  ];
50}
51
52def ArithIntegerOverflowFlagsInterface : OpInterface<"ArithIntegerOverflowFlagsInterface"> {
53  let description = [{
54    Access to op integer overflow flags.
55  }];
56
57  let cppNamespace = "::mlir::arith";
58
59  let methods = [
60    InterfaceMethod<
61      /*desc=*/        "Returns an IntegerOverflowFlagsAttr attribute for the operation",
62      /*returnType=*/  "IntegerOverflowFlagsAttr",
63      /*methodName=*/  "getOverflowAttr",
64      /*args=*/        (ins),
65      /*methodBody=*/  [{}],
66      /*defaultImpl=*/ [{
67        auto op = cast<ConcreteOp>(this->getOperation());
68        return op.getOverflowFlagsAttr();
69      }]
70      >,
71    InterfaceMethod<
72      /*desc=*/        "Returns whether the operation has the No Unsigned Wrap keyword",
73      /*returnType=*/  "bool",
74      /*methodName=*/  "hasNoUnsignedWrap",
75      /*args=*/        (ins),
76      /*methodBody=*/  [{}],
77      /*defaultImpl=*/ [{
78        auto op = cast<ConcreteOp>(this->getOperation());
79        IntegerOverflowFlags flags = op.getOverflowFlagsAttr().getValue();
80        return bitEnumContainsAll(flags, IntegerOverflowFlags::nuw);
81      }]
82      >,
83    InterfaceMethod<
84      /*desc=*/        "Returns whether the operation has the No Signed Wrap keyword",
85      /*returnType=*/  "bool",
86      /*methodName=*/  "hasNoSignedWrap",
87      /*args=*/        (ins),
88      /*methodBody=*/  [{}],
89      /*defaultImpl=*/ [{
90        auto op = cast<ConcreteOp>(this->getOperation());
91        IntegerOverflowFlags flags = op.getOverflowFlagsAttr().getValue();
92        return bitEnumContainsAll(flags, IntegerOverflowFlags::nsw);
93      }]
94      >,
95    StaticInterfaceMethod<
96      /*desc=*/        [{Returns the name of the IntegerOverflowFlagsAttr attribute
97                         for the operation}],
98      /*returnType=*/  "StringRef",
99      /*methodName=*/  "getIntegerOverflowAttrName",
100      /*args=*/        (ins),
101      /*methodBody=*/  [{}],
102      /*defaultImpl=*/ [{
103        return "overflowFlags";
104      }]
105      >
106  ];
107}
108
109def ArithRoundingModeInterface : OpInterface<"ArithRoundingModeInterface"> {
110  let description = [{
111    Access to op rounding mode.
112  }];
113
114  let cppNamespace = "::mlir::arith";
115
116  let methods = [
117    InterfaceMethod<
118      /*desc=*/        "Returns a RoundingModeAttr attribute for the operation",
119      /*returnType=*/  "RoundingModeAttr",
120      /*methodName=*/  "getRoundingModeAttr",
121      /*args=*/        (ins),
122      /*methodBody=*/  [{}],
123      /*defaultImpl=*/ [{
124        auto op = cast<ConcreteOp>(this->getOperation());
125        return op.getRoundingmodeAttr();
126      }]
127    >,
128    StaticInterfaceMethod<
129      /*desc=*/        [{Returns the name of the RoundingModeAttr attribute for
130                         the operation}],
131      /*returnType=*/  "StringRef",
132      /*methodName=*/  "getRoundingModeAttrName",
133      /*args=*/        (ins),
134      /*methodBody=*/  [{}],
135      /*defaultImpl=*/ [{
136        return "roundingmode";
137      }]
138    >
139  ];
140}
141
142#endif // ARITH_OPS_INTERFACES
143