Skip to content

Commit

Permalink
Avoid unnecessary copies in some for loops
Browse files Browse the repository at this point in the history
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
  • Loading branch information
compnerd committed Apr 24, 2017
1 parent f5d6c7c commit 74d2cb5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class LoopBase {
/// 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;
}
Expand Down
6 changes: 3 additions & 3 deletions include/llvm/Analysis/LoopInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/Support/GenericDomTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> {
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;
Expand Down

0 comments on commit 74d2cb5

Please sign in to comment.