[Mlir-commits] [mlir] 2e8c112 - [mlir] Add elementAttr to TypedArrayAttrBase.

Alex Zinenko llvmlistbot at llvm.org
Thu Feb 13 00:25:52 PST 2020


Author: Abdurrahman Akkas
Date: 2020-02-13T09:25:27+01:00
New Revision: 2e8c112ecf562afdd8a6b3c3467571233b9b55ae

URL: https://github.com/llvm/llvm-project/commit/2e8c112ecf562afdd8a6b3c3467571233b9b55ae
DIFF: https://github.com/llvm/llvm-project/commit/2e8c112ecf562afdd8a6b3c3467571233b9b55ae.diff

LOG: [mlir] Add elementAttr to TypedArrayAttrBase.

In code generators, one can automate the translation of typed ArrayAttrs
if element attribute translators are already implemented. However, the
type of the element attribute is lost at the construction of
TypedArrayAttrBase. With this change one can inspect the element type
and generate the translation logic automatically, which will reduce the
code repetition.

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpBase.td
    mlir/test/mlir-tblgen/op-attribute.td

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 1ee7a25811c0..e4165914cde5 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1130,6 +1130,8 @@ class TypedArrayAttrBase<Attr element, string description>: ArrayAttrBase<
                           "; })">]>,
     description> {
   let constBuilderCall = "$_builder.getArrayAttr($0)";
+
+  Attr elementAttr = element;
 }
 
 def I32ArrayAttr : TypedArrayAttrBase<I32Attr,

diff  --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index 61c887b2d59c..e400bf395f41 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -1,5 +1,6 @@
 // RUN: mlir-tblgen -gen-op-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL --dump-input-on-failure
 // RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF --dump-input-on-failure
+// RUN: mlir-tblgen -print-records -I %S/../../include %s | FileCheck %s --check-prefix=RECORD --dump-input-on-failure
 
 include "mlir/IR/OpBase.td"
 
@@ -239,3 +240,12 @@ def UnitAttrOp : NS_Op<"unit_attr_op", []> {
 // DEF:   return {{.*}} != nullptr
 
 // DEF: build(Builder *odsBuilder, OperationState &odsState, /*optional*/UnitAttr attr)
+
+
+// Test elementAttr field of TypedArrayAttr.
+// ---
+
+def SomeTypedArrayAttr : TypedArrayAttrBase<SomeAttr, "SomeAttr array">;
+
+// RECORD-LABEL: def SomeTypedArrayAttr
+// RECORD: Attr elementAttr = SomeAttr;


        


More information about the Mlir-commits mailing list