Skip to content

Commit

Permalink
[mlir] Add elementAttr to TypedArrayAttrBase.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Abdurrahman Akkas authored and ftynse committed Feb 13, 2020
1 parent 005b720 commit 2e8c112
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mlir/include/mlir/IR/OpBase.td
Expand Up @@ -1130,6 +1130,8 @@ class TypedArrayAttrBase<Attr element, string description>: ArrayAttrBase<
"; })">]>,
description> {
let constBuilderCall = "$_builder.getArrayAttr($0)";

Attr elementAttr = element;
}

def I32ArrayAttr : TypedArrayAttrBase<I32Attr,
Expand Down
10 changes: 10 additions & 0 deletions 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"

Expand Down Expand Up @@ -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;

0 comments on commit 2e8c112

Please sign in to comment.