Skip to content

Commit 38611f4

Browse files
Xin TongXin Tong
authored andcommitted
[RLE-DSE] Use SmallDenseMap instead of DenseMap in DSE to save memory allocations.
Many, if not most functions, do not have more than 64 BasicBlocks (BBState) Existing tests ensure correctness.
1 parent 9d41905 commit 38611f4

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/SILPasses/Scalar/DeadStoreElimination.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class DSEContext {
278278
llvm::BumpPtrAllocator BPA;
279279

280280
/// Map every basic block to its location state.
281-
llvm::DenseMap<SILBasicBlock *, BBState *> BBToLocState;
281+
llvm::SmallDenseMap<SILBasicBlock *, BBState, 4> BBToLocState;
282282

283283
/// Keeps the actual BBStates.
284284
std::vector<BBState> BBStates;
@@ -295,7 +295,7 @@ class DSEContext {
295295
MemLocationIndexMap LocToBitIndex;
296296

297297
/// Return the BBState for the basic block this basic block belongs to.
298-
BBState *getBBLocState(SILBasicBlock *B) { return BBToLocState[B]; }
298+
BBState *getBBLocState(SILBasicBlock *B) { return &BBToLocState[B]; }
299299

300300
/// Return the BBState for the basic block this instruction belongs to.
301301
BBState *getBBLocState(SILInstruction *I) {
@@ -854,13 +854,8 @@ void DSEContext::run() {
854854
// than 64 basic blocks. Therefore, allocate the BBState in a vector and use
855855
// pointer in BBToLocState to access them.
856856
for (auto &B : *F) {
857-
BBStates.push_back(BBState(&B));
858-
BBStates.back().init(MemLocationVault.size());
859-
}
860-
861-
// Initialize the BBToLocState mapping.
862-
for (auto &S : BBStates) {
863-
BBToLocState[S.getBB()] = &S;
857+
BBToLocState[&B] = BBState(&B);
858+
BBToLocState[&B].init(MemLocationVault.size());
864859
}
865860

866861
// Generate the genset and killset for each basic block.

0 commit comments

Comments
 (0)