Skip to content

Commit 141122e

Browse files
committed
[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)
1 parent 7c93452 commit 141122e

10 files changed

+30
-30
lines changed

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static StringRef NormalizeNameForSpellingComparison(StringRef Name) {
161161
// Normalize the spelling of a GNU attribute (i.e. "x" in "__attribute__((x))"),
162162
// removing "__" if it appears at the beginning and end of the attribute's name.
163163
static StringRef NormalizeGNUAttrSpelling(StringRef AttrSpelling) {
164-
if (AttrSpelling.startswith("__") && AttrSpelling.endswith("__")) {
164+
if (AttrSpelling.starts_with("__") && AttrSpelling.ends_with("__")) {
165165
AttrSpelling = AttrSpelling.substr(2, AttrSpelling.size() - 4);
166166
}
167167

@@ -356,7 +356,7 @@ namespace {
356356
}
357357

358358
void writeDump(raw_ostream &OS) const override {
359-
if (StringRef(type).endswith("Decl *")) {
359+
if (StringRef(type).ends_with("Decl *")) {
360360
OS << " OS << \" \";\n";
361361
OS << " dumpBareDeclRef(SA->get" << getUpperName() << "());\n";
362362
} else if (type == "IdentifierInfo *") {
@@ -4537,7 +4537,7 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
45374537
continue;
45384538
ArgNames.push_back(Arg->getValueAsString("Name").str());
45394539
for (const auto &Class : Arg->getSuperClasses()) {
4540-
if (Class.first->getName().startswith("Variadic")) {
4540+
if (Class.first->getName().starts_with("Variadic")) {
45414541
ArgNames.back().append("...");
45424542
break;
45434543
}

clang/utils/TableGen/NeonEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,17 @@ Type Type::fromTypedefName(StringRef Name) {
736736
Name = Name.drop_front();
737737
}
738738

739-
if (Name.startswith("float")) {
739+
if (Name.starts_with("float")) {
740740
T.Kind = Float;
741741
Name = Name.drop_front(5);
742-
} else if (Name.startswith("poly")) {
742+
} else if (Name.starts_with("poly")) {
743743
T.Kind = Poly;
744744
Name = Name.drop_front(4);
745-
} else if (Name.startswith("bfloat")) {
745+
} else if (Name.starts_with("bfloat")) {
746746
T.Kind = BFloat16;
747747
Name = Name.drop_front(6);
748748
} else {
749-
assert(Name.startswith("int"));
749+
assert(Name.starts_with("int"));
750750
Name = Name.drop_front(3);
751751
}
752752

@@ -787,7 +787,7 @@ Type Type::fromTypedefName(StringRef Name) {
787787
Name = Name.drop_front(I);
788788
}
789789

790-
assert(Name.startswith("_t") && "Malformed typedef!");
790+
assert(Name.starts_with("_t") && "Malformed typedef!");
791791
return T;
792792
}
793793

@@ -1655,7 +1655,7 @@ std::pair<Type, std::string> Intrinsic::DagEmitter::emitDagShuffle(DagInit *DI){
16551655
std::string S = "__builtin_shufflevector(" + Arg1.second + ", " + Arg2.second;
16561656
for (auto &E : Elts) {
16571657
StringRef Name = E->getName();
1658-
assert_with_loc(Name.startswith("sv"),
1658+
assert_with_loc(Name.starts_with("sv"),
16591659
"Incorrect element kind in shuffle mask!");
16601660
S += ", " + Name.drop_front(2).str();
16611661
}

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ extractSingletonRegisterForAsmOperand(MatchableInfo::AsmOperand &Op,
910910
return;
911911
}
912912

913-
if (!Tok.startswith(RegisterPrefix))
913+
if (!Tok.starts_with(RegisterPrefix))
914914
return;
915915

916916
StringRef RegName = Tok.substr(RegisterPrefix.size());
@@ -1520,7 +1520,7 @@ void AsmMatcherInfo::buildInfo() {
15201520

15211521
// If the tblgen -match-prefix option is specified (for tblgen hackers),
15221522
// filter the set of instructions we consider.
1523-
if (!StringRef(CGI->TheDef->getName()).startswith(MatchPrefix))
1523+
if (!StringRef(CGI->TheDef->getName()).starts_with(MatchPrefix))
15241524
continue;
15251525

15261526
// Ignore "codegen only" instructions.
@@ -1555,7 +1555,7 @@ void AsmMatcherInfo::buildInfo() {
15551555
// filter the set of instruction aliases we consider, based on the target
15561556
// instruction.
15571557
if (!StringRef(Alias->ResultInst->TheDef->getName())
1558-
.startswith( MatchPrefix))
1558+
.starts_with(MatchPrefix))
15591559
continue;
15601560

15611561
StringRef V = Alias->TheDef->getValueAsString("AsmVariantName");

llvm/utils/TableGen/CallingConvEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) {
106106
// Emit all of the actions, in order.
107107
for (unsigned i = 0, e = CCActions->size(); i != e; ++i) {
108108
Record *Action = CCActions->getElementAsRecord(i);
109-
SwiftAction = llvm::any_of(Action->getSuperClasses(),
110-
[](const std::pair<Record *, SMRange> &Class) {
111-
std::string Name =
112-
Class.first->getNameInitAsString();
113-
return StringRef(Name).startswith("CCIfSwift");
114-
});
109+
SwiftAction =
110+
llvm::any_of(Action->getSuperClasses(),
111+
[](const std::pair<Record *, SMRange> &Class) {
112+
std::string Name = Class.first->getNameInitAsString();
113+
return StringRef(Name).starts_with("CCIfSwift");
114+
});
115115

116116
O << "\n";
117117
EmitAction(Action, 2, O);

llvm/utils/TableGen/CodeGenSchedule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct InstRegexOp : public SetTheory::Operator {
118118
// The generic opcodes are unsorted, handle them manually.
119119
for (auto *Inst : Generics) {
120120
StringRef InstName = Inst->TheDef->getName();
121-
if (InstName.startswith(Prefix) &&
121+
if (InstName.starts_with(Prefix) &&
122122
(!Regexpr || Regexpr->match(InstName.substr(Prefix.size())))) {
123123
Elts.insert(Inst->TheDef);
124124
NumMatches++;
@@ -134,7 +134,7 @@ struct InstRegexOp : public SetTheory::Operator {
134134
}
135135
bool operator()(StringRef LHS, const CodeGenInstruction *RHS) {
136136
return LHS < RHS->TheDef->getName() &&
137-
!RHS->TheDef->getName().startswith(LHS);
137+
!RHS->TheDef->getName().starts_with(LHS);
138138
}
139139
};
140140
auto Range1 =

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct DXILOperationData {
8181
if (R->getValue("llvm_intrinsic")) {
8282
auto *IntrinsicDef = R->getValueAsDef("llvm_intrinsic");
8383
auto DefName = IntrinsicDef->getName();
84-
assert(DefName.startswith("int_") && "invalid intrinsic name");
84+
assert(DefName.starts_with("int_") && "invalid intrinsic name");
8585
// Remove the int_ from intrinsic name.
8686
Intrinsic = DefName.substr(4);
8787
}

llvm/utils/TableGen/GlobalISel/CodeExpander.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ void CodeExpander::emit(raw_ostream &OS) const {
3131
OS << Current.substr(0, Pos);
3232
Current = Current.substr(Pos);
3333

34-
if (Current.startswith("\n")) {
34+
if (Current.starts_with("\n")) {
3535
OS << "\n" << Indent;
3636
Current = Current.drop_front(1);
3737
continue;
3838
}
3939

40-
if (Current.startswith("\\$") || Current.startswith("\\\\")) {
40+
if (Current.starts_with("\\$") || Current.starts_with("\\\\")) {
4141
OS << Current[1];
4242
Current = Current.drop_front(2);
4343
continue;
4444
}
4545

46-
if (Current.startswith("\\")) {
46+
if (Current.starts_with("\\")) {
4747
Current = Current.drop_front(1);
4848
continue;
4949
}
5050

51-
if (Current.startswith("${")) {
51+
if (Current.starts_with("${")) {
5252
StringRef StartVar = Current;
5353
Current = Current.drop_front(2);
5454
StringRef Var;

llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class GlobalISelMatchTableExecutorEmitter {
110110
OS << " case GICXXPred_" << TypeIdentifier << "_Predicate_"
111111
<< GetPredEnumName(Pred) << ": {\n"
112112
<< " " << Code << "\n";
113-
if (!StringRef(Code).ltrim().startswith("return")) {
113+
if (!StringRef(Code).ltrim().starts_with("return")) {
114114
OS << " llvm_unreachable(\"" << GetPredEnumName(Pred)
115115
<< " should have returned\");\n";
116116
}

llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void X86EVEX2VEXTablesEmitter::run(raw_ostream &OS) {
170170
// Currently we only do AVX related checks and assume each instruction
171171
// has one and only one AVX related predicates.
172172
for (unsigned i = 0, e = PredicatesRecords.size(); i != e; ++i)
173-
if (PredicatesRecords[i]->getName().startswith("HasAVX"))
173+
if (PredicatesRecords[i]->getName().starts_with("HasAVX"))
174174
return PredicatesRecords[i]->getValueAsString("CondString");
175175
llvm_unreachable(
176176
"Instruction with checkPredicate set must have one predicate!");
@@ -187,7 +187,7 @@ void X86EVEX2VEXTablesEmitter::run(raw_ostream &OS) {
187187
if (!Def->isSubClassOf("X86Inst"))
188188
continue;
189189
// _REV instruction should not appear before encoding optimization
190-
if (Def->getName().endswith("_REV"))
190+
if (Def->getName().ends_with("_REV"))
191191
continue;
192192
RecognizableInstrBase RI(*Inst);
193193

llvm/utils/TableGen/X86FoldTablesEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void X86FoldTablesEmitter::addEntryWithFlags(FoldTable &Table,
439439
// Check no-kz version's isMoveReg
440440
StringRef RegInstName = RegRec->getName();
441441
unsigned DropLen =
442-
RegInstName.endswith("rkz") ? 2 : (RegInstName.endswith("rk") ? 1 : 0);
442+
RegInstName.ends_with("rkz") ? 2 : (RegInstName.ends_with("rk") ? 1 : 0);
443443
Record *BaseDef =
444444
DropLen ? Records.getDef(RegInstName.drop_back(DropLen)) : nullptr;
445445
bool IsMoveReg =
@@ -598,7 +598,7 @@ void X86FoldTablesEmitter::run(raw_ostream &o) {
598598
if (Match != OpcRegInsts.end()) {
599599
const CodeGenInstruction *RegInst = *Match;
600600
StringRef RegInstName = RegInst->TheDef->getName();
601-
if (RegInstName.endswith("_REV") || RegInstName.endswith("_alt")) {
601+
if (RegInstName.ends_with("_REV") || RegInstName.ends_with("_alt")) {
602602
if (auto *RegAltRec = Records.getDef(RegInstName.drop_back(4))) {
603603
RegInst = &Target.getInstruction(RegAltRec);
604604
}

0 commit comments

Comments
 (0)