Index: mlir/docs/DeclarativeRewrites.md =================================================================== --- mlir/docs/DeclarativeRewrites.md +++ mlir/docs/DeclarativeRewrites.md @@ -400,7 +400,7 @@ example and decompose the array attribute into two attributes: ```tablegen -class getNthAttr : NativeCodeCall<"$_self.getValue()[" # n # "]">; +class getNthAttr : NativeCodeCall<"$_self[" # n # "]">; def : Pat<(OneAttrOp $attr), (TwoAttrOp (getNthAttr<0>:$attr), (getNthAttr<1>:$attr)>; Index: mlir/docs/Tutorials/Toy/Ch-7.md =================================================================== --- mlir/docs/Tutorials/Toy/Ch-7.md +++ mlir/docs/Tutorials/Toy/Ch-7.md @@ -495,7 +495,7 @@ return nullptr; size_t elementIndex = index().getZExtValue(); - return structAttr.getValue()[elementIndex]; + return structAttr[elementIndex]; } ``` Index: mlir/examples/toy/Ch7/mlir/ToyCombine.cpp =================================================================== --- mlir/examples/toy/Ch7/mlir/ToyCombine.cpp +++ mlir/examples/toy/Ch7/mlir/ToyCombine.cpp @@ -43,7 +43,7 @@ return nullptr; size_t elementIndex = index().getZExtValue(); - return structAttr.getValue()[elementIndex]; + return structAttr[elementIndex]; } /// This is an example of a c++ rewrite pattern for the TransposeOp. It Index: mlir/include/mlir/IR/Attributes.h =================================================================== --- mlir/include/mlir/IR/Attributes.h +++ mlir/include/mlir/IR/Attributes.h @@ -204,6 +204,7 @@ static ArrayAttr get(ArrayRef value, MLIRContext *context); ArrayRef getValue() const; + Attribute operator[](unsigned idx) const; /// Support range iteration. using iterator = llvm::ArrayRef::iterator; Index: mlir/include/mlir/IR/OpBase.td =================================================================== --- mlir/include/mlir/IR/OpBase.td +++ mlir/include/mlir/IR/OpBase.td @@ -1292,7 +1292,7 @@ class IntArrayNthElemEq : AttrConstraint< And<[ CPred<"$_self.cast().size() > " # index>, - CPred<"$_self.cast().getValue()[" # index # "]" + CPred<"$_self.cast()[" # index # "]" ".cast().getInt() == " # value> ]>, "whose " # index # "-th element must be " # value>; @@ -1300,7 +1300,7 @@ class IntArrayNthElemMinValue : AttrConstraint< And<[ CPred<"$_self.cast().size() > " # index>, - CPred<"$_self.cast().getValue()[" # index # "]" + CPred<"$_self.cast()[" # index # "]" ".cast().getInt() >= " # min> ]>, "whose " # index # "-th element must be at least " # min>; Index: mlir/lib/Dialect/VectorOps/VectorOps.cpp =================================================================== --- mlir/lib/Dialect/VectorOps/VectorOps.cpp +++ mlir/lib/Dialect/VectorOps/VectorOps.cpp @@ -1143,7 +1143,7 @@ shape.reserve(vectorType.getRank()); unsigned idx = 0; for (unsigned e = offsets.size(); idx < e; ++idx) - shape.push_back(sizes.getValue()[idx].cast().getInt()); + shape.push_back(sizes[idx].cast().getInt()); for (unsigned e = vectorType.getShape().size(); idx < e; ++idx) shape.push_back(vectorType.getShape()[idx]); Index: mlir/lib/IR/Attributes.cpp =================================================================== --- mlir/lib/IR/Attributes.cpp +++ mlir/lib/IR/Attributes.cpp @@ -68,6 +68,11 @@ ArrayRef ArrayAttr::getValue() const { return getImpl()->value; } +Attribute ArrayAttr::operator[](unsigned idx) const { + assert(idx < size() && "index out of bounds"); + return getValue()[idx]; +} + //===----------------------------------------------------------------------===// // BoolAttr //===----------------------------------------------------------------------===// Index: mlir/test/lib/TestDialect/TestDialect.cpp =================================================================== --- mlir/test/lib/TestDialect/TestDialect.cpp +++ mlir/test/lib/TestDialect/TestDialect.cpp @@ -42,7 +42,7 @@ auto args = block->getArguments(); auto e = std::min(arrayAttr.size(), args.size()); for (unsigned i = 0; i < e; ++i) { - if (auto strAttr = arrayAttr.getValue()[i].dyn_cast()) + if (auto strAttr = arrayAttr[i].dyn_cast()) setNameFn(args[i], strAttr.getValue()); } } Index: mlir/test/lib/TestDialect/TestOps.td =================================================================== --- mlir/test/lib/TestDialect/TestOps.td +++ mlir/test/lib/TestDialect/TestOps.td @@ -609,12 +609,11 @@ let results = (outs I32); } def Constraint0 : AttrConstraint< - CPred<"$_self.cast().getValue()[0]." + CPred<"$_self.cast()[0]." "cast().getInt() == 0">, "[0] == 0">; def Constraint1 : AttrConstraint< - CPred<"$_self.cast().getValue()[1]." - "cast().getInt() == 1">, + CPred<"$_self.cast()[1].cast().getInt() == 1">, "[1] == 1">; def : Pat<(OpAllAttrConstraint1 AllAttrConstraintsOf<[Constraint0, Constraint1]>:$attr), Index: mlir/test/mlir-tblgen/predicate.td =================================================================== --- mlir/test/mlir-tblgen/predicate.td +++ mlir/test/mlir-tblgen/predicate.td @@ -56,7 +56,7 @@ } // CHECK-LABEL: OpH::verify() -// CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast().getValue()[0].cast().getInt() == 8))))) +// CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast()[0].cast().getInt() == 8))))) // CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be 8"); def OpI: NS_Op<"op_for_arr_min_value_at_index", []> { @@ -64,7 +64,7 @@ } // CHECK-LABEL: OpI::verify() -// CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast().getValue()[0].cast().getInt() >= 8))))) +// CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast()[0].cast().getInt() >= 8))))) // CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 8"); def OpJ: NS_Op<"op_for_TCopVTEtAreSameAt", [