[Mlir-commits] [mlir] [mlir][arith] Add overflow flags support to arith ops (PR #77211)

Tobias Gysi llvmlistbot at llvm.org
Sun Jan 7 23:23:28 PST 2024


================
@@ -49,6 +57,33 @@ class AttrConvertFastMathToLLVM {
 
   ArrayRef<NamedAttribute> getAttrs() const { return convertedAttr.getAttrs(); }
 
+private:
+  NamedAttrList convertedAttr;
+};
+
+// Attribute converter that populates a NamedAttrList by removing the overflow
+// attribute from the source operation attributes, and replacing it with an
+// equivalent LLVM fastmath attribute.
+template <typename SourceOp, typename TargetOp>
+class AttrConvertOverflowToLLVM {
+public:
+  AttrConvertOverflowToLLVM(SourceOp srcOp) {
+    // Copy the source attributes.
+    convertedAttr = NamedAttrList{srcOp->getAttrs()};
+    // Get the name of the arith fastmath attribute.
+    llvm::StringRef arithAttrName = SourceOp::getIntegerOverflowAttrName();
+    // Remove the source fastmath attribute.
+    auto arithAttr = dyn_cast_or_null<arith::IntegerOverflowFlagsAttr>(
----------------
gysit wrote:

```suggestion
    auto arithAttr = dyn_cast_if_present<arith::IntegerOverflowFlagsAttr>(
```
ultra nit: AFAIK dyn_cast_or_null is deprecated.

https://github.com/llvm/llvm-project/pull/77211


More information about the Mlir-commits mailing list