Use llvm::any_of and llvm::none_of (NFC)

This commit is contained in:
Kazu Hirata 2021-10-24 17:35:33 -07:00
parent 19d3bc1e67
commit 4bd46501c3
23 changed files with 54 additions and 74 deletions

View File

@ -78,8 +78,7 @@ class StoredDeclsList {
}
Data.setPointer(NewHead);
assert(llvm::find_if(getLookupResult(), ShouldErase) ==
getLookupResult().end() && "Still exists!");
assert(llvm::none_of(getLookupResult(), ShouldErase) && "Still exists!");
}
void erase(NamedDecl *ND) {

View File

@ -5912,7 +5912,7 @@ static bool isImmediateSinkBlock(const CFGBlock *Blk) {
// at least for now, but once we have better support for exceptions,
// we'd need to carefully handle the case when the throw is being
// immediately caught.
if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
if (llvm::any_of(*Blk, [](const CFGElement &Elm) {
if (Optional<CFGStmt> StmtElm = Elm.getAs<CFGStmt>())
if (isa<CXXThrowExpr>(StmtElm->getStmt()))
return true;

View File

@ -86,11 +86,9 @@ class CapExprSet : public SmallVector<CapabilityExpr, 4> {
public:
/// Push M onto list, but discard duplicates.
void push_back_nodup(const CapabilityExpr &CapE) {
iterator It = std::find_if(begin(), end(),
[=](const CapabilityExpr &CapE2) {
return CapE.equals(CapE2);
});
if (It == end())
if (llvm::none_of(*this, [=](const CapabilityExpr &CapE2) {
return CapE.equals(CapE2);
}))
push_back(CapE);
}
};

View File

@ -313,10 +313,8 @@ static constexpr llvm::StringLiteral ValidFamilyNames[] = {
bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
bool IsFamily = llvm::is_contained(ValidFamilyNames, Name);
bool IsMCU =
llvm::find_if(AVRMcus, [&](const MCUInfo &Info) {
return Info.Name == Name;
}) != std::end(AVRMcus);
bool IsMCU = llvm::any_of(
AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
return IsFamily || IsMCU;
}

View File

@ -83,7 +83,7 @@ CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const CallExpr *E,
/* ParamsToSkip = */ 0);
// We don't know how to emit non-scalar varargs.
if (std::any_of(Args.begin() + 1, Args.end(), [&](const CallArg &A) {
if (llvm::any_of(llvm::drop_begin(Args), [&](const CallArg &A) {
return !A.getRValue(*this).isScalar();
})) {
CGM.ErrorUnsupported(E, "non-scalar arg to printf");

View File

@ -751,13 +751,11 @@ struct CounterCoverageMappingBuilder
/// is already added to \c SourceRegions.
bool isRegionAlreadyAdded(SourceLocation StartLoc, SourceLocation EndLoc,
bool isBranch = false) {
return SourceRegions.rend() !=
std::find_if(SourceRegions.rbegin(), SourceRegions.rend(),
[&](const SourceMappingRegion &Region) {
return Region.getBeginLoc() == StartLoc &&
Region.getEndLoc() == EndLoc &&
Region.isBranch() == isBranch;
});
return llvm::any_of(
llvm::reverse(SourceRegions), [&](const SourceMappingRegion &Region) {
return Region.getBeginLoc() == StartLoc &&
Region.getEndLoc() == EndLoc && Region.isBranch() == isBranch;
});
}
/// Adjust the most recently visited location to \c EndLoc.

View File

@ -4691,10 +4691,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
if (Args.hasArg(options::OPT_fdiscard_value_names) &&
(std::any_of(Inputs.begin(), Inputs.end(),
[](const clang::driver::InputInfo &II) {
return types::isLLVMIR(II.getType());
}))) {
llvm::any_of(Inputs, [](const clang::driver::InputInfo &II) {
return types::isLLVMIR(II.getType());
})) {
D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
}
CmdArgs.push_back("-discard-value-names");

View File

@ -1075,10 +1075,9 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
if (PreviousMustBeValue || Previous->is(tok::r_paren)) {
// If the line contains an '@' sign, the previous token might be an
// annotation, which can precede another identifier/value.
bool HasAt = std::find_if(Line->Tokens.begin(), Line->Tokens.end(),
[](UnwrappedLineNode &LineNode) {
return LineNode.Tok->is(tok::at);
}) != Line->Tokens.end();
bool HasAt = llvm::any_of(Line->Tokens, [](UnwrappedLineNode &LineNode) {
return LineNode.Tok->is(tok::at);
});
if (HasAt)
return;
}

View File

@ -1068,8 +1068,8 @@ bool Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
// Ensure that any ellipsis was in the right place.
SourceLocation EllipsisLoc;
if (std::any_of(std::begin(EllipsisLocs), std::end(EllipsisLocs),
[](SourceLocation Loc) { return Loc.isValid(); })) {
if (llvm::any_of(EllipsisLocs,
[](SourceLocation Loc) { return Loc.isValid(); })) {
// The '...' should appear before the identifier in an init-capture, and
// after the identifier otherwise.
bool InitCapture = InitKind != LambdaCaptureInitKind::NoInit;

View File

@ -1634,7 +1634,7 @@ public:
private:
static bool hasAlwaysUninitializedUse(const UsesVec* vec) {
return std::any_of(vec->begin(), vec->end(), [](const UninitUse &U) {
return llvm::any_of(*vec, [](const UninitUse &U) {
return U.getKind() == UninitUse::Always ||
U.getKind() == UninitUse::AfterCall ||
U.getKind() == UninitUse::AfterDecl;

View File

@ -436,7 +436,7 @@ void Sema::CheckExtraCXXDefaultArguments(Declarator &D) {
}
static bool functionDeclHasDefaultArgument(const FunctionDecl *FD) {
return std::any_of(FD->param_begin(), FD->param_end(), [](ParmVarDecl *P) {
return llvm::any_of(FD->parameters(), [](ParmVarDecl *P) {
return P->hasDefaultArg() && !P->hasInheritedDefaultArg();
});
}

View File

@ -308,8 +308,7 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
}
return declaresSameEntity(Pack.first.get<NamedDecl *>(), LocalPack);
};
if (std::find_if(LSI->LocalPacks.begin(), LSI->LocalPacks.end(),
DeclaresThisPack) != LSI->LocalPacks.end())
if (llvm::any_of(LSI->LocalPacks, DeclaresThisPack))
LambdaParamPackReferences.push_back(Pack);
}
@ -328,8 +327,8 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
bool EnclosingStmtExpr = false;
for (unsigned N = FunctionScopes.size(); N; --N) {
sema::FunctionScopeInfo *Func = FunctionScopes[N-1];
if (std::any_of(
Func->CompoundScopes.begin(), Func->CompoundScopes.end(),
if (llvm::any_of(
Func->CompoundScopes,
[](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; })) {
EnclosingStmtExpr = true;
break;

View File

@ -2676,9 +2676,9 @@ static void emitAttrList(raw_ostream &OS, StringRef Class,
// Determines if an attribute has a Pragma spelling.
static bool AttrHasPragmaSpelling(const Record *R) {
std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(*R);
return llvm::find_if(Spellings, [](const FlattenedSpelling &S) {
return S.variety() == "Pragma";
}) != Spellings.end();
return llvm::any_of(Spellings, [](const FlattenedSpelling &S) {
return S.variety() == "Pragma";
});
}
namespace {

View File

@ -417,8 +417,7 @@ public:
/// Return true if the intrinsic takes an immediate operand.
bool hasImmediate() const {
return std::any_of(Types.begin(), Types.end(),
[](const Type &T) { return T.isImmediate(); });
return llvm::any_of(Types, [](const Type &T) { return T.isImmediate(); });
}
/// Return the parameter index of the immediate operand.
@ -1271,9 +1270,8 @@ void Intrinsic::emitShadowedArgs() {
}
bool Intrinsic::protoHasScalar() const {
return std::any_of(Types.begin(), Types.end(), [](const Type &T) {
return T.isScalar() && !T.isImmediate();
});
return llvm::any_of(
Types, [](const Type &T) { return T.isScalar() && !T.isImmediate(); });
}
void Intrinsic::emitBodyAsBuiltinCall() {

View File

@ -3591,9 +3591,8 @@ void ARMExidxSyntheticSection::writeTo(uint8_t *buf) {
}
bool ARMExidxSyntheticSection::isNeeded() const {
return llvm::find_if(exidxSections, [](InputSection *isec) {
return isec->isLive();
}) != exidxSections.end();
return llvm::any_of(exidxSections,
[](InputSection *isec) { return isec->isLive(); });
}
bool ARMExidxSyntheticSection::classof(const SectionBase *d) {

View File

@ -468,8 +468,7 @@ void Writer::populateTargetFeatures() {
auto isTLS = [](InputChunk *segment) {
return segment->live && segment->isTLS();
};
tlsUsed = tlsUsed ||
std::any_of(file->segments.begin(), file->segments.end(), isTLS);
tlsUsed = tlsUsed || llvm::any_of(file->segments, isTLS);
}
if (inferFeatures)
@ -950,10 +949,9 @@ bool Writer::needsPassiveInitialization(const OutputSegment *segment) {
}
bool Writer::hasPassiveInitializedSegments() {
return std::find_if(segments.begin(), segments.end(),
[this](const OutputSegment *s) {
return this->needsPassiveInitialization(s);
}) != segments.end();
return llvm::any_of(segments, [this](const OutputSegment *s) {
return this->needsPassiveInitialization(s);
});
}
void Writer::createSyntheticInitFunctions() {

View File

@ -47,10 +47,9 @@ public:
private:
void AddArch(const ArchSpec &spec) {
auto iter = std::find_if(
m_archs.begin(), m_archs.end(),
[spec](const ArchSpec &rhs) { return spec.IsExactMatch(rhs); });
if (iter != m_archs.end())
if (llvm::any_of(m_archs, [spec](const ArchSpec &rhs) {
return spec.IsExactMatch(rhs);
}))
return;
if (spec.IsValid())
m_archs.push_back(spec);

View File

@ -23,16 +23,14 @@ using namespace lldb_private;
bool VMRange::ContainsValue(const VMRange::collection &coll,
lldb::addr_t value) {
return llvm::find_if(coll, [&](const VMRange &r) {
return r.Contains(value);
}) != coll.end();
return llvm::any_of(coll,
[&](const VMRange &r) { return r.Contains(value); });
}
bool VMRange::ContainsRange(const VMRange::collection &coll,
const VMRange &range) {
return llvm::find_if(coll, [&](const VMRange &r) {
return r.Contains(range);
}) != coll.end();
return llvm::any_of(coll,
[&](const VMRange &r) { return r.Contains(range); });
}
void VMRange::Dump(llvm::raw_ostream &s, lldb::addr_t offset,

View File

@ -132,9 +132,9 @@ void AssumptionCache::updateAffectedValues(AssumeInst *CI) {
for (auto &AV : Affected) {
auto &AVV = getOrInsertAffectedValues(AV.Assume);
if (std::find_if(AVV.begin(), AVV.end(), [&](ResultElem &Elem) {
if (llvm::none_of(AVV, [&](ResultElem &Elem) {
return Elem.Assume == CI && Elem.Index == AV.Index;
}) == AVV.end())
}))
AVV.push_back({CI, AV.Index});
}
}

View File

@ -521,10 +521,9 @@ void CacheCost::calculateCacheFootprint() {
LLVM_DEBUG(dbgs() << "COMPUTING LOOP CACHE COSTS\n");
for (const Loop *L : Loops) {
assert((std::find_if(LoopCosts.begin(), LoopCosts.end(),
[L](const LoopCacheCostTy &LCC) {
return LCC.first == L;
}) == LoopCosts.end()) &&
assert(llvm::none_of(
LoopCosts,
[L](const LoopCacheCostTy &LCC) { return LCC.first == L; }) &&
"Should not add duplicate element");
CacheCostTy LoopCost = computeLoopCacheCost(*L, RefGroups);
LoopCosts.push_back(std::make_pair(L, LoopCost));

View File

@ -3297,7 +3297,7 @@ static bool checkForMustTailInVarArgFn(bool IsVarArg, const BasicBlock &BB) {
// Walk the block backwards, because tail calls usually only appear at the end
// of a block.
return std::any_of(BB.rbegin(), BB.rend(), [](const Instruction &I) {
return llvm::any_of(llvm::reverse(BB), [](const Instruction &I) {
const auto *CI = dyn_cast<CallInst>(&I);
return CI && CI->isMustTailCall();
});

View File

@ -110,9 +110,8 @@ struct llvm::TimeTraceProfiler {
// templates from within, we only want to add the topmost one. "topmost"
// happens to be the ones that don't have any currently open entries above
// itself.
if (std::find_if(++Stack.rbegin(), Stack.rend(), [&](const Entry &Val) {
return Val.Name == E.Name;
}) == Stack.rend()) {
if (llvm::none_of(llvm::drop_begin(llvm::reverse(Stack)),
[&](const Entry &Val) { return Val.Name == E.Name; })) {
auto &CountAndTotal = CountAndTotalPerName[E.Name];
CountAndTotal.first++;
CountAndTotal.second += Duration;

View File

@ -3252,7 +3252,7 @@ bool HexagonLoopRescheduling::processLoop(LoopCand &C) {
auto LoopInpEq = [G] (const PhiInfo &P) -> bool {
return G.Out.Reg == P.LR.Reg;
};
if (llvm::find_if(Phis, LoopInpEq) == Phis.end())
if (llvm::none_of(Phis, LoopInpEq))
continue;
G.Inp.Reg = Inputs.find_first();