[llvm] r237301 - Add llvm::all_of which wraps std::all_of.
Pete Cooper
peter_cooper at apple.com
Wed May 13 15:19:13 PDT 2015
Author: pete
Date: Wed May 13 17:19:13 2015
New Revision: 237301
URL: http://llvm.org/viewvc/llvm-project?rev=237301&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/ADT/STLExtras.h
llvm/trunk/lib/Analysis/LoopInfo.cpp
Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=237301&r1=237300&r2=237301&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/STLExtras.h Wed May 13 17:19:13 2015
@@ -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>
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=237301&r1=237300&r2=237301&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Wed May 13 17:19:13 2015
@@ -65,11 +65,7 @@ bool Loop::isLoopInvariant(const Value *
/// 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
More information about the llvm-commits
mailing list