Skip to content

Commit 026a29e

Browse files
[Analysis, CodeGen, DebugInfo] Use StringRef::operator== instead of StringRef::equals (NFC) (llvm#91304)
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 53 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 7208569 commit 026a29e

13 files changed

+24
-28
lines changed

llvm/lib/Analysis/BlockFrequencyInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,11 @@ void BlockFrequencyInfo::calculate(const Function &F,
188188
BFI.reset(new ImplType);
189189
BFI->calculate(F, BPI, LI);
190190
if (ViewBlockFreqPropagationDAG != GVDT_None &&
191-
(ViewBlockFreqFuncName.empty() ||
192-
F.getName().equals(ViewBlockFreqFuncName))) {
191+
(ViewBlockFreqFuncName.empty() || F.getName() == ViewBlockFreqFuncName)) {
193192
view();
194193
}
195194
if (PrintBFI &&
196-
(PrintBFIFuncName.empty() || F.getName().equals(PrintBFIFuncName))) {
195+
(PrintBFIFuncName.empty() || F.getName() == PrintBFIFuncName)) {
197196
print(dbgs());
198197
}
199198
}

llvm/lib/Analysis/BranchProbabilityInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,8 @@ void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LoopI,
12731273
EstimatedBlockWeight.clear();
12741274
SccI.reset();
12751275

1276-
if (PrintBranchProb &&
1277-
(PrintBranchProbFuncName.empty() ||
1278-
F.getName().equals(PrintBranchProbFuncName))) {
1276+
if (PrintBranchProb && (PrintBranchProbFuncName.empty() ||
1277+
F.getName() == PrintBranchProbFuncName)) {
12791278
print(dbgs());
12801279
}
12811280
}

llvm/lib/Analysis/LoopInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ MDNode *llvm::findOptionMDForLoopID(MDNode *LoopID, StringRef Name) {
10321032
if (!S)
10331033
continue;
10341034
// Return the operand node if MDString holds expected metadata.
1035-
if (Name.equals(S->getString()))
1035+
if (Name == S->getString())
10361036
return MD;
10371037
}
10381038

llvm/lib/Analysis/MemoryProfileInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ AllocationType llvm::memprof::getMIBAllocType(const MDNode *MIB) {
8686
// types that can be applied based on the allocation profile data.
8787
auto *MDS = dyn_cast<MDString>(MIB->getOperand(1));
8888
assert(MDS);
89-
if (MDS->getString().equals("cold")) {
89+
if (MDS->getString() == "cold") {
9090
return AllocationType::Cold;
91-
} else if (MDS->getString().equals("hot")) {
91+
} else if (MDS->getString() == "hot") {
9292
return AllocationType::Hot;
9393
}
9494
return AllocationType::NotCold;

llvm/lib/CodeGen/MIRSampleProfile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ bool MIRProfileLoaderPass::runOnMachineFunction(MachineFunction &MF) {
372372
MF.RenumberBlocks();
373373
if (ViewBFIBefore && ViewBlockLayoutWithBFI != GVDT_None &&
374374
(ViewBlockFreqFuncName.empty() ||
375-
MF.getFunction().getName().equals(ViewBlockFreqFuncName))) {
375+
MF.getFunction().getName() == ViewBlockFreqFuncName)) {
376376
MBFI->view("MIR_Prof_loader_b." + MF.getName(), false);
377377
}
378378

@@ -382,7 +382,7 @@ bool MIRProfileLoaderPass::runOnMachineFunction(MachineFunction &MF) {
382382

383383
if (ViewBFIAfter && ViewBlockLayoutWithBFI != GVDT_None &&
384384
(ViewBlockFreqFuncName.empty() ||
385-
MF.getFunction().getName().equals(ViewBlockFreqFuncName))) {
385+
MF.getFunction().getName() == ViewBlockFreqFuncName)) {
386386
MBFI->view("MIR_prof_loader_a." + MF.getName(), false);
387387
}
388388

llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,11 @@ void MachineBlockFrequencyInfo::calculate(
198198
MBFI.reset(new ImplType);
199199
MBFI->calculate(F, MBPI, MLI);
200200
if (ViewMachineBlockFreqPropagationDAG != GVDT_None &&
201-
(ViewBlockFreqFuncName.empty() ||
202-
F.getName().equals(ViewBlockFreqFuncName))) {
201+
(ViewBlockFreqFuncName.empty() || F.getName() == ViewBlockFreqFuncName)) {
203202
view("MachineBlockFrequencyDAGS." + F.getName());
204203
}
205204
if (PrintMachineBlockFreq &&
206-
(PrintBFIFuncName.empty() || F.getName().equals(PrintBFIFuncName))) {
205+
(PrintBFIFuncName.empty() || F.getName() == PrintBFIFuncName)) {
207206
MBFI->print(dbgs());
208207
}
209208
}

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,7 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
35003500
}
35013501
if (ViewBlockLayoutWithBFI != GVDT_None &&
35023502
(ViewBlockFreqFuncName.empty() ||
3503-
F->getFunction().getName().equals(ViewBlockFreqFuncName))) {
3503+
F->getFunction().getName() == ViewBlockFreqFuncName)) {
35043504
if (RenumberBlocksBeforeView)
35053505
MF.RenumberBlocks();
35063506
MBFI->view("MBP." + MF.getName(), false);

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override) {
22492249
if (IsDisabled)
22502250
RecipType = RecipType.substr(1);
22512251

2252-
if (RecipType.equals(VTName) || RecipType.equals(VTNameNoSize))
2252+
if (RecipType == VTName || RecipType == VTNameNoSize)
22532253
return IsDisabled ? TargetLoweringBase::ReciprocalEstimate::Disabled
22542254
: TargetLoweringBase::ReciprocalEstimate::Enabled;
22552255
}
@@ -2299,7 +2299,7 @@ static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override) {
22992299
continue;
23002300

23012301
RecipType = RecipType.substr(0, RefPos);
2302-
if (RecipType.equals(VTName) || RecipType.equals(VTNameNoSize))
2302+
if (RecipType == VTName || RecipType == VTNameNoSize)
23032303
return RefSteps;
23042304
}
23052305

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
10361036
// name, or a unique ID for the section.
10371037
SmallString<128> Name;
10381038
StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
1039-
if (FunctionSectionName.equals(".text") ||
1039+
if (FunctionSectionName == ".text" ||
10401040
FunctionSectionName.starts_with(".text.")) {
10411041
// Function is in a regular .text section.
10421042
StringRef FunctionName = MBB.getParent()->getName();

llvm/lib/DebugInfo/LogicalView/Core/LVOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ bool LVPatterns::matchPattern(StringRef Input, const LVMatchInfo &MatchInfo) {
512512
for (const LVMatch &Match : MatchInfo) {
513513
switch (Match.Mode) {
514514
case LVMatchMode::Match:
515-
Matched = Input.equals(Match.Pattern);
515+
Matched = Input == Match.Pattern;
516516
break;
517517
case LVMatchMode::NoCase:
518518
Matched = Input.equals_insensitive(Match.Pattern);

0 commit comments

Comments
 (0)