From 88d319a29ff5d3be1bb9a7e88ef6e17df1dfe607 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 13 Dec 2023 22:58:30 -0800 Subject: [PATCH] [mlir] Use StringRef::{starts,ends}_with (NFC) This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with. --- mlir/lib/AsmParser/AttributeParser.cpp | 2 +- mlir/lib/AsmParser/Parser.cpp | 2 +- mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 2 +- mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp | 2 +- mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp | 6 +++--- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 2 +- mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp | 2 +- mlir/lib/IR/Operation.cpp | 2 +- mlir/lib/Query/Matcher/Parser.cpp | 2 +- mlir/lib/Support/ToolUtilities.cpp | 2 +- mlir/lib/TableGen/Class.cpp | 3 ++- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 2 +- mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp | 2 +- mlir/lib/Tools/PDLL/Parser/Parser.cpp | 4 ++-- mlir/lib/Tools/lsp-server-support/Protocol.cpp | 4 ++-- mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp | 2 +- mlir/lib/Tools/lsp-server-support/Transport.cpp | 2 +- mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp | 3 ++- mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp | 4 ++-- mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp | 2 +- mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp | 2 +- .../mlir-parser-fuzzer/bytecode/mlir-bytecode-parser-fuzzer.cpp | 2 +- mlir/tools/mlir-parser-fuzzer/text/mlir-text-parser-fuzzer.cpp | 2 +- mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp | 4 ++-- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 2 +- mlir/tools/mlir-tblgen/OpDocGen.cpp | 4 ++-- mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp | 2 +- 27 files changed, 36 insertions(+), 34 deletions(-) diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp index d085fb6af6bc..efa65e49abc3 100644 --- a/mlir/lib/AsmParser/AttributeParser.cpp +++ b/mlir/lib/AsmParser/AttributeParser.cpp @@ -660,7 +660,7 @@ TensorLiteralParser::getFloatAttrElements(SMLoc loc, FloatType eltTy, const Token &token = signAndToken.second; // Handle hexadecimal float literals. - if (token.is(Token::integer) && token.getSpelling().startswith("0x")) { + if (token.is(Token::integer) && token.getSpelling().starts_with("0x")) { std::optional result; if (failed(p.parseFloatFromIntegerLiteral(result, token, isNegative, eltTy.getFloatSemantics(), diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp index 1fca85beb87f..3aa9adcbe1c5 100644 --- a/mlir/lib/AsmParser/Parser.cpp +++ b/mlir/lib/AsmParser/Parser.cpp @@ -2477,7 +2477,7 @@ public: AsmResourceEntryKind getKind() const final { if (value.isAny(Token::kw_true, Token::kw_false)) return AsmResourceEntryKind::Bool; - return value.getSpelling().startswith("\"0x") + return value.getSpelling().starts_with("\"0x") ? AsmResourceEntryKind::Blob : AsmResourceEntryKind::String; } diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index 0bc2a2f676ba..7cf3bd83b925 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -2564,7 +2564,7 @@ BytecodeReader::finalize(function_ref shouldMaterialize) { } bool mlir::isBytecode(llvm::MemoryBufferRef buffer) { - return buffer.getBuffer().startswith("ML\xefR"); + return buffer.getBuffer().starts_with("ML\xefR"); } /// Read the bytecode from the provided memory buffer reference. diff --git a/mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp b/mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp index 4f075c71c947..2540e1fb86d8 100644 --- a/mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp +++ b/mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp @@ -14,7 +14,7 @@ using namespace mlir; using namespace mlir::amdgpu; FailureOr Chipset::parse(StringRef name) { - if (!name.startswith("gfx")) + if (!name.starts_with("gfx")) return failure(); unsigned major = 0; unsigned minor = 0; diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp index f0c294c22695..5cce7befce52 100644 --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp @@ -201,9 +201,9 @@ SerializeToHsacoPass::translateToLLVMIR(llvm::LLVMContext &llvmContext) { StringRef funcName = f.getName(); if ("printf" == funcName) needOpenCl = true; - if (funcName.startswith("__ockl_")) + if (funcName.starts_with("__ockl_")) needOckl = true; - if (funcName.startswith("__ocml_")) + if (funcName.starts_with("__ocml_")) needOcml = true; } } @@ -253,7 +253,7 @@ SerializeToHsacoPass::translateToLLVMIR(llvm::LLVMContext &llvmContext) { if (needOcml || needOckl) { addControlConstant("__oclc_wavefrontsize64", 1, 8); StringRef chipSet = this->chip.getValue(); - if (chipSet.startswith("gfx")) + if (chipSet.starts_with("gfx")) chipSet = chipSet.substr(3); uint32_t minor = llvm::APInt(32, chipSet.substr(chipSet.size() - 2), 16).getZExtValue(); diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 53e1088f620d..458bf83eac17 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2916,7 +2916,7 @@ OpFoldResult LLVM::OrOp::fold(FoldAdaptor adaptor) { //===----------------------------------------------------------------------===// LogicalResult CallIntrinsicOp::verify() { - if (!getIntrin().startswith("llvm.")) + if (!getIntrin().starts_with("llvm.")) return emitOpError() << "intrinsic name must start with 'llvm.'"; return success(); } diff --git a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp index c92472acf279..3fa26bce1509 100644 --- a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp +++ b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp @@ -69,7 +69,7 @@ LogicalResult transform::detail::expandPathsToMLIRFiles( continue; } - if (!StringRef(fileName).endswith(".mlir")) { + if (!StringRef(fileName).ends_with(".mlir")) { LLVM_DEBUG(DBGS() << " Skipping '" << fileName << "' because it does not end with '.mlir'\n"); continue; diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 7507e0cd0c99..87be08712ea3 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -751,7 +751,7 @@ void OpState::print(Operation *op, OpAsmPrinter &p, StringRef defaultDialect) { void OpState::printOpName(Operation *op, OpAsmPrinter &p, StringRef defaultDialect) { StringRef name = op->getName().getStringRef(); - if (name.startswith((defaultDialect + ".").str()) && name.count('.') == 1) + if (name.starts_with((defaultDialect + ".").str()) && name.count('.') == 1) name = name.drop_front(defaultDialect.size() + 1); p.getStream() << name; } diff --git a/mlir/lib/Query/Matcher/Parser.cpp b/mlir/lib/Query/Matcher/Parser.cpp index be9e60de221d..6585b5d740f6 100644 --- a/mlir/lib/Query/Matcher/Parser.cpp +++ b/mlir/lib/Query/Matcher/Parser.cpp @@ -384,7 +384,7 @@ bool Parser::parseMatcherExpressionImpl(const TokenInfo &nameToken, // completions minus the prefix. void Parser::addCompletion(const TokenInfo &compToken, const MatcherCompletion &completion) { - if (llvm::StringRef(completion.typedText).startswith(compToken.text)) { + if (llvm::StringRef(completion.typedText).starts_with(compToken.text)) { completions.emplace_back(completion.typedText.substr(compToken.text.size()), completion.matcherDecl); } diff --git a/mlir/lib/Support/ToolUtilities.cpp b/mlir/lib/Support/ToolUtilities.cpp index 0f9c4a933d00..ee0214f3d8ac 100644 --- a/mlir/lib/Support/ToolUtilities.cpp +++ b/mlir/lib/Support/ToolUtilities.cpp @@ -58,7 +58,7 @@ mlir::splitAndProcessBuffer(std::unique_ptr originalBuffer, } // Check that suffix is as expected and doesn't have any dash post. - bool expectedSuffix = buffer.startswith(splitMarker.take_back(checkLen)) && + bool expectedSuffix = buffer.starts_with(splitMarker.take_back(checkLen)) && buffer.size() > checkLen && buffer[checkLen] != '0'; if (expectedSuffix) { sourceBuffers.push_back(prev); diff --git a/mlir/lib/TableGen/Class.cpp b/mlir/lib/TableGen/Class.cpp index 360382305685..f71d7e07ed49 100644 --- a/mlir/lib/TableGen/Class.cpp +++ b/mlir/lib/TableGen/Class.cpp @@ -18,7 +18,8 @@ using namespace mlir::tblgen; /// Returns space to be emitted after the given C++ `type`. return "" if the /// ends with '&' or '*', or is empty, else returns " ". static StringRef getSpaceAfterType(StringRef type) { - return (type.empty() || type.endswith("&") || type.endswith("*")) ? "" : " "; + return (type.empty() || type.ends_with("&") || type.ends_with("*")) ? "" + : " "; } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 3dd082aae193..9f0e1f3c3bb6 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -161,7 +161,7 @@ translateDataLayout(DataLayoutSpecInterface attribute, } layoutStream.flush(); StringRef layoutSpec(llvmDataLayout); - if (layoutSpec.startswith("-")) + if (layoutSpec.starts_with("-")) layoutSpec = layoutSpec.drop_front(); return llvm::DataLayout(layoutSpec); diff --git a/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp b/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp index 7510e1e2eb9b..954aaa98c329 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp @@ -354,7 +354,7 @@ Deserializer::processOp(ArrayRef words) { // The deserializer uses "spirv_fn_" as the function name if the input // SPIR-V blob does not contain a name for it. We should use a more clear // indication for such case rather than relying on naming details. - if (!parsedFunc.getName().startswith("spirv_fn_")) + if (!parsedFunc.getName().starts_with("spirv_fn_")) return emitError(unknownLoc, "function name mismatch between OpEntryPoint " "and OpFunction with ") diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 93eb5e892e22..cfbc4e4536fe 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -792,7 +792,7 @@ LogicalResult Parser::parseInclude(SmallVectorImpl &decls) { // Check the type of include. If ending with `.pdll`, this is another pdl file // to be parsed along with the current module. - if (filename.endswith(".pdll")) { + if (filename.ends_with(".pdll")) { if (failed(lexer.pushInclude(filename, fileLoc))) return emitError(fileLoc, "unable to open include file `" + filename + "`"); @@ -807,7 +807,7 @@ LogicalResult Parser::parseInclude(SmallVectorImpl &decls) { } // Otherwise, this must be a `.td` include. - if (filename.endswith(".td")) + if (filename.ends_with(".td")) return parseTdInclude(filename, fileLoc, decls); return emitError(fileLoc, diff --git a/mlir/lib/Tools/lsp-server-support/Protocol.cpp b/mlir/lib/Tools/lsp-server-support/Protocol.cpp index 6d8cec6a54d1..e110fdd97a38 100644 --- a/mlir/lib/Tools/lsp-server-support/Protocol.cpp +++ b/mlir/lib/Tools/lsp-server-support/Protocol.cpp @@ -157,7 +157,7 @@ static llvm::Expected uriFromAbsolutePath(StringRef absolutePath, // If authority if empty, we only print body if it starts with "/"; otherwise, // the URI is invalid. - if (!authority.empty() || StringRef(body).startswith("/")) { + if (!authority.empty() || StringRef(body).starts_with("/")) { uri.append("//"); percentEncode(authority, uri); } @@ -167,7 +167,7 @@ static llvm::Expected uriFromAbsolutePath(StringRef absolutePath, static llvm::Expected getAbsolutePath(StringRef authority, StringRef body) { - if (!body.startswith("/")) + if (!body.starts_with("/")) return llvm::createStringError( llvm::inconvertibleErrorCode(), "File scheme: expect body to be an absolute path starting " diff --git a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp index b6f4f3cc1869..f8d348aba5a3 100644 --- a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp +++ b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp @@ -99,7 +99,7 @@ lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, SMLoc loc) { SmallVector commentLines; while (std::optional line = popLastLine()) { // Check for a comment at the beginning of the line. - if (!line->startswith("//")) + if (!line->starts_with("//")) break; // Extract the document string from the comment. diff --git a/mlir/lib/Tools/lsp-server-support/Transport.cpp b/mlir/lib/Tools/lsp-server-support/Transport.cpp index 3915146f6a66..df675cf78210 100644 --- a/mlir/lib/Tools/lsp-server-support/Transport.cpp +++ b/mlir/lib/Tools/lsp-server-support/Transport.cpp @@ -345,7 +345,7 @@ LogicalResult JSONTransport::readDelimitedMessage(std::string &json) { llvm::SmallString<128> line; while (succeeded(readLine(in, line))) { StringRef lineRef = line.str().trim(); - if (lineRef.startswith("//")) { + if (lineRef.starts_with("//")) { // Found a delimiter for the message. if (lineRef == "// -----") break; diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp index d272164b1d26..0f23366f6fe8 100644 --- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp @@ -253,7 +253,8 @@ void LSPServer::onCodeAction(const CodeActionParams ¶ms, if (only.empty()) return true; return llvm::any_of(only, [&](StringRef base) { - return kind.consume_front(base) && (kind.empty() || kind.startswith(".")); + return kind.consume_front(base) && + (kind.empty() || kind.starts_with(".")); }); }; diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp index 9850c9725607..de657a3df9ef 100644 --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp @@ -181,7 +181,7 @@ static unsigned getBlockNumber(Block *block) { static void printDefBlockName(raw_ostream &os, Block *block, SMRange loc = {}) { // Try to extract a name from the source location. std::optional text = getTextFromRange(loc); - if (text && text->startswith("^")) { + if (text && text->starts_with("^")) { os << *text; return; } @@ -900,7 +900,7 @@ void MLIRDocument::getCodeActionForDiagnostic( // Ignore diagnostics that print the current operation. These are always // enabled for the language server, but not generally during normal // parsing/verification. - if (message.startswith("see current operation: ")) + if (message.starts_with("see current operation: ")) return; // Get the start of the line containing the diagnostic. diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp index 8efc61476731..a5c6c2bb2c6a 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp @@ -946,7 +946,7 @@ public: break; case llvm::sys::fs::file_type::regular_file: { // Only consider concrete files that can actually be included by PDLL. - if (filename.endswith(".pdll") || filename.endswith(".td")) + if (filename.ends_with(".pdll") || filename.ends_with(".td")) addIncludeCompletion(filename, /*isDirectory=*/false); break; } diff --git a/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp b/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp index 8f0c13af9de5..a6678995fc6f 100644 --- a/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp +++ b/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp @@ -48,7 +48,7 @@ struct TestEmulateWideIntPass } func::FuncOp op = getOperation(); - if (!op.getSymName().startswith(testFunctionPrefix)) + if (!op.getSymName().starts_with(testFunctionPrefix)) return; MLIRContext *ctx = op.getContext(); diff --git a/mlir/tools/mlir-parser-fuzzer/bytecode/mlir-bytecode-parser-fuzzer.cpp b/mlir/tools/mlir-parser-fuzzer/bytecode/mlir-bytecode-parser-fuzzer.cpp index 21411b684c15..bb06c64d7215 100644 --- a/mlir/tools/mlir-parser-fuzzer/bytecode/mlir-bytecode-parser-fuzzer.cpp +++ b/mlir/tools/mlir-parser-fuzzer/bytecode/mlir-bytecode-parser-fuzzer.cpp @@ -26,7 +26,7 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerTestOneInput(const uint8_t *data, return -1; llvm::StringRef str(reinterpret_cast(data), size - 1); // Skip if not bytecode. - if (!str.startswith("ML\xefR")) + if (!str.starts_with("ML\xefR")) return -1; // Create a null-terminated memory buffer from the input. diff --git a/mlir/tools/mlir-parser-fuzzer/text/mlir-text-parser-fuzzer.cpp b/mlir/tools/mlir-parser-fuzzer/text/mlir-text-parser-fuzzer.cpp index 5555c039eae9..faa578bc1fde 100644 --- a/mlir/tools/mlir-parser-fuzzer/text/mlir-text-parser-fuzzer.cpp +++ b/mlir/tools/mlir-parser-fuzzer/text/mlir-text-parser-fuzzer.cpp @@ -26,7 +26,7 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerTestOneInput(const uint8_t *data, return -1; llvm::StringRef str(reinterpret_cast(data), size - 1); // Skip if bytecode. - if (str.startswith("ML\xefR")) + if (str.starts_with("ML\xefR")) return -1; // Create a null-terminated memory buffer from the input. diff --git a/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp b/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp index f627d2dd3ea0..00665f93c8a5 100644 --- a/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp +++ b/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp @@ -98,7 +98,7 @@ public: return name.str(); name = record.getName(); - assert(name.startswith("int_") && + assert(name.starts_with("int_") && "LLVM intrinsic names are expected to start with 'int_'"); name = name.drop_front(4); llvm::SmallVector chunks; @@ -121,7 +121,7 @@ public: /// Get the name of the record without the "intrinsic" prefix. llvm::StringRef getProperRecordName() const { llvm::StringRef name = record.getName(); - assert(name.startswith("int_") && + assert(name.starts_with("int_") && "LLVM intrinsic names are expected to start with 'int_'"); return name.drop_front(4); } diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 57392434285f..cd37c8dcd3d5 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1960,7 +1960,7 @@ static std::string generateTypeForGetter(const NamedTypeConstraint &value) { /// Adaptor will have values that are not from the type of their operation and /// this is expected, so we dont generate TypedValue for Adaptor if (value.constraint.getCPPClassName() != "::mlir::Type" && - StringRef(value.constraint.getCPPClassName()).startswith("::")) + StringRef(value.constraint.getCPPClassName()).starts_with("::")) str = llvm::formatv("::mlir::TypedValue<{0}>", value.constraint.getCPPClassName()) .str(); diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp index b5b26a70859e..877ef1089dce 100644 --- a/mlir/tools/mlir-tblgen/OpDocGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp @@ -79,7 +79,7 @@ void mlir::tblgen::emitDescriptionComment(StringRef description, raw_indented_ostream ros(os); StringRef trimmed = description.rtrim(" \t"); ros.printReindented(trimmed, (Twine(prefix) + "/// ").str()); - if (!trimmed.endswith("\n")) + if (!trimmed.ends_with("\n")) ros << "\n"; } @@ -137,7 +137,7 @@ static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) { StringRef traitName = trait.getDef().getValueAsString("trait"); traitName.consume_back("::Trait"); traitName.consume_back("::Impl"); - if (ref.startswith("anonymous_")) + if (ref.starts_with("anonymous_")) name = traitName.str(); if (isa(&trait)) { if (trait.getDef().isSubClassOf("SideEffectsTraitBase")) { diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp index 0c0ad2cfeffd..0770ed562309 100644 --- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp +++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp @@ -295,7 +295,7 @@ static bool isODSReserved(StringRef str) { {"attributes", "create", "context", "ip", "operands", "print", "get_asm", "loc", "verify", "regions", "results", "self", "operation", "DIALECT_NAMESPACE", "OPERATION_NAME"}); - return str.startswith("_ods_") || str.endswith("_ods") || + return str.starts_with("_ods_") || str.ends_with("_ods") || reserved.contains(str); } -- 2.11.4.GIT