Author: Simon Pilgrim Date: 2023-11-03T17:53:56Z New Revision: 141122ece3c09a2f2e3c0280687633820bf632d5
URL: https://github.com/llvm/llvm-project/commit/141122ece3c09a2f2e3c0280687633820bf632d5 DIFF: https://github.com/llvm/llvm-project/commit/141122ece3c09a2f2e3c0280687633820bf632d5.diff LOG: [TableGen] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC. startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view) Added: Modified: clang/utils/TableGen/ClangAttrEmitter.cpp clang/utils/TableGen/NeonEmitter.cpp llvm/utils/TableGen/AsmMatcherEmitter.cpp llvm/utils/TableGen/CallingConvEmitter.cpp llvm/utils/TableGen/CodeGenSchedule.cpp llvm/utils/TableGen/DXILEmitter.cpp llvm/utils/TableGen/GlobalISel/CodeExpander.cpp llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp llvm/utils/TableGen/X86FoldTablesEmitter.cpp Removed: ################################################################################ diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 4231bcbb362539d..4ec00573e8a9da8 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -161,7 +161,7 @@ static StringRef NormalizeNameForSpellingComparison(StringRef Name) { // Normalize the spelling of a GNU attribute (i.e. "x" in "__attribute__((x))"), // removing "__" if it appears at the beginning and end of the attribute's name. static StringRef NormalizeGNUAttrSpelling(StringRef AttrSpelling) { - if (AttrSpelling.startswith("__") && AttrSpelling.endswith("__")) { + if (AttrSpelling.starts_with("__") && AttrSpelling.ends_with("__")) { AttrSpelling = AttrSpelling.substr(2, AttrSpelling.size() - 4); } @@ -356,7 +356,7 @@ namespace { } void writeDump(raw_ostream &OS) const override { - if (StringRef(type).endswith("Decl *")) { + if (StringRef(type).ends_with("Decl *")) { OS << " OS << \" \";\n"; OS << " dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; } else if (type == "IdentifierInfo *") { @@ -4537,7 +4537,7 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, raw_ostream &OS) { continue; ArgNames.push_back(Arg->getValueAsString("Name").str()); for (const auto &Class : Arg->getSuperClasses()) { - if (Class.first->getName().startswith("Variadic")) { + if (Class.first->getName().starts_with("Variadic")) { ArgNames.back().append("..."); break; } diff --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp index 3c891dbe9d7aa0f..4b112972a1ec981 100644 --- a/clang/utils/TableGen/NeonEmitter.cpp +++ b/clang/utils/TableGen/NeonEmitter.cpp @@ -736,17 +736,17 @@ Type Type::fromTypedefName(StringRef Name) { Name = Name.drop_front(); } - if (Name.startswith("float")) { + if (Name.starts_with("float")) { T.Kind = Float; Name = Name.drop_front(5); - } else if (Name.startswith("poly")) { + } else if (Name.starts_with("poly")) { T.Kind = Poly; Name = Name.drop_front(4); - } else if (Name.startswith("bfloat")) { + } else if (Name.starts_with("bfloat")) { T.Kind = BFloat16; Name = Name.drop_front(6); } else { - assert(Name.startswith("int")); + assert(Name.starts_with("int")); Name = Name.drop_front(3); } @@ -787,7 +787,7 @@ Type Type::fromTypedefName(StringRef Name) { Name = Name.drop_front(I); } - assert(Name.startswith("_t") && "Malformed typedef!"); + assert(Name.starts_with("_t") && "Malformed typedef!"); return T; } @@ -1655,7 +1655,7 @@ std::pair<Type, std::string> Intrinsic::DagEmitter::emitDagShuffle(DagInit *DI){ std::string S = "__builtin_shufflevector(" + Arg1.second + ", " + Arg2.second; for (auto &E : Elts) { StringRef Name = E->getName(); - assert_with_loc(Name.startswith("sv"), + assert_with_loc(Name.starts_with("sv"), "Incorrect element kind in shuffle mask!"); S += ", " + Name.drop_front(2).str(); } diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp index 6231f5530d35146..f774f0c1018b3e1 100644 --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -910,7 +910,7 @@ extractSingletonRegisterForAsmOperand(MatchableInfo::AsmOperand &Op, return; } - if (!Tok.startswith(RegisterPrefix)) + if (!Tok.starts_with(RegisterPrefix)) return; StringRef RegName = Tok.substr(RegisterPrefix.size()); @@ -1520,7 +1520,7 @@ void AsmMatcherInfo::buildInfo() { // If the tblgen -match-prefix option is specified (for tblgen hackers), // filter the set of instructions we consider. - if (!StringRef(CGI->TheDef->getName()).startswith(MatchPrefix)) + if (!StringRef(CGI->TheDef->getName()).starts_with(MatchPrefix)) continue; // Ignore "codegen only" instructions. @@ -1555,7 +1555,7 @@ void AsmMatcherInfo::buildInfo() { // filter the set of instruction aliases we consider, based on the target // instruction. if (!StringRef(Alias->ResultInst->TheDef->getName()) - .startswith( MatchPrefix)) + .starts_with(MatchPrefix)) continue; StringRef V = Alias->TheDef->getValueAsString("AsmVariantName"); diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp index de3810b2e227916..06670e84d857260 100644 --- a/llvm/utils/TableGen/CallingConvEmitter.cpp +++ b/llvm/utils/TableGen/CallingConvEmitter.cpp @@ -106,12 +106,12 @@ void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) { // Emit all of the actions, in order. for (unsigned i = 0, e = CCActions->size(); i != e; ++i) { Record *Action = CCActions->getElementAsRecord(i); - SwiftAction = llvm::any_of(Action->getSuperClasses(), - [](const std::pair<Record *, SMRange> &Class) { - std::string Name = - Class.first->getNameInitAsString(); - return StringRef(Name).startswith("CCIfSwift"); - }); + SwiftAction = + llvm::any_of(Action->getSuperClasses(), + [](const std::pair<Record *, SMRange> &Class) { + std::string Name = Class.first->getNameInitAsString(); + return StringRef(Name).starts_with("CCIfSwift"); + }); O << "\n"; EmitAction(Action, 2, O); diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index c753d9f9edd4319..c3c5e4f8eb2d8c3 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -118,7 +118,7 @@ struct InstRegexOp : public SetTheory::Operator { // The generic opcodes are unsorted, handle them manually. for (auto *Inst : Generics) { StringRef InstName = Inst->TheDef->getName(); - if (InstName.startswith(Prefix) && + if (InstName.starts_with(Prefix) && (!Regexpr || Regexpr->match(InstName.substr(Prefix.size())))) { Elts.insert(Inst->TheDef); NumMatches++; @@ -134,7 +134,7 @@ struct InstRegexOp : public SetTheory::Operator { } bool operator()(StringRef LHS, const CodeGenInstruction *RHS) { return LHS < RHS->TheDef->getName() && - !RHS->TheDef->getName().startswith(LHS); + !RHS->TheDef->getName().starts_with(LHS); } }; auto Range1 = diff --git a/llvm/utils/TableGen/DXILEmitter.cpp b/llvm/utils/TableGen/DXILEmitter.cpp index b294c66007f8419..a199463961be419 100644 --- a/llvm/utils/TableGen/DXILEmitter.cpp +++ b/llvm/utils/TableGen/DXILEmitter.cpp @@ -81,7 +81,7 @@ struct DXILOperationData { if (R->getValue("llvm_intrinsic")) { auto *IntrinsicDef = R->getValueAsDef("llvm_intrinsic"); auto DefName = IntrinsicDef->getName(); - assert(DefName.startswith("int_") && "invalid intrinsic name"); + assert(DefName.starts_with("int_") && "invalid intrinsic name"); // Remove the int_ from intrinsic name. Intrinsic = DefName.substr(4); } diff --git a/llvm/utils/TableGen/GlobalISel/CodeExpander.cpp b/llvm/utils/TableGen/GlobalISel/CodeExpander.cpp index 42b4aabf2755e7f..20f98bef4887c74 100644 --- a/llvm/utils/TableGen/GlobalISel/CodeExpander.cpp +++ b/llvm/utils/TableGen/GlobalISel/CodeExpander.cpp @@ -31,24 +31,24 @@ void CodeExpander::emit(raw_ostream &OS) const { OS << Current.substr(0, Pos); Current = Current.substr(Pos); - if (Current.startswith("\n")) { + if (Current.starts_with("\n")) { OS << "\n" << Indent; Current = Current.drop_front(1); continue; } - if (Current.startswith("\\$") || Current.startswith("\\\\")) { + if (Current.starts_with("\\$") || Current.starts_with("\\\\")) { OS << Current[1]; Current = Current.drop_front(2); continue; } - if (Current.startswith("\\")) { + if (Current.starts_with("\\")) { Current = Current.drop_front(1); continue; } - if (Current.startswith("${")) { + if (Current.starts_with("${")) { StringRef StartVar = Current; Current = Current.drop_front(2); StringRef Var; diff --git a/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h b/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h index 13193ff8cc9fefd..c30198f11195c68 100644 --- a/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h +++ b/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h @@ -110,7 +110,7 @@ class GlobalISelMatchTableExecutorEmitter { OS << " case GICXXPred_" << TypeIdentifier << "_Predicate_" << GetPredEnumName(Pred) << ": {\n" << " " << Code << "\n"; - if (!StringRef(Code).ltrim().startswith("return")) { + if (!StringRef(Code).ltrim().starts_with("return")) { OS << " llvm_unreachable(\"" << GetPredEnumName(Pred) << " should have returned\");\n"; } diff --git a/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp b/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp index 4b71174604c4f11..9871cf62cc0ad68 100644 --- a/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp +++ b/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp @@ -170,7 +170,7 @@ void X86EVEX2VEXTablesEmitter::run(raw_ostream &OS) { // Currently we only do AVX related checks and assume each instruction // has one and only one AVX related predicates. for (unsigned i = 0, e = PredicatesRecords.size(); i != e; ++i) - if (PredicatesRecords[i]->getName().startswith("HasAVX")) + if (PredicatesRecords[i]->getName().starts_with("HasAVX")) return PredicatesRecords[i]->getValueAsString("CondString"); llvm_unreachable( "Instruction with checkPredicate set must have one predicate!"); @@ -187,7 +187,7 @@ void X86EVEX2VEXTablesEmitter::run(raw_ostream &OS) { if (!Def->isSubClassOf("X86Inst")) continue; // _REV instruction should not appear before encoding optimization - if (Def->getName().endswith("_REV")) + if (Def->getName().ends_with("_REV")) continue; RecognizableInstrBase RI(*Inst); diff --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp index 6144e8b214c9866..86e8de89bc7e539 100644 --- a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp +++ b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp @@ -439,7 +439,7 @@ void X86FoldTablesEmitter::addEntryWithFlags(FoldTable &Table, // Check no-kz version's isMoveReg StringRef RegInstName = RegRec->getName(); unsigned DropLen = - RegInstName.endswith("rkz") ? 2 : (RegInstName.endswith("rk") ? 1 : 0); + RegInstName.ends_with("rkz") ? 2 : (RegInstName.ends_with("rk") ? 1 : 0); Record *BaseDef = DropLen ? Records.getDef(RegInstName.drop_back(DropLen)) : nullptr; bool IsMoveReg = @@ -598,7 +598,7 @@ void X86FoldTablesEmitter::run(raw_ostream &o) { if (Match != OpcRegInsts.end()) { const CodeGenInstruction *RegInst = *Match; StringRef RegInstName = RegInst->TheDef->getName(); - if (RegInstName.endswith("_REV") || RegInstName.endswith("_alt")) { + if (RegInstName.ends_with("_REV") || RegInstName.ends_with("_alt")) { if (auto *RegAltRec = Records.getDef(RegInstName.drop_back(4))) { RegInst = &Target.getInstruction(RegAltRec); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits