mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 05:40:09 +00:00
[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.
This commit is contained in:
parent
5c9d82de6b
commit
88d319a29f
@ -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<APFloat> result;
|
||||
if (failed(p.parseFloatFromIntegerLiteral(result, token, isNegative,
|
||||
eltTy.getFloatSemantics(),
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -2564,7 +2564,7 @@ BytecodeReader::finalize(function_ref<bool(Operation *)> 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.
|
||||
|
@ -14,7 +14,7 @@ using namespace mlir;
|
||||
using namespace mlir::amdgpu;
|
||||
|
||||
FailureOr<Chipset> Chipset::parse(StringRef name) {
|
||||
if (!name.startswith("gfx"))
|
||||
if (!name.starts_with("gfx"))
|
||||
return failure();
|
||||
unsigned major = 0;
|
||||
unsigned minor = 0;
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> 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);
|
||||
|
@ -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("*")) ? ""
|
||||
: " ";
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -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);
|
||||
|
@ -354,7 +354,7 @@ Deserializer::processOp<spirv::EntryPointOp>(ArrayRef<uint32_t> words) {
|
||||
// The deserializer uses "spirv_fn_<id>" 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 <id> ")
|
||||
|
@ -792,7 +792,7 @@ LogicalResult Parser::parseInclude(SmallVectorImpl<ast::Decl *> &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<ast::Decl *> &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,
|
||||
|
@ -157,7 +157,7 @@ static llvm::Expected<std::string> 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<std::string> uriFromAbsolutePath(StringRef absolutePath,
|
||||
|
||||
static llvm::Expected<std::string> 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 "
|
||||
|
@ -99,7 +99,7 @@ lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, SMLoc loc) {
|
||||
SmallVector<StringRef> commentLines;
|
||||
while (std::optional<StringRef> 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.
|
||||
|
@ -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;
|
||||
|
@ -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("."));
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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<StringRef> 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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -26,7 +26,7 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerTestOneInput(const uint8_t *data,
|
||||
return -1;
|
||||
llvm::StringRef str(reinterpret_cast<const char *>(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.
|
||||
|
@ -26,7 +26,7 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerTestOneInput(const uint8_t *data,
|
||||
return -1;
|
||||
llvm::StringRef str(reinterpret_cast<const char *>(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.
|
||||
|
@ -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<llvm::StringRef, 8> 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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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<InterfaceTrait>(&trait)) {
|
||||
if (trait.getDef().isSubClassOf("SideEffectsTraitBase")) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user