[Mlir-commits] [mlir] 03092f2 - [mlir] Add BoolArrayAttr in Tablegen + Builder support

Nicolas Vasilache llvmlistbot at llvm.org
Mon May 18 06:46:15 PDT 2020


Author: Nicolas Vasilache
Date: 2020-05-18T09:42:12-04:00
New Revision: 03092f2fa7b4d2609858666f8bba293078582fdd

URL: https://github.com/llvm/llvm-project/commit/03092f2fa7b4d2609858666f8bba293078582fdd
DIFF: https://github.com/llvm/llvm-project/commit/03092f2fa7b4d2609858666f8bba293078582fdd.diff

LOG: [mlir] Add BoolArrayAttr in Tablegen + Builder support

Differential Revision: https://reviews.llvm.org/D80090

Added: 
    

Modified: 
    mlir/include/mlir/IR/Builders.h
    mlir/include/mlir/IR/OpBase.td
    mlir/lib/IR/Builders.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h
index a11da75f3ebf..d4dc8041d3b1 100644
--- a/mlir/include/mlir/IR/Builders.h
+++ b/mlir/include/mlir/IR/Builders.h
@@ -128,6 +128,7 @@ class Builder {
   DenseIntElementsAttr getI64TensorAttr(ArrayRef<int64_t> values);
 
   ArrayAttr getAffineMapArrayAttr(ArrayRef<AffineMap> values);
+  ArrayAttr getBoolArrayAttr(ArrayRef<bool> values);
   ArrayAttr getI32ArrayAttr(ArrayRef<int32_t> values);
   ArrayAttr getI64ArrayAttr(ArrayRef<int64_t> values);
   ArrayAttr getIndexArrayAttr(ArrayRef<int64_t> values);

diff  --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index ca7b5c2607a6..6a7542c7127c 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1346,6 +1346,10 @@ class TypedArrayAttrBase<Attr element, string description>: ArrayAttrBase<
   Attr elementAttr = element;
 }
 
+def BoolArrayAttr : TypedArrayAttrBase<BoolAttr,
+                                      "1-bit boolean array attribute"> {
+  let constBuilderCall = "$_builder.getBoolArrayAttr($0)";
+}
 def I32ArrayAttr : TypedArrayAttrBase<I32Attr,
                                       "32-bit integer array attribute"> {
   let constBuilderCall = "$_builder.getI32ArrayAttr($0)";

diff  --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index fcaf33aa98eb..4cb4a5c2962b 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -202,12 +202,17 @@ Builder::getSymbolRefAttr(StringRef value,
   return SymbolRefAttr::get(value, nestedReferences, getContext());
 }
 
+ArrayAttr Builder::getBoolArrayAttr(ArrayRef<bool> values) {
+  auto attrs = llvm::to_vector<8>(llvm::map_range(
+      values, [this](bool v) -> Attribute { return getBoolAttr(v); }));
+  return getArrayAttr(attrs);
+}
+
 ArrayAttr Builder::getI32ArrayAttr(ArrayRef<int32_t> values) {
   auto attrs = llvm::to_vector<8>(llvm::map_range(
       values, [this](int32_t v) -> Attribute { return getI32IntegerAttr(v); }));
   return getArrayAttr(attrs);
 }
-
 ArrayAttr Builder::getI64ArrayAttr(ArrayRef<int64_t> values) {
   auto attrs = llvm::to_vector<8>(llvm::map_range(
       values, [this](int64_t v) -> Attribute { return getI64IntegerAttr(v); }));


        


More information about the Mlir-commits mailing list