[Mlir-commits] [mlir] [mlir][IR] Add `Builder::getArrayAttr` overload for concrete attributes (PR #170870)

Mehdi Amini llvmlistbot at llvm.org
Fri Dec 5 08:24:12 PST 2025


================
@@ -112,6 +112,15 @@ class Builder {
   StringAttr getStringAttr(const Twine &bytes);
   ArrayAttr getArrayAttr(ArrayRef<Attribute> value);
 
+  // Convenience method for containers of specific attribute types. E.g., this
+  // overload will match SmallVector<IntegerAttr>.
+  template <typename ContainerTy>
+  ArrayAttr getArrayAttr(const ContainerTy &value) {
+    auto ref = ArrayRef(value);
+    return getArrayAttr(ArrayRef<Attribute>(
+        static_cast<const Attribute *>(ref.data()), ref.size()));
----------------
joker-eph wrote:

The math work if you think of it in terms of assembly, but C++ rules are more abstracts.
For example you can't take unrelated structures and do the same kind of things (or accessing similar fields) even if they have the same memory layout in practice.

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


More information about the Mlir-commits mailing list