IRCE: Demote template to ArrayRef and SmallVector to array.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 6 Feb 2015 14:43:49 +0000 (14:43 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 6 Feb 2015 14:43:49 +0000 (14:43 +0000)
NFC.

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

lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

index 327d4fea25da4c1009e5e625773304ba6ac1deeb..e9b5f7023c3a58c833b3e6e8935b09293d5117a1 100644 (file)
@@ -569,10 +569,8 @@ class LoopConstrainer {
   // Even though we do not preserve any passes at this time, we at least need to
   // keep the parent loop structure consistent.  The `LPPassManager' seems to
   // verify this after running a loop pass.  This function adds the list of
-  // blocks denoted by the iterator range [BlocksBegin, BlocksEnd) to this loops
-  // parent loop if required.
-  template<typename IteratorTy>
-  void addToParentLoopIfNeeded(IteratorTy BlocksBegin, IteratorTy BlocksEnd);
+  // blocks denoted by BBs to this loops parent loop if required.
+  void addToParentLoopIfNeeded(ArrayRef<BasicBlock *> BBs);
 
   // Some global state.
   Function &F;
@@ -1009,15 +1007,13 @@ LoopConstrainer::createPreheader(const LoopConstrainer::LoopStructure &LS,
   return Preheader;
 }
 
-template<typename IteratorTy>
-void LoopConstrainer::addToParentLoopIfNeeded(IteratorTy Begin,
-                                              IteratorTy End) {
+void LoopConstrainer::addToParentLoopIfNeeded(ArrayRef<BasicBlock *> BBs) {
   Loop *ParentLoop = OriginalLoop.getParentLoop();
   if (!ParentLoop)
     return;
 
-  for (; Begin != End; Begin++)
-    ParentLoop->addBasicBlockToLoop(*Begin, OriginalLoopInfo);
+  for (BasicBlock *BB : BBs)
+    ParentLoop->addBasicBlockToLoop(BB, OriginalLoopInfo);
 }
 
 bool LoopConstrainer::run() {
@@ -1082,27 +1078,20 @@ bool LoopConstrainer::run() {
                                  PostLoopRRI);
   }
 
-  SmallVector<BasicBlock *, 6> NewBlocks;
-  NewBlocks.push_back(PostLoopPreheader);
-  NewBlocks.push_back(PreLoopRRI.PseudoExit);
-  NewBlocks.push_back(PreLoopRRI.ExitSelector);
-  NewBlocks.push_back(PostLoopRRI.PseudoExit);
-  NewBlocks.push_back(PostLoopRRI.ExitSelector);
-  if (MainLoopPreheader != Preheader)
-    NewBlocks.push_back(MainLoopPreheader);
+  BasicBlock *NewMainLoopPreheader =
+      MainLoopPreheader != Preheader ? MainLoopPreheader : nullptr;
+  BasicBlock *NewBlocks[] = {PostLoopPreheader,        PreLoopRRI.PseudoExit,
+                             PreLoopRRI.ExitSelector,  PostLoopRRI.PseudoExit,
+                             PostLoopRRI.ExitSelector, NewMainLoopPreheader};
 
   // Some of the above may be nullptr, filter them out before passing to
   // addToParentLoopIfNeeded.
-  auto NewBlocksEnd = std::remove(NewBlocks.begin(), NewBlocks.end(), nullptr);
+  auto NewBlocksEnd =
+      std::remove(std::begin(NewBlocks), std::end(NewBlocks), nullptr);
 
-  typedef SmallVector<BasicBlock *, 6>::iterator SmallVectItTy;
-  typedef std::vector<BasicBlock *>::iterator StdVectItTy;
-
-  addToParentLoopIfNeeded<SmallVectItTy>(NewBlocks.begin(), NewBlocksEnd);
-  addToParentLoopIfNeeded<StdVectItTy>(PreLoop.Blocks.begin(),
-                                       PreLoop.Blocks.end());
-  addToParentLoopIfNeeded<StdVectItTy>(PostLoop.Blocks.begin(),
-                                       PostLoop.Blocks.end());
+  addToParentLoopIfNeeded(makeArrayRef(std::begin(NewBlocks), NewBlocksEnd));
+  addToParentLoopIfNeeded(PreLoop.Blocks);
+  addToParentLoopIfNeeded(PostLoop.Blocks);
 
   return true;
 }