]> granicus.if.org Git - llvm/commitdiff
Avoid unnecessary copies in some for loops
authorSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 24 Apr 2017 20:01:03 +0000 (20:01 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 24 Apr 2017 20:01:03 +0000 (20:01 +0000)
Use constant references rather than `const auto` which will cause the
copy constructor.  These particular cases cause issues for the swift
compiler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301237 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h
include/llvm/Analysis/LoopInfoImpl.h
include/llvm/Support/GenericDomTree.h

index 2fad1737d1c03b76b5cedbfdcd940acf7fb951e7..096df1e421a77edb868a35e18684ade6a7f532db 100644 (file)
@@ -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;
     }
index 6dc0422ce0e94c2a7fa6cea5977d318d8a63b971..66c9f68afc6069d54e21375b8770bf35c4711c2e 100644 (file)
@@ -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);
index eb7c27d2ffa5b0547a37991ddcc676b27e55edbf..851ff7d80403f9abbd7358568e003b5e648677c9 100644 (file)
@@ -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;