Skip to content

Commit

Permalink
[tools, utils] Use StringRef::contains (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Oct 23, 2021
1 parent ec2a252 commit 4e3eebc
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion llvm/tools/llvm-cov/CoverageFilters.cpp
Expand Up @@ -21,7 +21,7 @@ bool NameCoverageFilter::matches(
const coverage::CoverageMapping &,
const coverage::FunctionRecord &Function) const {
StringRef FuncName = Function.Name;
return FuncName.find(Name) != StringRef::npos;
return FuncName.contains(Name);
}

bool NameRegexCoverageFilter::matches(
Expand Down
7 changes: 3 additions & 4 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Expand Up @@ -836,7 +836,7 @@ static void parseInputFilenamesFile(MemoryBuffer *Buffer,
if (SanitizedEntry.startswith("#"))
continue;
// If there's no comma, it's an unweighted profile.
else if (SanitizedEntry.find(',') == StringRef::npos)
else if (!SanitizedEntry.contains(','))
addWeightedInput(WFV, {std::string(SanitizedEntry), 1});
else
addWeightedInput(WFV, parseWeightedFile(SanitizedEntry));
Expand Down Expand Up @@ -2108,9 +2108,8 @@ static int showInstrProfile(const std::string &Filename, bool ShowCounts,
if (FuncIsCS != ShowCS)
continue;
}
bool Show =
ShowAllFunctions || (!ShowFunction.empty() &&
Func.Name.find(ShowFunction) != Func.Name.npos);
bool Show = ShowAllFunctions ||
(!ShowFunction.empty() && Func.Name.contains(ShowFunction));

bool doTextFormatDump = (Show && TextFormat);

Expand Down
6 changes: 3 additions & 3 deletions llvm/tools/llvm-profgen/PerfReader.cpp
Expand Up @@ -449,7 +449,7 @@ bool PerfReaderBase::extractLBRStack(TraceStream &TraceIt,
// Skip the leading instruction pointer.
size_t Index = 0;
uint64_t LeadingAddr;
if (!Records.empty() && Records[0].find('/') == StringRef::npos) {
if (!Records.empty() && !Records[0].contains('/')) {
if (Records[0].getAsInteger(16, LeadingAddr)) {
WarnInvalidLBR(TraceIt);
TraceIt.advance();
Expand Down Expand Up @@ -862,7 +862,7 @@ bool PerfReaderBase::isLBRSample(StringRef Line) {
Line.trim().split(Records, " ", 2, false);
if (Records.size() < 2)
return false;
if (Records[1].startswith("0x") && Records[1].find('/') != StringRef::npos)
if (Records[1].startswith("0x") && Records[1].contains('/'))
return true;
return false;
}
Expand All @@ -877,7 +877,7 @@ bool PerfReaderBase::isMMap2Event(StringRef Line) {

// PERF_RECORD_MMAP2 does not appear at the beginning of the line
// for ` perf script --show-mmap-events -i ...`
return Line.find("PERF_RECORD_MMAP2") != StringRef::npos;
return Line.contains("PERF_RECORD_MMAP2");
}

// The raw hybird sample is like
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-profgen/ProfileGenerator.cpp
Expand Up @@ -403,8 +403,7 @@ void ProfileGenerator::populateBodySamplesForAllFunctions(

static bool isOutlinedFunction(StringRef CalleeName) {
// Check whether it's from hot-cold func split or coro split.
return CalleeName.find(".resume") != StringRef::npos ||
CalleeName.find(".cold") != StringRef::npos;
return CalleeName.contains(".resume") || CalleeName.contains(".cold");
}

StringRef ProfileGeneratorBase::getCalleeNameForOffset(uint64_t TargetOffset) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/AsmMatcherEmitter.cpp
Expand Up @@ -1071,7 +1071,7 @@ bool MatchableInfo::validate(StringRef CommentDelimiter, bool IsAlias) const {
// Remove comments from the asm string. We know that the asmstring only
// has one line.
if (!CommentDelimiter.empty() &&
StringRef(AsmString).find(CommentDelimiter) != StringRef::npos)
StringRef(AsmString).contains(CommentDelimiter))
PrintFatalError(TheDef->getLoc(),
"asmstring for instruction has comment character in it, "
"mark it isCodeGenOnly");
Expand All @@ -1086,7 +1086,7 @@ bool MatchableInfo::validate(StringRef CommentDelimiter, bool IsAlias) const {
std::set<std::string> OperandNames;
for (const AsmOperand &Op : AsmOperands) {
StringRef Tok = Op.Token;
if (Tok[0] == '$' && Tok.find(':') != StringRef::npos)
if (Tok[0] == '$' && Tok.contains(':'))
PrintFatalError(TheDef->getLoc(),
"matchable with operand modifier '" + Tok +
"' not supported by asm matcher. Mark isCodeGenOnly!");
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/TableGen/X86FoldTablesEmitter.cpp
Expand Up @@ -79,13 +79,13 @@ const ManualMapEntry ManualMapSet[] = {

static bool isExplicitAlign(const CodeGenInstruction *Inst) {
return any_of(ExplicitAlign, [Inst](const char *InstStr) {
return Inst->TheDef->getName().find(InstStr) != StringRef::npos;
return Inst->TheDef->getName().contains(InstStr);
});
}

static bool isExplicitUnalign(const CodeGenInstruction *Inst) {
return any_of(ExplicitUnalign, [Inst](const char *InstStr) {
return Inst->TheDef->getName().find(InstStr) != StringRef::npos;
return Inst->TheDef->getName().contains(InstStr);
});
}

Expand Down Expand Up @@ -278,7 +278,7 @@ static inline bool hasMemoryFormat(const Record *Inst) {
}

static inline bool isNOREXRegClass(const Record *Op) {
return Op->getName().find("_NOREX") != StringRef::npos;
return Op->getName().contains("_NOREX");
}

static inline bool isRegisterOperand(const Record *Rec) {
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/TableGen/X86RecognizableInstr.cpp
Expand Up @@ -109,12 +109,12 @@ RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
// FIXME: Is there some better way to check for In64BitMode?
std::vector<Record*> Predicates = Rec->getValueAsListOfDefs("Predicates");
for (unsigned i = 0, e = Predicates.size(); i != e; ++i) {
if (Predicates[i]->getName().find("Not64Bit") != Name.npos ||
Predicates[i]->getName().find("In32Bit") != Name.npos) {
if (Predicates[i]->getName().contains("Not64Bit") ||
Predicates[i]->getName().contains("In32Bit")) {
Is32Bit = true;
break;
}
if (Predicates[i]->getName().find("In64Bit") != Name.npos) {
if (Predicates[i]->getName().contains("In64Bit")) {
Is64Bit = true;
break;
}
Expand Down

0 comments on commit 4e3eebc

Please sign in to comment.