Skip to content

Commit c18bcd0

Browse files
[Target] Use StringRef::operator== instead of StringRef::equals (NFC) (#91072) (#91138)
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 38 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 3219c0e commit c18bcd0

16 files changed

+36
-35
lines changed

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
5656
}
5757

5858
StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
59-
if (Scope.equals("none"))
59+
if (Scope == "none")
6060
return {false, false};
6161

62-
if (Scope.equals("all"))
62+
if (Scope == "all")
6363
return {true, true};
6464

65-
assert(Scope.equals("non-leaf"));
65+
assert(Scope == "non-leaf");
6666
return {true, false};
6767
}
6868

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ void AMDGPUAsmPrinter::emitResourceUsageRemarks(
13061306
// makes it easier to tell which resource usage go with which kernel since
13071307
// the kernel name will always be displayed first.
13081308
std::string LabelStr = RemarkLabel.str() + ": ";
1309-
if (!RemarkName.equals("FunctionName"))
1309+
if (RemarkName != "FunctionName")
13101310
LabelStr = Indent + LabelStr;
13111311

13121312
ORE->emit([&]() {

llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ struct AAUniformWorkGroupSizeFunction : public AAUniformWorkGroupSize {
332332

333333
bool InitialValue = false;
334334
if (F->hasFnAttribute("uniform-work-group-size"))
335-
InitialValue = F->getFnAttribute("uniform-work-group-size")
336-
.getValueAsString()
337-
.equals("true");
335+
InitialValue =
336+
F->getFnAttribute("uniform-work-group-size").getValueAsString() ==
337+
"true";
338338

339339
if (InitialValue)
340340
indicateOptimisticFixpoint();

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI,
14601460
if (G->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS ||
14611461
G->getAddressSpace() == AMDGPUAS::REGION_ADDRESS) {
14621462
if (!MFI->isModuleEntryFunction() &&
1463-
!GV->getName().equals("llvm.amdgcn.module.lds")) {
1463+
GV->getName() != "llvm.amdgcn.module.lds") {
14641464
SDLoc DL(Op);
14651465
const Function &Fn = DAG.getMachineFunction().getFunction();
14661466
DiagnosticInfoUnsupported BadLDSDecl(

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ bool AMDGPULegalizerInfo::legalizeGlobalValue(
29192919

29202920
if (AS == AMDGPUAS::LOCAL_ADDRESS || AS == AMDGPUAS::REGION_ADDRESS) {
29212921
if (!MFI->isModuleEntryFunction() &&
2922-
!GV->getName().equals("llvm.amdgcn.module.lds")) {
2922+
GV->getName() != "llvm.amdgcn.module.lds") {
29232923
const Function &Fn = MF.getFunction();
29242924
DiagnosticInfoUnsupported BadLDSDecl(
29252925
Fn, "local memory global used by non-kernel function", MI.getDebugLoc(),

llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
6161
}
6262

6363
StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
64-
if (Scope.equals("none"))
64+
if (Scope == "none")
6565
return {false, false};
6666

67-
if (Scope.equals("all"))
67+
if (Scope == "all")
6868
return {true, true};
6969

70-
assert(Scope.equals("non-leaf"));
70+
assert(Scope == "non-leaf");
7171
return {true, false};
7272
}
7373

llvm/lib/Target/BPF/BTFDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void BTFDebug::processDeclAnnotations(DINodeArray Annotations,
588588
for (const Metadata *Annotation : Annotations->operands()) {
589589
const MDNode *MD = cast<MDNode>(Annotation);
590590
const MDString *Name = cast<MDString>(MD->getOperand(0));
591-
if (!Name->getString().equals("btf_decl_tag"))
591+
if (Name->getString() != "btf_decl_tag")
592592
continue;
593593

594594
const MDString *Value = cast<MDString>(MD->getOperand(1));
@@ -627,7 +627,7 @@ int BTFDebug::genBTFTypeTags(const DIDerivedType *DTy, int BaseTypeId) {
627627
for (const Metadata *Annotations : Annots->operands()) {
628628
const MDNode *MD = cast<MDNode>(Annotations);
629629
const MDString *Name = cast<MDString>(MD->getOperand(0));
630-
if (!Name->getString().equals("btf_type_tag"))
630+
if (Name->getString() != "btf_type_tag")
631631
continue;
632632
MDStrs.push_back(cast<MDString>(MD->getOperand(1)));
633633
}

llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static cl::opt<bool>
8686
static bool isSmallDataSection(StringRef Sec) {
8787
// sectionName is either ".sdata" or ".sbss". Looking for an exact match
8888
// obviates the need for checks for section names such as ".sdatafoo".
89-
if (Sec.equals(".sdata") || Sec.equals(".sbss") || Sec.equals(".scommon"))
89+
if (Sec == ".sdata" || Sec == ".sbss" || Sec == ".scommon")
9090
return true;
9191
// If either ".sdata." or ".sbss." is a substring of the section name
9292
// then put the symbol in small data.

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ StringRef Hexagon_MC::selectHexagonCPU(StringRef CPU) {
158158
// non-tiny subtarget. See: addArchSubtarget
159159
std::pair<StringRef, StringRef> ArchP = ArchV.split('t');
160160
std::pair<StringRef, StringRef> CPUP = CPU.split('t');
161-
if (!ArchP.first.equals(CPUP.first))
161+
if (ArchP.first != CPUP.first)
162162
report_fatal_error("conflicting architectures specified.");
163163
return CPU;
164164
}
@@ -578,7 +578,7 @@ MCSubtargetInfo *Hexagon_MC::createHexagonMCSubtargetInfo(const Triple &TT,
578578
if (X != nullptr && (CPUName == "hexagonv67t" || CPUName == "hexagon71t"))
579579
addArchSubtarget(X, ArchFS);
580580

581-
if (CPU.equals("help"))
581+
if (CPU == "help")
582582
exit(0);
583583

584584
if (!isCPUValid(CPUName.str())) {

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ void PPCAIXAsmPrinter::emitPGORefs(Module &M) {
28962896
bool HasNonZeroLengthPrfCntsSection = false;
28972897
const DataLayout &DL = M.getDataLayout();
28982898
for (GlobalVariable &GV : M.globals())
2899-
if (GV.hasSection() && GV.getSection().equals("__llvm_prf_cnts") &&
2899+
if (GV.hasSection() && GV.getSection() == "__llvm_prf_cnts" &&
29002900
DL.getTypeAllocSize(GV.getValueType()) > 0) {
29012901
HasNonZeroLengthPrfCntsSection = true;
29022902
break;

0 commit comments

Comments
 (0)