[llvm] r269767 - [LCSSA] Use any_of() to simplify the code. NFCI.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue May 17 10:21:36 PDT 2016


On Tue, May 17, 2016 at 7:24 AM, Davide Italiano via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: davide
> Date: Tue May 17 09:24:41 2016
> New Revision: 269767
>
> URL: http://llvm.org/viewvc/llvm-project?rev=269767&view=rev
> Log:
> [LCSSA] Use any_of() to simplify the code. NFCI.
>
> Modified:
>     llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LCSSA.cpp?rev=269767&r1=269766&r2=269767&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/LCSSA.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/LCSSA.cpp Tue May 17 09:24:41 2016
> @@ -53,10 +53,8 @@ STATISTIC(NumLCSSA, "Number of live out
>  /// Return true if the specified block is in the list.
>  static bool isExitBlock(BasicBlock *BB,
>                          const SmallVectorImpl<BasicBlock *> &ExitBlocks) {
> -  for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
> -    if (ExitBlocks[i] == BB)
> -      return true;
> -  return false;
> +  return std::any_of(ExitBlocks.begin(), ExitBlocks.end(),
> +                     [&](BasicBlock *EB) { return EB == BB; });
>  }
>
>  /// Given an instruction in the loop, check to see if it has any uses
> that are
> @@ -210,11 +208,9 @@ blockDominatesAnExit(BasicBlock *BB,
>                       DominatorTree &DT,
>                       const SmallVectorImpl<BasicBlock *> &ExitBlocks) {
>    DomTreeNode *DomNode = DT.getNode(BB);
> -  for (BasicBlock *ExitBB : ExitBlocks)
> -    if (DT.dominates(DomNode, DT.getNode(ExitBB)))
> -      return true;
> -
> -  return false;
> +  return std::any_of(ExitBlocks.begin(), ExitBlocks.end(), [&](BasicBlock
> *EB) {
>

FWIW, in STLExtras.h we have llvm::any_of that takes a range rather than
begin/end iterators, so it's a bit more compact if you prefer to use that.


> +    return DT.dominates(DomNode, DT.getNode(EB));
> +  });
>  }
>
>  bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160517/5cf30956/attachment.html>


More information about the llvm-commits mailing list