[llvm] r301237 - Avoid unnecessary copies in some for loops

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 24 13:01:04 PDT 2017


Author: compnerd
Date: Mon Apr 24 15:01:03 2017
New Revision: 301237

URL: http://llvm.org/viewvc/llvm-project?rev=301237&view=rev
Log:
Avoid unnecessary copies in some for loops

Use constant references rather than `const auto` which will cause the
copy constructor.  These particular cases cause issues for the swift
compiler.

Modified:
    llvm/trunk/include/llvm/Analysis/LoopInfo.h
    llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h
    llvm/trunk/include/llvm/Support/GenericDomTree.h

Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=301237&r1=301236&r2=301237&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Mon Apr 24 15:01:03 2017
@@ -158,7 +158,7 @@ public:
   /// True if terminator in the block can branch to another block that is
   /// outside of the current loop.
   bool isLoopExiting(const BlockT *BB) const {
-    for (const auto Succ : children<const BlockT*>(BB)) {
+    for (const auto &Succ : children<const BlockT*>(BB)) {
       if (!contains(Succ))
         return true;
     }

Modified: llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h?rev=301237&r1=301236&r2=301237&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h Mon Apr 24 15:01:03 2017
@@ -35,7 +35,7 @@ template<class BlockT, class LoopT>
 void LoopBase<BlockT, LoopT>::
 getExitingBlocks(SmallVectorImpl<BlockT *> &ExitingBlocks) const {
   for (const auto BB : blocks())
-    for (const auto Succ : children<BlockT*>(BB))
+    for (const auto &Succ : children<BlockT*>(BB))
       if (!contains(Succ)) {
         // Not in current loop? It must be an exit block.
         ExitingBlocks.push_back(BB);
@@ -61,7 +61,7 @@ template<class BlockT, class LoopT>
 void LoopBase<BlockT, LoopT>::
 getExitBlocks(SmallVectorImpl<BlockT*> &ExitBlocks) const {
   for (const auto BB : blocks())
-    for (const auto Succ : children<BlockT*>(BB))
+    for (const auto &Succ : children<BlockT*>(BB))
       if (!contains(Succ))
         // Not in current loop? It must be an exit block.
         ExitBlocks.push_back(Succ);
@@ -83,7 +83,7 @@ template<class BlockT, class LoopT>
 void LoopBase<BlockT, LoopT>::
 getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const {
   for (const auto BB : blocks())
-    for (const auto Succ : children<BlockT*>(BB))
+    for (const auto &Succ : children<BlockT*>(BB))
       if (!contains(Succ))
         // Not in current loop? It must be an exit block.
         ExitEdges.emplace_back(BB, Succ);

Modified: llvm/trunk/include/llvm/Support/GenericDomTree.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GenericDomTree.h?rev=301237&r1=301236&r2=301237&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GenericDomTree.h (original)
+++ llvm/trunk/include/llvm/Support/GenericDomTree.h Mon Apr 24 15:01:03 2017
@@ -286,13 +286,13 @@ protected:
     NodeRef NewBBSucc = *GraphT::child_begin(NewBB);
 
     std::vector<NodeRef> PredBlocks;
-    for (const auto Pred : children<Inverse<N>>(NewBB))
+    for (const auto &Pred : children<Inverse<N>>(NewBB))
       PredBlocks.push_back(Pred);
 
     assert(!PredBlocks.empty() && "No predblocks?");
 
     bool NewBBDominatesNewBBSucc = true;
-    for (const auto Pred : children<Inverse<N>>(NewBBSucc)) {
+    for (const auto &Pred : children<Inverse<N>>(NewBBSucc)) {
       if (Pred != NewBB && !dominates(NewBBSucc, Pred) &&
           isReachableFromEntry(Pred)) {
         NewBBDominatesNewBBSucc = false;




More information about the llvm-commits mailing list