Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 39eef64

Browse files
MLIR Teamtensorflower-gardener
authored andcommitted
Add I32ElementsAttr to OpBase
PiperOrigin-RevId: 264969142
1 parent bdf29df commit 39eef64

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

include/mlir/IR/OpBase.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,19 @@ def TypeArrayAttr : TypedArrayAttrBase<TypeAttr, "type array attribute"> {
902902
let constBuilderCall = ?;
903903
}
904904

905+
def I32ElementsAttr : Attr<
906+
CPred<"$_self.isa<DenseIntElementsAttr>() &&"
907+
"$_self.cast<DenseIntElementsAttr>().getType()."
908+
"getElementType().isInteger(32)">,
909+
"32-bit integer elements attribute"> {
910+
let storageType = [{ DenseIntElementsAttr }];
911+
let returnType = [{ DenseIntElementsAttr }];
912+
let constBuilderCall = "$_builder.getDenseElementsAttr("
913+
"$_builder.getTensorType({}, $_builder.getIntegerType(32)), "
914+
"{$_builder.getI32IntegerAttr($0)})";
915+
let convertFromStorage = "$_self";
916+
}
917+
905918
// Attributes containing symbol references.
906919
def SymbolRefAttr : Attr<CPred<"$_self.isa<SymbolRefAttr>()">,
907920
"symbol reference attribute"> {

test/lib/TestDialect/TestOps.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ def SingleBlockImplicitTerminatorOp : TEST_Op<"SingleBlockImplicitTerminator",
238238
let regions = (region SizedRegion<1>:$region);
239239
}
240240

241+
def I32ElementsAttributesOp : TEST_Op<"i32ElementsAttr"> {
242+
let arguments = (ins I32ElementsAttr:$attr);
243+
}
244+
241245
//===----------------------------------------------------------------------===//
242246
// Test Patterns
243247
//===----------------------------------------------------------------------===//

test/mlir-tblgen/types.mlir

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,27 @@ func @does_not_have_static_memref(%arg0: memref<?xi32>) {
205205
// expected-error@+1 {{'test.takes_static_memref' op operand #0 must be statically shaped memref of any type values}}
206206
"test.takes_static_memref"(%arg0) : (memref<?xi32>) -> ()
207207
}
208+
209+
// -----
210+
211+
func @elements_attr_not_i32_f32() {
212+
// expected-error@+1 {{32-bit integer elements attribute}}
213+
"test.i32ElementsAttr"() {attr = dense<[1.0, 20.0]>:tensor<2xf32>} : () -> ()
214+
return
215+
}
216+
217+
// -----
218+
219+
func @elements_attr_not_i32_i64() {
220+
// expected-error@+1 {{32-bit integer elements attribute}}
221+
"test.i32ElementsAttr"() {attr = dense<[1, 20]>:tensor<2xi64>} : () -> ()
222+
return
223+
}
224+
225+
226+
// -----
227+
228+
func @elements_attr_i32(%arg0: tensor<1x2xi32>) {
229+
"test.i32ElementsAttr"() {attr = dense<[1, 2]>:tensor<2xi32>} : () -> ()
230+
return
231+
}

0 commit comments

Comments
 (0)