Skip to content

Commit d3d2ea6

Browse files
[PartialInlining] Use DenseSet instead of DenseMap (NFC) (#127170)
This patch changes the type of VisitedMap to DenseSet from DenseMap because the value side of the map is always "true". Technically: if (VisitedMap[*SI]) inserts "false" as a value, but the value is immediately overridden with: VisitedMap[*SI] = true; While we are at it, this patch removes the repeated hash lookups around the "if" statement.
1 parent 4b4432f commit d3d2ea6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Diff for: llvm/lib/Transforms/IPO/PartialInlining.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
412412
bool ColdCandidateFound = false;
413413
BasicBlock *CurrEntry = EntryBlock;
414414
std::vector<BasicBlock *> DFS;
415-
DenseMap<BasicBlock *, bool> VisitedMap;
415+
SmallPtrSet<BasicBlock *, 8> VisitedSet;
416416
DFS.push_back(CurrEntry);
417-
VisitedMap[CurrEntry] = true;
417+
VisitedSet.insert(CurrEntry);
418418

419419
// Use Depth First Search on the basic blocks to find CFG edges that are
420420
// considered cold.
@@ -432,9 +432,8 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
432432
BBProfileCount(ThisBB) < MinBlockCounterExecution)
433433
continue;
434434
for (auto SI = succ_begin(ThisBB); SI != succ_end(ThisBB); ++SI) {
435-
if (VisitedMap[*SI])
435+
if (!VisitedSet.insert(*SI).second)
436436
continue;
437-
VisitedMap[*SI] = true;
438437
DFS.push_back(*SI);
439438
// If branch isn't cold, we skip to the next one.
440439
BranchProbability SuccProb = BPI.getEdgeProbability(ThisBB, *SI);
@@ -492,7 +491,7 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
492491
// at inner regions because the outer region may have live-exit
493492
// variables.
494493
for (auto *BB : DominateVector)
495-
VisitedMap[BB] = true;
494+
VisitedSet.insert(BB);
496495

497496
// ReturnBlock here means the block after the outline call
498497
BasicBlock *ReturnBlock = ExitBlock->getSingleSuccessor();

0 commit comments

Comments
 (0)