From: Saleem Abdulrasool Date: Mon, 24 Apr 2017 20:01:03 +0000 (+0000) Subject: Avoid unnecessary copies in some for loops X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=74d2cb54e4d2d008fb0428510924ba7545a1c912;p=llvm 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301237 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 2fad1737d1c..096df1e421a 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -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(BB)) { + for (const auto &Succ : children(BB)) { if (!contains(Succ)) return true; } diff --git a/include/llvm/Analysis/LoopInfoImpl.h b/include/llvm/Analysis/LoopInfoImpl.h index 6dc0422ce0e..66c9f68afc6 100644 --- a/include/llvm/Analysis/LoopInfoImpl.h +++ b/include/llvm/Analysis/LoopInfoImpl.h @@ -35,7 +35,7 @@ template void LoopBase:: getExitingBlocks(SmallVectorImpl &ExitingBlocks) const { for (const auto BB : blocks()) - for (const auto Succ : children(BB)) + for (const auto &Succ : children(BB)) if (!contains(Succ)) { // Not in current loop? It must be an exit block. ExitingBlocks.push_back(BB); @@ -61,7 +61,7 @@ template void LoopBase:: getExitBlocks(SmallVectorImpl &ExitBlocks) const { for (const auto BB : blocks()) - for (const auto Succ : children(BB)) + for (const auto &Succ : children(BB)) if (!contains(Succ)) // Not in current loop? It must be an exit block. ExitBlocks.push_back(Succ); @@ -83,7 +83,7 @@ template void LoopBase:: getExitEdges(SmallVectorImpl &ExitEdges) const { for (const auto BB : blocks()) - for (const auto Succ : children(BB)) + for (const auto &Succ : children(BB)) if (!contains(Succ)) // Not in current loop? It must be an exit block. ExitEdges.emplace_back(BB, Succ); diff --git a/include/llvm/Support/GenericDomTree.h b/include/llvm/Support/GenericDomTree.h index eb7c27d2ffa..851ff7d8040 100644 --- a/include/llvm/Support/GenericDomTree.h +++ b/include/llvm/Support/GenericDomTree.h @@ -286,13 +286,13 @@ protected: NodeRef NewBBSucc = *GraphT::child_begin(NewBB); std::vector PredBlocks; - for (const auto Pred : children>(NewBB)) + for (const auto &Pred : children>(NewBB)) PredBlocks.push_back(Pred); assert(!PredBlocks.empty() && "No predblocks?"); bool NewBBDominatesNewBBSucc = true; - for (const auto Pred : children>(NewBBSucc)) { + for (const auto &Pred : children>(NewBBSucc)) { if (Pred != NewBB && !dominates(NewBBSucc, Pred) && isReachableFromEntry(Pred)) { NewBBDominatesNewBBSucc = false;