diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td --- a/mlir/include/mlir/IR/BuiltinAttributes.td +++ b/mlir/include/mlir/IR/BuiltinAttributes.td @@ -1064,6 +1064,9 @@ /// Return the number of bytes in this string. size_t size() const { return getValue().size(); } + /// Return whether the string is empty. + bool empty() const { return getValue().empty(); } + /// Iterate over the underlying string data. StringRef::iterator begin() const { return getValue().begin(); } StringRef::iterator end() const { return getValue().end(); } diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -149,7 +149,7 @@ // Value must not be empty StringAttr strAttr = llvm::dyn_cast(getValueAttr()); - if (strAttr && strAttr.getValue().empty()) + if (strAttr && strAttr.empty()) return emitOpError() << "value must not be empty"; auto value = cast(getValueAttr()); @@ -160,9 +160,7 @@ return success(); } -OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { - return getValue(); -} +OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { return getValue(); } //===----------------------------------------------------------------------===// // IncludeOp diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -84,7 +84,7 @@ } llvm::MDString *DebugTranslation::getMDStringOrNull(StringAttr stringAttr) { - if (!stringAttr || stringAttr.getValue().empty()) + if (!stringAttr || stringAttr.empty()) return nullptr; return llvm::MDString::get(llvmCtx, stringAttr); } diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -859,7 +859,7 @@ ArrayAttr value = getNames(); for (size_t i = 0, e = value.size(); i != e; ++i) if (auto str = dyn_cast(value[i])) - if (!str.getValue().empty()) + if (!str.empty()) setNameFn(getResult(i), str.getValue()); } diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp --- a/mlir/unittests/IR/AttributeTest.cpp +++ b/mlir/unittests/IR/AttributeTest.cpp @@ -432,7 +432,7 @@ auto zeroStringValue = cast(sparseString.getValues()[{1, 1}]); - EXPECT_TRUE(zeroStringValue.getValue().empty()); + EXPECT_TRUE(zeroStringValue.empty()); EXPECT_TRUE(zeroStringValue.getType() == stringTy); }