From b1ce35cdfb58d4e93de58445aef744cded16b386 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Tue, 1 Dec 2015 07:49:23 +0000 Subject: [PATCH] Introduce a range version of std::any_of, and use it in SCEV Reviewers: dblaikie, pcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D15063 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254390 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/STLExtras.h | 8 ++++++++ lib/Analysis/ScalarEvolution.cpp | 7 +++---- tools/llvm-pdbdump/LinePrinter.cpp | 9 +++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 1bd3b291e0e..3655a20d883 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -371,6 +371,14 @@ bool all_of(R &&Range, UnaryPredicate &&P) { std::forward(P)); } +/// Provide wrappers to std::any_of which take ranges instead of having to pass +/// begin/end explicitly. +template +bool any_of(R &&Range, UnaryPredicate &&P) { + return std::any_of(Range.begin(), Range.end(), + std::forward(P)); +} + //===----------------------------------------------------------------------===// // Extra additions to //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 23daeb67d65..4c8b6e7de84 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -8403,8 +8403,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, // The only time we can solve this is when we have all constant indices. // Otherwise, we cannot determine the overflow conditions. - if (std::any_of(op_begin(), op_end(), - [](const SCEV *Op) { return !isa(Op);})) + if (any_of(operands(), [](const SCEV *Op) { return !isa(Op); })) return SE.getCouldNotCompute(); // Okay at this point we know that all elements of the chrec are constants and @@ -9694,8 +9693,8 @@ bool SCEVUnionPredicate::implies(const SCEVPredicate *N) const { return false; auto &SCEVPreds = ScevPredsIt->second; - return std::any_of(SCEVPreds.begin(), SCEVPreds.end(), - [N](const SCEVPredicate *I) { return I->implies(N); }); + return any_of(SCEVPreds, + [N](const SCEVPredicate *I) { return I->implies(N); }); } const SCEV *SCEVUnionPredicate::getExpr() const { return nullptr; } diff --git a/tools/llvm-pdbdump/LinePrinter.cpp b/tools/llvm-pdbdump/LinePrinter.cpp index 4f3ee54c769..a43727f02b5 100644 --- a/tools/llvm-pdbdump/LinePrinter.cpp +++ b/tools/llvm-pdbdump/LinePrinter.cpp @@ -11,15 +11,12 @@ #include "llvm-pdbdump.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Regex.h" #include namespace { -template bool any_of_range(T &&R, Pred P) { - return std::any_of(R.begin(), R.end(), P); -} - bool IsItemExcluded(llvm::StringRef Item, std::list &IncludeFilters, std::list &ExcludeFilters) { @@ -30,10 +27,10 @@ bool IsItemExcluded(llvm::StringRef Item, // Include takes priority over exclude. If the user specified include // filters, and none of them include this item, them item is gone. - if (!IncludeFilters.empty() && !any_of_range(IncludeFilters, match_pred)) + if (!IncludeFilters.empty() && !any_of(IncludeFilters, match_pred)) return true; - if (any_of_range(ExcludeFilters, match_pred)) + if (any_of(ExcludeFilters, match_pred)) return true; return false; -- 2.34.1