[Mlir-commits] [mlir] 41eb2ce - [MLIR] Mark additional builtin attr methods const
Fabian Schuiki
llvmlistbot at llvm.org
Tue Jun 8 05:45:27 PDT 2021
Author: Fabian Schuiki
Date: 2021-06-08T14:45:19+02:00
New Revision: 41eb2cec47986d8128c0ef03164a007b0db67127
URL: https://github.com/llvm/llvm-project/commit/41eb2cec47986d8128c0ef03164a007b0db67127
DIFF: https://github.com/llvm/llvm-project/commit/41eb2cec47986d8128c0ef03164a007b0db67127.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/IR/BuiltinAttributes.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td
index 5d6646bbb370..3d1d77cd89e9 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 <typename AttrTy>
- iterator_range<attr_value_iterator<AttrTy>> getAsRange() {
+ iterator_range<attr_value_iterator<AttrTy>> getAsRange() const {
return llvm::make_range(attr_value_iterator<AttrTy>(begin()),
attr_value_iterator<AttrTy>(end()));
}
template <typename AttrTy,
typename UnderlyingTy = typename AttrTy::ValueType>
- auto getAsValueRange() {
+ auto getAsValueRange() const {
return llvm::map_range(getAsRange<AttrTy>(), [](AttrTy attr) {
return static_cast<UnderlyingTy>(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<typename AttrClass>
- AttrClass getAs(StringRef name) {
- return get(name).dyn_cast_or_null<AttrClass>();
+ template<typename AttrClass, typename NameClass>
+ AttrClass getAs(NameClass name) const {
+ return get(name).template dyn_cast_or_null<AttrClass>();
}
private:
More information about the Mlir-commits
mailing list