From 41eb2cec47986d8128c0ef03164a007b0db67127 Mon Sep 17 00:00:00 2001 From: Fabian Schuiki Date: Mon, 7 Jun 2021 17:33:23 +0200 Subject: [PATCH] [MLIR] Mark additional builtin attr methods const * Mark the following methods const: * `ArrayAttr::getAsRange` * `ArrayAttr::getAsValueRange` * `DictionaryAttr::getAs` * Make `DictionarAttr::getAs` generic over the name class, such that `Identifier` and `StringRef` arguments get forwarded to the underlying call to `get`. (Made generic to avoid introducing a dependency on `include/mlir/IR/Identifier.h` as per the diff discussion.) Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D103822 --- mlir/include/mlir/IR/BuiltinAttributes.td | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td index 5d6646b..3d1d77c 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.td +++ b/mlir/include/mlir/IR/BuiltinAttributes.td @@ -114,13 +114,13 @@ def Builtin_ArrayAttr : Builtin_Attr<"Array"> { public: template - iterator_range> getAsRange() { + iterator_range> getAsRange() const { return llvm::make_range(attr_value_iterator(begin()), attr_value_iterator(end())); } template - auto getAsValueRange() { + auto getAsValueRange() const { return llvm::map_range(getAsRange(), [](AttrTy attr) { return static_cast(attr.getValue()); }); @@ -345,9 +345,9 @@ def Builtin_DictionaryAttr : Builtin_Attr<"Dictionary"> { /// Return the specified attribute if present and is an instance of /// `AttrClass`, null otherwise. - template - AttrClass getAs(StringRef name) { - return get(name).dyn_cast_or_null(); + template + AttrClass getAs(NameClass name) const { + return get(name).template dyn_cast_or_null(); } private: -- 2.7.4