Skip to content

[IR] Use StringRef::operator== instead of StringRef::equals (NFC) #90550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ struct StrBoolAttr {
static bool isSet(const Function &Fn,
StringRef Kind) {
auto A = Fn.getFnAttribute(Kind);
return A.getValueAsString().equals("true");
return A.getValueAsString() == "true";
}

static void set(Function &Fn,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
}
}

if (F->arg_size() == 2 && Name.equals("coro.end")) {
if (F->arg_size() == 2 && Name == "coro.end") {
rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::coro_end);
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
if (MDNode *MDIrrLoopHeader =
TI->getMetadata(LLVMContext::MD_irr_loop)) {
MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
if (MDName->getString().equals("loop_header_weight")) {
if (MDName->getString() == "loop_header_weight") {
auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
return std::optional<uint64_t>(CI->getValue().getZExtValue());
}
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/IR/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,8 +1847,8 @@ bool Function::hasAddressTaken(const User **PutOffender,
if (llvm::all_of(FUU->users(), [](const User *U) {
if (const auto *GV = dyn_cast<GlobalVariable>(U))
return GV->hasName() &&
(GV->getName().equals("llvm.compiler.used") ||
GV->getName().equals("llvm.used"));
(GV->getName() == "llvm.compiler.used" ||
GV->getName() == "llvm.used");
return false;
}))
continue;
Expand Down Expand Up @@ -1993,7 +1993,7 @@ std::optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {
MDNode *MD = getMetadata(LLVMContext::MD_prof);
if (MD && MD->getOperand(0))
if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) {
if (MDS->getString().equals("function_entry_count")) {
if (MDS->getString() == "function_entry_count") {
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
uint64_t Count = CI->getValue().getZExtValue();
// A value of -1 is used for SamplePGO when there were no samples.
Expand All @@ -2002,7 +2002,7 @@ std::optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {
return std::nullopt;
return ProfileCount(Count, PCT_Real);
} else if (AllowSynthetic &&
MDS->getString().equals("synthetic_function_entry_count")) {
MDS->getString() == "synthetic_function_entry_count") {
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
uint64_t Count = CI->getValue().getZExtValue();
return ProfileCount(Count, PCT_Synthetic);
Expand All @@ -2015,7 +2015,7 @@ DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {
DenseSet<GlobalValue::GUID> R;
if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
if (MDS->getString().equals("function_entry_count"))
if (MDS->getString() == "function_entry_count")
for (unsigned i = 2; i < MD->getNumOperands(); i++)
R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i))
->getValue()
Expand All @@ -2031,9 +2031,8 @@ void Function::setSectionPrefix(StringRef Prefix) {

std::optional<StringRef> Function::getSectionPrefix() const {
if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
assert(cast<MDString>(MD->getOperand(0))
->getString()
.equals("function_section_prefix") &&
assert(cast<MDString>(MD->getOperand(0))->getString() ==
"function_section_prefix" &&
"Metadata not match");
return cast<MDString>(MD->getOperand(1))->getString();
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/IR/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,7 @@ MDNode *MDNode::mergeDirectCallProfMetadata(MDNode *A, MDNode *B,
"first operand should be a non-null MDString");
StringRef AProfName = AMDS->getString();
StringRef BProfName = BMDS->getString();
if (AProfName.equals("branch_weights") &&
BProfName.equals("branch_weights")) {
if (AProfName == "branch_weights" && BProfName == "branch_weights") {
ConstantInt *AInstrWeight =
mdconst::dyn_extract<ConstantInt>(A->getOperand(1));
ConstantInt *BInstrWeight =
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/IR/ProfDataUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool isTargetMD(const MDNode *ProfData, const char *Name, unsigned MinOps) {
if (!ProfDataName)
return false;

return ProfDataName->getString().equals(Name);
return ProfDataName->getString() == Name;
}

} // namespace
Expand Down Expand Up @@ -161,7 +161,7 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
if (!ProfDataName)
return false;

if (ProfDataName->getString().equals("branch_weights")) {
if (ProfDataName->getString() == "branch_weights") {
for (unsigned Idx = 1; Idx < ProfileData->getNumOperands(); Idx++) {
auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx));
assert(V && "Malformed branch_weight in MD_prof node");
Expand All @@ -170,8 +170,7 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
return true;
}

if (ProfDataName->getString().equals("VP") &&
ProfileData->getNumOperands() > 3) {
if (ProfDataName->getString() == "VP" && ProfileData->getNumOperands() > 3) {
TotalVal = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(2))
->getValue()
.getZExtValue();
Expand All @@ -197,8 +196,8 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
return;

auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(0));
if (!ProfDataName || (!ProfDataName->getString().equals("branch_weights") &&
!ProfDataName->getString().equals("VP")))
if (!ProfDataName || (ProfDataName->getString() != "branch_weights" &&
ProfDataName->getString() != "VP"))
return;

LLVMContext &C = I.getContext();
Expand All @@ -207,7 +206,7 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
SmallVector<Metadata *, 3> Vals;
Vals.push_back(ProfileData->getOperand(0));
APInt APS(128, S), APT(128, T);
if (ProfDataName->getString().equals("branch_weights") &&
if (ProfDataName->getString() == "branch_weights" &&
ProfileData->getNumOperands() > 0) {
// Using APInt::div may be expensive, but most cases should fit 64 bits.
APInt Val(128, mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(1))
Expand All @@ -216,7 +215,7 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
Val *= APS;
Vals.push_back(MDB.createConstant(ConstantInt::get(
Type::getInt32Ty(C), Val.udiv(APT).getLimitedValue(UINT32_MAX))));
} else if (ProfDataName->getString().equals("VP"))
} else if (ProfDataName->getString() == "VP")
for (unsigned i = 1; i < ProfileData->getNumOperands(); i += 2) {
// The first value is the key of the value profile, which will not change.
Vals.push_back(ProfileData->getOperand(i));
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/IR/ProfileSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static ConstantAsMetadata *getValMD(MDTuple *MD, const char *Key) {
ConstantAsMetadata *ValMD = dyn_cast<ConstantAsMetadata>(MD->getOperand(1));
if (!KeyMD || !ValMD)
return nullptr;
if (!KeyMD->getString().equals(Key))
if (KeyMD->getString() != Key)
return nullptr;
return ValMD;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ static bool isKeyValuePair(MDTuple *MD, const char *Key, const char *Val) {
MDString *ValMD = dyn_cast<MDString>(MD->getOperand(1));
if (!KeyMD || !ValMD)
return false;
if (!KeyMD->getString().equals(Key) || !ValMD->getString().equals(Val))
if (KeyMD->getString() != Key || ValMD->getString() != Val)
return false;
return true;
}
Expand All @@ -150,7 +150,7 @@ static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary) {
if (!MD || MD->getNumOperands() != 2)
return false;
MDString *KeyMD = dyn_cast<MDString>(MD->getOperand(0));
if (!KeyMD || !KeyMD->getString().equals("DetailedSummary"))
if (!KeyMD || KeyMD->getString() != "DetailedSummary")
return false;
MDTuple *EntriesMD = dyn_cast<MDTuple>(MD->getOperand(1));
if (!EntriesMD)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ struct TargetTypeInfo {
static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
LLVMContext &C = Ty->getContext();
StringRef Name = Ty->getName();
if (Name.equals("spirv.Image"))
if (Name == "spirv.Image")
return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal);
if (Name.starts_with("spirv."))
return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2379,8 +2379,8 @@ void Verifier::verifyFunctionMetadata(
"expected string with name of the !prof annotation", MD);
MDString *MDS = cast<MDString>(MD->getOperand(0));
StringRef ProfName = MDS->getString();
Check(ProfName.equals("function_entry_count") ||
ProfName.equals("synthetic_function_entry_count"),
Check(ProfName == "function_entry_count" ||
ProfName == "synthetic_function_entry_count",
"first operand should be 'function_entry_count'"
" or 'synthetic_function_entry_count'",
MD);
Expand Down Expand Up @@ -4785,7 +4785,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
StringRef ProfName = MDS->getString();

// Check consistency of !prof branch_weights metadata.
if (ProfName.equals("branch_weights")) {
if (ProfName == "branch_weights") {
if (isa<InvokeInst>(&I)) {
Check(MD->getNumOperands() == 2 || MD->getNumOperands() == 3,
"Wrong number of InvokeInst branch_weights operands", MD);
Expand Down