diff options
| author | Pete Cooper <peter_cooper@apple.com> | 2015-05-13 22:19:13 +0000 |
|---|---|---|
| committer | Pete Cooper <peter_cooper@apple.com> | 2015-05-13 22:19:13 +0000 |
| commit | a264dc09336ea163aabbdcb59694f76750f2d46c (patch) | |
| tree | be91ee2b6c6c6b149a2fac9cbb76bee146702ffc /llvm | |
| parent | ab9fd035fdc4a3babfd70f3642758aad2695ad26 (diff) | |
| download | bcm5719-llvm-a264dc09336ea163aabbdcb59694f76750f2d46c.tar.gz bcm5719-llvm-a264dc09336ea163aabbdcb59694f76750f2d46c.zip | |
Add llvm::all_of which wraps std::all_of.
This version doesn't need begin/end but can instead just take a type which has begin/end methods.
Use this to replace an eligible foreach loop in LoopInfo found by David Blaikie in r237224.
Reviewed by David Blaikie.
llvm-svn: 237301
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/ADT/STLExtras.h | 9 | ||||
| -rw-r--r-- | llvm/lib/Analysis/LoopInfo.cpp | 6 |
2 files changed, 10 insertions, 5 deletions
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 921bd820d97..b68345a1dcf 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -18,6 +18,7 @@ #define LLVM_ADT_STLEXTRAS_H #include "llvm/Support/Compiler.h" +#include <algorithm> // for std::all_of #include <cassert> #include <cstddef> // for std::size_t #include <cstdlib> // for qsort @@ -327,6 +328,14 @@ void DeleteContainerSeconds(Container &C) { C.clear(); } +/// Provide wrappers to std::all_of which take ranges instead of having to pass +/// being/end explicitly. +template<typename R, class UnaryPredicate> +bool all_of(R &&Range, UnaryPredicate &&P) { + return std::all_of(Range.begin(), Range.end(), + std::forward<UnaryPredicate>(P)); +} + //===----------------------------------------------------------------------===// // Extra additions to <memory> //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 932b080eb3e..6b6faf8a66c 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -65,11 +65,7 @@ bool Loop::isLoopInvariant(const Value *V) const { /// hasLoopInvariantOperands - Return true if all the operands of the /// specified instruction are loop invariant. bool Loop::hasLoopInvariantOperands(const Instruction *I) const { - for (auto &Op : I->operands()) - if (!isLoopInvariant(Op)) - return false; - - return true; + return all_of(I->operands(), [this](Value *V) { return isLoopInvariant(V); }); } /// makeLoopInvariant - If the given value is an instruciton inside of the |

