forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
0609eb1b32
commit
cd8aa234fd
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue