Skip to content

Commit f4f5602

Browse files
kazutakahiratasookach
authored andcommitted
[Transforms] Use StringRef::operator== instead of StringRef::equals (NFC) (llvm#91072)
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 31 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
1 parent ad7499a commit f4f5602

File tree

10 files changed

+26
-28
lines changed

10 files changed

+26
-28
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,11 +1846,10 @@ static void splitAsyncCoroutine(Function &F, coro::Shape &Shape,
18461846
auto ProjectionFunctionName =
18471847
Suspend->getAsyncContextProjectionFunction()->getName();
18481848
bool UseSwiftMangling = false;
1849-
if (ProjectionFunctionName.equals("__swift_async_resume_project_context")) {
1849+
if (ProjectionFunctionName == "__swift_async_resume_project_context") {
18501850
ResumeNameSuffix = "TQ";
18511851
UseSwiftMangling = true;
1852-
} else if (ProjectionFunctionName.equals(
1853-
"__swift_async_resume_get_context")) {
1852+
} else if (ProjectionFunctionName == "__swift_async_resume_get_context") {
18541853
ResumeNameSuffix = "TY";
18551854
UseSwiftMangling = true;
18561855
}

llvm/lib/Transforms/IPO/BlockExtractor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ bool BlockExtractor::runOnModule(Module &M) {
142142
report_fatal_error("Invalid function name specified in the input file",
143143
/*GenCrashDiag=*/false);
144144
for (const auto &BBInfo : BInfo.second) {
145-
auto Res = llvm::find_if(*F, [&](const BasicBlock &BB) {
146-
return BB.getName().equals(BBInfo);
147-
});
145+
auto Res = llvm::find_if(
146+
*F, [&](const BasicBlock &BB) { return BB.getName() == BBInfo; });
148147
if (Res == F->end())
149148
report_fatal_error("Invalid block name specified in the input file",
150149
/*GenCrashDiag=*/false);

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ static bool annotateAllFunctions(
21252125
HotFunctions.push_back(&F);
21262126
if (PGOViewCounts != PGOVCT_None &&
21272127
(ViewBlockFreqFuncName.empty() ||
2128-
F.getName().equals(ViewBlockFreqFuncName))) {
2128+
F.getName() == ViewBlockFreqFuncName)) {
21292129
LoopInfo LI{DominatorTree(F)};
21302130
std::unique_ptr<BranchProbabilityInfo> NewBPI =
21312131
std::make_unique<BranchProbabilityInfo>(F, LI);
@@ -2140,7 +2140,7 @@ static bool annotateAllFunctions(
21402140
}
21412141
if (PGOViewRawCounts != PGOVCT_None &&
21422142
(ViewBlockFreqFuncName.empty() ||
2143-
F.getName().equals(ViewBlockFreqFuncName))) {
2143+
F.getName() == ViewBlockFreqFuncName)) {
21442144
if (PGOViewRawCounts == PGOVCT_Graph)
21452145
if (ViewBlockFreqFuncName.empty())
21462146
WriteGraph(&Func, Twine("PGORawCounts_") + Func.getFunc().getName());

llvm/lib/Transforms/Scalar/ADCE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ bool AggressiveDeadCodeElimination::isInstrumentsConstant(Instruction &I) {
350350
// TODO -- move this test into llvm::isInstructionTriviallyDead
351351
if (CallInst *CI = dyn_cast<CallInst>(&I))
352352
if (Function *Callee = CI->getCalledFunction())
353-
if (Callee->getName().equals(getInstrProfValueProfFuncName()))
353+
if (Callee->getName() == getInstrProfValueProfFuncName())
354354
if (isa<Constant>(CI->getArgOperand(0)))
355355
return true;
356356
return false;

llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static Instruction *findLocationForEntrySafepoint(Function &F,
591591
const char GCSafepointPollName[] = "gc.safepoint_poll";
592592

593593
static bool isGCSafepointPoll(Function &F) {
594-
return F.getName().equals(GCSafepointPollName);
594+
return F.getName() == GCSafepointPollName;
595595
}
596596

597597
/// Returns true if this function should be rewritten to include safepoint

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,10 +1685,10 @@ makeStatepointExplicitImpl(CallBase *Call, /* to replace */
16851685

16861686
// Pass through the requested lowering if any. The default is live-through.
16871687
StringRef DeoptLowering = getDeoptLowering(Call);
1688-
if (DeoptLowering.equals("live-in"))
1688+
if (DeoptLowering == "live-in")
16891689
Flags |= uint32_t(StatepointFlags::DeoptLiveIn);
16901690
else {
1691-
assert(DeoptLowering.equals("live-through") && "Unsupported value!");
1691+
assert(DeoptLowering == "live-through" && "Unsupported value!");
16921692
}
16931693

16941694
FunctionCallee CallTarget(Call->getFunctionType(), Call->getCalledOperand());

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ MDNode *llvm::GetUnrollMetadata(MDNode *LoopID, StringRef Name) {
10771077
if (!S)
10781078
continue;
10791079

1080-
if (Name.equals(S->getString()))
1080+
if (Name == S->getString())
10811081
return MD;
10821082
}
10831083
return nullptr;

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *StringMD,
222222
// If it is of form key = value, try to parse it.
223223
if (Node->getNumOperands() == 2) {
224224
MDString *S = dyn_cast<MDString>(Node->getOperand(0));
225-
if (S && S->getString().equals(StringMD)) {
225+
if (S && S->getString() == StringMD) {
226226
ConstantInt *IntMD =
227227
mdconst::extract_or_null<ConstantInt>(Node->getOperand(1));
228228
if (IntMD && IntMD->getSExtValue() == V)

llvm/lib/Transforms/Utils/SymbolRewriter.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ bool RewriteMapParser::parseEntry(yaml::Stream &YS, yaml::KeyValueNode &Entry,
308308
}
309309

310310
RewriteType = Key->getValue(KeyStorage);
311-
if (RewriteType.equals("function"))
311+
if (RewriteType == "function")
312312
return parseRewriteFunctionDescriptor(YS, Key, Value, DL);
313-
else if (RewriteType.equals("global variable"))
313+
else if (RewriteType == "global variable")
314314
return parseRewriteGlobalVariableDescriptor(YS, Key, Value, DL);
315-
else if (RewriteType.equals("global alias"))
315+
else if (RewriteType == "global alias")
316316
return parseRewriteGlobalAliasDescriptor(YS, Key, Value, DL);
317317

318318
YS.printError(Entry.getKey(), "unknown rewrite type");
@@ -348,19 +348,19 @@ parseRewriteFunctionDescriptor(yaml::Stream &YS, yaml::ScalarNode *K,
348348
}
349349

350350
KeyValue = Key->getValue(KeyStorage);
351-
if (KeyValue.equals("source")) {
351+
if (KeyValue == "source") {
352352
std::string Error;
353353

354354
Source = std::string(Value->getValue(ValueStorage));
355355
if (!Regex(Source).isValid(Error)) {
356356
YS.printError(Field.getKey(), "invalid regex: " + Error);
357357
return false;
358358
}
359-
} else if (KeyValue.equals("target")) {
359+
} else if (KeyValue == "target") {
360360
Target = std::string(Value->getValue(ValueStorage));
361-
} else if (KeyValue.equals("transform")) {
361+
} else if (KeyValue == "transform") {
362362
Transform = std::string(Value->getValue(ValueStorage));
363-
} else if (KeyValue.equals("naked")) {
363+
} else if (KeyValue == "naked") {
364364
std::string Undecorated;
365365

366366
Undecorated = std::string(Value->getValue(ValueStorage));
@@ -417,17 +417,17 @@ parseRewriteGlobalVariableDescriptor(yaml::Stream &YS, yaml::ScalarNode *K,
417417
}
418418

419419
KeyValue = Key->getValue(KeyStorage);
420-
if (KeyValue.equals("source")) {
420+
if (KeyValue == "source") {
421421
std::string Error;
422422

423423
Source = std::string(Value->getValue(ValueStorage));
424424
if (!Regex(Source).isValid(Error)) {
425425
YS.printError(Field.getKey(), "invalid regex: " + Error);
426426
return false;
427427
}
428-
} else if (KeyValue.equals("target")) {
428+
} else if (KeyValue == "target") {
429429
Target = std::string(Value->getValue(ValueStorage));
430-
} else if (KeyValue.equals("transform")) {
430+
} else if (KeyValue == "transform") {
431431
Transform = std::string(Value->getValue(ValueStorage));
432432
} else {
433433
YS.printError(Field.getKey(), "unknown Key for Global Variable");
@@ -480,17 +480,17 @@ parseRewriteGlobalAliasDescriptor(yaml::Stream &YS, yaml::ScalarNode *K,
480480
}
481481

482482
KeyValue = Key->getValue(KeyStorage);
483-
if (KeyValue.equals("source")) {
483+
if (KeyValue == "source") {
484484
std::string Error;
485485

486486
Source = std::string(Value->getValue(ValueStorage));
487487
if (!Regex(Source).isValid(Error)) {
488488
YS.printError(Field.getKey(), "invalid regex: " + Error);
489489
return false;
490490
}
491-
} else if (KeyValue.equals("target")) {
491+
} else if (KeyValue == "target") {
492492
Target = std::string(Value->getValue(ValueStorage));
493-
} else if (KeyValue.equals("transform")) {
493+
} else if (KeyValue == "transform") {
494494
Transform = std::string(Value->getValue(ValueStorage));
495495
} else {
496496
YS.printError(Field.getKey(), "unknown key for Global Alias");

llvm/unittests/Transforms/Utils/LocalTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ TEST(Local, SimplifyCFGWithNullAC) {
11961196
// Obtain BasicBlock of interest to this test, %test.bb.
11971197
BasicBlock *TestBB = nullptr;
11981198
for (BasicBlock &BB : F) {
1199-
if (BB.getName().equals("test.bb")) {
1199+
if (BB.getName() == "test.bb") {
12001200
TestBB = &BB;
12011201
break;
12021202
}

0 commit comments

Comments
 (0)