Skip to content

Commit 026a29e

Browse files
[Analysis, CodeGen, DebugInfo] Use StringRef::operator== instead of StringRef::equals (NFC) (#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);

llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,8 @@ void LVBinaryReader::mapVirtualAddress(const object::ObjectFile &Obj) {
184184
consumeError(SectionNameOrErr.takeError());
185185
continue;
186186
}
187-
if ((*SectionNameOrErr).equals(".text") ||
188-
(*SectionNameOrErr).equals("CODE") ||
189-
(*SectionNameOrErr).equals(".code")) {
187+
if (*SectionNameOrErr == ".text" || *SectionNameOrErr == "CODE" ||
188+
*SectionNameOrErr == ".code") {
190189
DotTextSectionIndex = Section.getIndex();
191190
// If the object is WebAssembly, update the address offset that
192191
// will be added to DWARF DW_AT_* attributes.

llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record,
834834
// Symbol was created as 'variable'; determine its real kind.
835835
Symbol->resetIsVariable();
836836

837-
if (Local.Name.equals("this")) {
837+
if (Local.Name == "this") {
838838
Symbol->setIsParameter();
839839
Symbol->setIsArtificial();
840840
} else {
@@ -885,7 +885,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record,
885885
Symbol->resetIsVariable();
886886

887887
// Check for the 'this' symbol.
888-
if (Local.Name.equals("this")) {
888+
if (Local.Name == "this") {
889889
Symbol->setIsArtificial();
890890
Symbol->setIsParameter();
891891
} else {
@@ -1429,7 +1429,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record, LocalSym &Local) {
14291429

14301430
// Be sure the 'this' symbol is marked as 'compiler generated'.
14311431
if (bool(Local.Flags & LocalSymFlags::IsCompilerGenerated) ||
1432-
Local.Name.equals("this")) {
1432+
Local.Name == "this") {
14331433
Symbol->setIsArtificial();
14341434
Symbol->setIsParameter();
14351435
} else {
@@ -1669,7 +1669,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record, UDTSym &UDT) {
16691669
Type->resetIncludeInPrint();
16701670
else {
16711671
StringRef RecordName = getRecordName(Types, UDT.Type);
1672-
if (UDT.Name.equals(RecordName))
1672+
if (UDT.Name == RecordName)
16731673
Type->resetIncludeInPrint();
16741674
Type->setType(LogicalVisitor->getElement(StreamTPI, UDT.Type));
16751675
}
@@ -2740,7 +2740,7 @@ Error LVLogicalVisitor::visitKnownMember(CVMemberRecord &Record,
27402740
getInnerComponent(NestedTypeName);
27412741
// We have an already created nested type. Add it to the current scope
27422742
// and update all its children if any.
2743-
if (OuterComponent.size() && OuterComponent.equals(RecordName)) {
2743+
if (OuterComponent.size() && OuterComponent == RecordName) {
27442744
if (!NestedType->getIsScopedAlready()) {
27452745
Scope->addElement(NestedType);
27462746
NestedType->setIsScopedAlready();

llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ std::vector<object::SectionedAddress>
355355
SymbolizableObjectFile::findSymbol(StringRef Symbol, uint64_t Offset) const {
356356
std::vector<object::SectionedAddress> Result;
357357
for (const SymbolDesc &Sym : Symbols) {
358-
if (Sym.Name.equals(Symbol)) {
358+
if (Sym.Name == Symbol) {
359359
uint64_t Addr = Sym.Addr;
360360
if (Offset < Sym.Size)
361361
Addr += Offset;

0 commit comments

Comments
 (0)