Skip to content

Commit

Permalink
Add I32ElementsAttr to OpBase
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 2649691
  • Loading branch information
MLIR Team authored and tensorflower-gardener committed Aug 23, 2019
1 parent d906f84 commit a329d33
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mlir/include/mlir/IR/OpBase.td
Expand Up @@ -902,6 +902,19 @@ def TypeArrayAttr : TypedArrayAttrBase<TypeAttr, "type array attribute"> {
let constBuilderCall = ?;
}

def I32ElementsAttr : Attr<
CPred<"$_self.isa<DenseIntElementsAttr>() &&"
"$_self.cast<DenseIntElementsAttr>().getType()."
"getElementType().isInteger(32)">,
"32-bit integer elements attribute"> {
let storageType = [{ DenseIntElementsAttr }];
let returnType = [{ DenseIntElementsAttr }];
let constBuilderCall = "$_builder.getDenseElementsAttr("
"$_builder.getTensorType({}, $_builder.getIntegerType(32)), "
"{$_builder.getI32IntegerAttr($0)})";
let convertFromStorage = "$_self";
}

// Attributes containing symbol references.
def SymbolRefAttr : Attr<CPred<"$_self.isa<SymbolRefAttr>()">,
"symbol reference attribute"> {
Expand Down
4 changes: 4 additions & 0 deletions mlir/test/lib/TestDialect/TestOps.td
Expand Up @@ -238,6 +238,10 @@ def SingleBlockImplicitTerminatorOp : TEST_Op<"SingleBlockImplicitTerminator",
let regions = (region SizedRegion<1>:$region);
}

def I32ElementsAttributesOp : TEST_Op<"i32ElementsAttr"> {
let arguments = (ins I32ElementsAttr:$attr);
}

//===----------------------------------------------------------------------===//
// Test Patterns
//===----------------------------------------------------------------------===//
Expand Down
24 changes: 24 additions & 0 deletions mlir/test/mlir-tblgen/types.mlir
Expand Up @@ -205,3 +205,27 @@ func @does_not_have_static_memref(%arg0: memref<?xi32>) {
// expected-error@+1 {{'test.takes_static_memref' op operand #0 must be statically shaped memref of any type values}}
"test.takes_static_memref"(%arg0) : (memref<?xi32>) -> ()
}

// -----

func @elements_attr_not_i32_f32() {
// expected-error@+1 {{32-bit integer elements attribute}}
"test.i32ElementsAttr"() {attr = dense<[1.0, 20.0]>:tensor<2xf32>} : () -> ()
return
}

// -----

func @elements_attr_not_i32_i64() {
// expected-error@+1 {{32-bit integer elements attribute}}
"test.i32ElementsAttr"() {attr = dense<[1, 20]>:tensor<2xi64>} : () -> ()
return
}


// -----

func @elements_attr_i32(%arg0: tensor<1x2xi32>) {
"test.i32ElementsAttr"() {attr = dense<[1, 2]>:tensor<2xi32>} : () -> ()
return
}

0 comments on commit a329d33

Please sign in to comment.