[llvm-reduce] Remove unnecessary loop.
authorFlorian Hahn <flo@fhahn.com>
Sat, 13 Nov 2021 20:05:58 +0000 (20:05 +0000)
committerFlorian Hahn <flo@fhahn.com>
Sun, 14 Nov 2021 21:03:21 +0000 (21:03 +0000)
After cd8aa234fdd2, there's no need to collect a vector of basic blocks
to keep first. Remove the first loop.

llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp

index 59d0cd9..c76322b 100644 (file)
@@ -90,28 +90,21 @@ removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
 /// Removes out-of-chunk arguments from functions, and modifies their calls
 /// accordingly. It also removes allocations of out-of-chunk arguments.
 static void extractBasicBlocksFromModule(Oracle &O, Module &Program) {
-  std::vector<BasicBlock *> InitBBsToKeep;
+  DenseSet<BasicBlock *> BBsToKeep;
 
-  for (auto &F : Program)
-    for (auto &BB : F)
-      if (O.shouldKeep())
-        InitBBsToKeep.push_back(&BB);
-
-  // We create a vector first, then convert it to a set, so that we don't have
-  // to pay the cost of rebalancing the set frequently if the order we insert
-  // the elements doesn't match the order they should appear inside the set.
-  DenseSet<BasicBlock *> BBsToKeep(InitBBsToKeep.begin(), InitBBsToKeep.end());
-
-  std::vector<BasicBlock *> BBsToDelete;
-  for (auto &F : Program)
+  SmallVector<BasicBlock *> BBsToDelete;
+  for (auto &F : Program) {
     for (auto &BB : F) {
-      if (!BBsToKeep.count(&BB)) {
+      if (O.shouldKeep())
+        BBsToKeep.insert(&BB);
+      else {
         BBsToDelete.push_back(&BB);
         // Remove out-of-chunk BB from successor phi nodes
         for (auto *Succ : successors(&BB))
           Succ->removePredecessor(&BB);
       }
     }
+  }
 
   // Replace terminators that reference out-of-chunk BBs
   for (auto &F : Program)