diff --git a/mlir/docs/DeclarativeRewrites.md b/mlir/docs/DeclarativeRewrites.md --- a/mlir/docs/DeclarativeRewrites.md +++ b/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)>; diff --git a/mlir/docs/Tutorials/Toy/Ch-7.md b/mlir/docs/Tutorials/Toy/Ch-7.md --- a/mlir/docs/Tutorials/Toy/Ch-7.md +++ b/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]; } ``` diff --git a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp --- a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp +++ b/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 diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h --- a/mlir/include/mlir/IR/Attributes.h +++ b/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; diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/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>; diff --git a/mlir/lib/Dialect/VectorOps/VectorOps.cpp b/mlir/lib/Dialect/VectorOps/VectorOps.cpp --- a/mlir/lib/Dialect/VectorOps/VectorOps.cpp +++ b/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]); diff --git a/mlir/lib/IR/Attributes.cpp b/mlir/lib/IR/Attributes.cpp --- a/mlir/lib/IR/Attributes.cpp +++ b/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 //===----------------------------------------------------------------------===// diff --git a/mlir/test/lib/TestDialect/TestDialect.cpp b/mlir/test/lib/TestDialect/TestDialect.cpp --- a/mlir/test/lib/TestDialect/TestDialect.cpp +++ b/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()); } } diff --git a/mlir/test/lib/TestDialect/TestOps.td b/mlir/test/lib/TestDialect/TestOps.td --- a/mlir/test/lib/TestDialect/TestOps.td +++ b/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), diff --git a/mlir/test/mlir-tblgen/predicate.td b/mlir/test/mlir-tblgen/predicate.td --- a/mlir/test/mlir-tblgen/predicate.td +++ b/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", [