From 33bf03ed89750a5ac6583ed4b12e71a8517813f4 Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Wed, 13 May 2015 22:19:13 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237301 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/STLExtras.h | 9 +++++++++ lib/Analysis/LoopInfo.cpp | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 921bd820d97..b68345a1dcf 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -18,6 +18,7 @@ #define LLVM_ADT_STLEXTRAS_H #include "llvm/Support/Compiler.h" +#include // for std::all_of #include #include // for std::size_t #include // 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 +bool all_of(R &&Range, UnaryPredicate &&P) { + return std::all_of(Range.begin(), Range.end(), + std::forward(P)); +} + //===----------------------------------------------------------------------===// // Extra additions to //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index 932b080eb3e..6b6faf8a66c 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/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 -- 2.11.0