[llvm-reduce] Use DenseSet instead of std::set (NFC).
authorFlorian Hahn <flo@fhahn.com>
Wed, 10 Nov 2021 13:56:22 +0000 (13:56 +0000)
committerFlorian Hahn <flo@fhahn.com>
Wed, 10 Nov 2021 13:56:22 +0000 (13:56 +0000)
When reducing functions with very large basic blocks (~ almost 1 million
BBs), the majority of time is spent maintaining the order in the std::set
for the basic blocks to keep.

In those cases, DenseSet<> is much more efficient. Use it instead.

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

index 3e38224..024129e 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "ReduceBasicBlocks.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
@@ -25,7 +26,7 @@ using namespace llvm;
 
 /// Replaces BB Terminator with one that only contains Chunk BBs
 static void replaceBranchTerminator(BasicBlock &BB,
-                                    const std::set<BasicBlock *> &BBsToKeep) {
+                                    const DenseSet<BasicBlock *> &BBsToKeep) {
   auto *Term = BB.getTerminator();
   std::vector<BasicBlock *> ChunkSucessors;
   for (auto *Succ : successors(&BB))
@@ -68,7 +69,7 @@ static void replaceBranchTerminator(BasicBlock &BB,
 /// replace with something)
 static void
 removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
-                                 const std::set<BasicBlock *> &BBsToKeep) {
+                                 const DenseSet<BasicBlock *> &BBsToKeep) {
   if (!BBsToKeep.count(SwInst.getDefaultDest())) {
     auto *FnRetTy = SwInst.getParent()->getParent()->getReturnType();
     ReturnInst::Create(SwInst.getContext(),
@@ -99,7 +100,7 @@ static void extractBasicBlocksFromModule(Oracle &O, Module &Program) {
   // 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.
-  std::set<BasicBlock *> BBsToKeep(InitBBsToKeep.begin(), InitBBsToKeep.end());
+  DenseSet<BasicBlock *> BBsToKeep(InitBBsToKeep.begin(), InitBBsToKeep.end());
 
   std::vector<BasicBlock *> BBsToDelete;
   for (auto &F : Program)