[llvm] r237224 - Change a loop in LoopInfo to foreach. NFC

David Blaikie dblaikie at gmail.com
Wed May 13 10:51:17 PDT 2015


On Tue, May 12, 2015 at 6:12 PM, Pete Cooper <peter_cooper at apple.com> wrote:

> Author: pete
> Date: Tue May 12 20:12:09 2015
> New Revision: 237224
>
> URL: http://llvm.org/viewvc/llvm-project?rev=237224&view=rev
> Log:
> Change a loop in LoopInfo to foreach.  NFC
>
> Modified:
>     llvm/trunk/lib/Analysis/LoopInfo.cpp
>
> Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=237224&r1=237223&r2=237224&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)
> +++ llvm/trunk/lib/Analysis/LoopInfo.cpp Tue May 12 20:12:09 2015
> @@ -65,8 +65,8 @@ 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 (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
> -    if (!isLoopInvariant(I->getOperand(i)))
> +  for (auto &Op : I->operands())
> +    if (!isLoopInvariant(Op))
>        return false;
>

Could be written as:

  return std::all_of(I->operands().begin(), I->operands().end(), [&](Value
*V) { return isLoopInvariant(V); );

If you like. (but the range-based-ness does make that a bit inconvenient,
though std::all_of adds a little readability improvement, I think - at some
point we'll just write range-based versions of algorithms like this so we
don't have to pass begin/end everywhere)


>
>    return true;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150513/cf4e91b6/attachment.html>


More information about the llvm-commits mailing list