[PATCH] D112757: [llvm-reduce] optimize extractFromModule functions
Dwight Guth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 28 14:10:51 PDT 2021
dwightguth created this revision.
dwightguth added a reviewer: aeubanks.
dwightguth requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The extractBasicBlocksFromModule, extractInstrFromModule, and other
similar functions previously performed very poorly when the number of
such elements in the program to reduce was very high. Previously, we
were creating the set which caches elements to keep by looping through
all elements in the module and adding them to the set. However, since
std::set is an ordered set, this introduces a massive amount of
rebalancing if the order of elements in the program and the order of
their pointers in memory are not the same.
The solution is straightforward: first put all the elements to be kept
in a vector, then use the constructor for std::set which takes a pair of
iterators over a collection. This constructor is optimized to avoid
doing unnecessary work when initializing large sets.
Also in this change, we pass BBsToKeep set to functions
replaceBranchTerminator and removeUninterestingBBsFromSwitch as a const
reference rather than passing it by value. This ought to prevent the
need to copy the collection each time these functions are called, which
is expensive if the collection is large.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112757
Files:
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112757.383163.patch
Type: text/x-patch
Size: 5596 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211028/4a03e339/attachment.bin>
More information about the llvm-commits
mailing list