Skip to content

Commit c18bcd0

Browse files
[Target] Use StringRef::operator== instead of StringRef::equals (NFC) (llvm#91072) (llvm#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;

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,9 +5302,10 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
53025302
SDValue MDV = N->getOperand(MDIndex);
53035303
const MDNode *MD = cast<MDNodeSDNode>(MDV)->getMD();
53045304
assert(MD->getNumOperands() != 0 && "Empty MDNode in operands!");
5305-
assert((isa<MDString>(MD->getOperand(0)) && cast<MDString>(
5306-
MD->getOperand(0))->getString().equals("ppc-trap-reason"))
5307-
&& "Unsupported annotation data type!");
5305+
assert((isa<MDString>(MD->getOperand(0)) &&
5306+
cast<MDString>(MD->getOperand(0))->getString() ==
5307+
"ppc-trap-reason") &&
5308+
"Unsupported annotation data type!");
53085309
for (unsigned i = 1; i < MD->getNumOperands(); i++) {
53095310
assert(isa<MDString>(MD->getOperand(i)) &&
53105311
"Invalid data type for annotation ppc-trap-reason!");

llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static bool hasPCRelativeForm(MachineInstr &Use) {
415415
bool runOnMachineFunction(MachineFunction &MF) override {
416416
// If the user wants to set the DSCR using command-line options,
417417
// load in the specified value at the start of main.
418-
if (DSCRValue.getNumOccurrences() > 0 && MF.getName().equals("main") &&
418+
if (DSCRValue.getNumOccurrences() > 0 && MF.getName() == "main" &&
419419
MF.getFunction().hasExternalLinkage()) {
420420
DSCRValue = (uint32_t)(DSCRValue & 0x01FFFFFF); // 25-bit DSCR mask
421421
RegScavenger RS;

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ static bool buildNDRange(const SPIRV::IncomingCall *Call,
17631763
if (!MRI->getRegClassOrNull(GWSPtr))
17641764
MRI->setRegClass(GWSPtr, &SPIRV::IDRegClass);
17651765
// TODO: Maybe simplify generation of the type of the fields.
1766-
unsigned Size = Call->Builtin->Name.equals("ndrange_3D") ? 3 : 2;
1766+
unsigned Size = Call->Builtin->Name == "ndrange_3D" ? 3 : 2;
17671767
unsigned BitWidth = GR->getPointerSize() == 64 ? 64 : 32;
17681768
Type *BaseTy = IntegerType::get(MF.getFunction().getContext(), BitWidth);
17691769
Type *FieldTy = ArrayType::get(BaseTy, Size);

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,44 +1377,44 @@ MCRegister SparcAsmParser::matchRegisterName(const AsmToken &Tok,
13771377
return IntRegs[RegNo];
13781378
}
13791379

1380-
if (Name.equals("xcc")) {
1380+
if (Name == "xcc") {
13811381
// FIXME:: check 64bit.
13821382
RegKind = SparcOperand::rk_Special;
13831383
return SP::ICC;
13841384
}
13851385

13861386
// JPS1 extension - aliases for ASRs
13871387
// Section A.51 - Read State Register
1388-
if (Name.equals("pcr")) {
1388+
if (Name == "pcr") {
13891389
RegKind = SparcOperand::rk_Special;
13901390
return SP::ASR16;
13911391
}
13921392

1393-
if (Name.equals("pic")) {
1393+
if (Name == "pic") {
13941394
RegKind = SparcOperand::rk_Special;
13951395
return SP::ASR17;
13961396
}
1397-
if (Name.equals("dcr")) {
1397+
if (Name == "dcr") {
13981398
RegKind = SparcOperand::rk_Special;
13991399
return SP::ASR18;
14001400
}
1401-
if (Name.equals("gsr")) {
1401+
if (Name == "gsr") {
14021402
RegKind = SparcOperand::rk_Special;
14031403
return SP::ASR19;
14041404
}
1405-
if (Name.equals("softint")) {
1405+
if (Name == "softint") {
14061406
RegKind = SparcOperand::rk_Special;
14071407
return SP::ASR22;
14081408
}
1409-
if (Name.equals("tick_cmpr")) {
1409+
if (Name == "tick_cmpr") {
14101410
RegKind = SparcOperand::rk_Special;
14111411
return SP::ASR23;
14121412
}
1413-
if (Name.equals("stick") || Name.equals("sys_tick")) {
1413+
if (Name == "stick" || Name == "sys_tick") {
14141414
RegKind = SparcOperand::rk_Special;
14151415
return SP::ASR24;
14161416
}
1417-
if (Name.equals("stick_cmpr") || Name.equals("sys_tick_cmpr")) {
1417+
if (Name == "stick_cmpr" || Name == "sys_tick_cmpr") {
14181418
RegKind = SparcOperand::rk_Special;
14191419
return SP::ASR25;
14201420
}

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ bool X86AsmParser::ParseRoundingModeOp(SMLoc Start, OperandVector &Operands) {
22962296
Operands.push_back(X86Operand::CreateImm(RndModeOp, Start, End));
22972297
return false;
22982298
}
2299-
if(Tok.getIdentifier().equals("sae")){
2299+
if (Tok.getIdentifier() == "sae") {
23002300
Parser.Lex(); // Eat the sae
23012301
if (!getLexer().is(AsmToken::RCurly))
23022302
return Error(Tok.getLoc(), "Expected } at this point");
@@ -2567,7 +2567,7 @@ bool X86AsmParser::ParseIntelMemoryOperandSize(unsigned &Size) {
25672567
.Default(0);
25682568
if (Size) {
25692569
const AsmToken &Tok = Lex(); // Eat operand size (e.g., byte, word).
2570-
if (!(Tok.getString().equals("PTR") || Tok.getString().equals("ptr")))
2570+
if (!(Tok.getString() == "PTR" || Tok.getString() == "ptr"))
25712571
return Error(Tok.getLoc(), "Expected 'PTR' or 'ptr' token!");
25722572
Lex(); // Eat ptr.
25732573
}

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3570,7 +3570,7 @@ bool X86InstrInfo::canMakeTailCallConditional(
35703570
if (Target.isSymbol()) {
35713571
StringRef Symbol(Target.getSymbolName());
35723572
// this is currently only relevant to r11/kernel indirect thunk.
3573-
if (Symbol.equals("__x86_indirect_thunk_r11"))
3573+
if (Symbol == "__x86_indirect_thunk_r11")
35743574
return false;
35753575
}
35763576
}

0 commit comments

Comments
 (0)