[llvm] cd8aa23 - [llvm-reduce] Use DenseSet instead of std::set (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 10 05:56:41 PST 2021
Author: Florian Hahn
Date: 2021-11-10T13:56:22Z
New Revision: cd8aa234fdd2a8436ba0830e0a4f340f90c6f6f3
URL: https://github.com/llvm/llvm-project/commit/cd8aa234fdd2a8436ba0830e0a4f340f90c6f6f3
DIFF: https://github.com/llvm/llvm-project/commit/cd8aa234fdd2a8436ba0830e0a4f340f90c6f6f3.diff
LOG: [llvm-reduce] Use DenseSet instead of std::set (NFC).
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.
Added:
Modified:
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
index 3e3822483a1ba..024129e28d64b 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -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)
More information about the llvm-commits
mailing list