-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[PartialInlining] Use DenseSet instead of DenseMap (NFC) #127170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PartialInlining] Use DenseSet instead of DenseMap (NFC) #127170
Conversation
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.
@llvm/pr-subscribers-llvm-transforms Author: Kazu Hirata (kazutakahirata) ChangesThis patch changes the type of VisitedMap to DenseSet from DenseMap Technically: if (VisitedMap[*SI]) inserts "false" as a value, but the value is immediately overridden VisitedMap[*SI] = true; While we are at it, this patch removes the repeated hash lookups Full diff: https://github.com/llvm/llvm-project/pull/127170.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp
index cead7b84c3fc8..ea75b637c1646 100644
--- a/llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -412,9 +412,9 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
bool ColdCandidateFound = false;
BasicBlock *CurrEntry = EntryBlock;
std::vector<BasicBlock *> DFS;
- DenseMap<BasicBlock *, bool> VisitedMap;
+ DenseSet<BasicBlock *> VisitedSet;
DFS.push_back(CurrEntry);
- VisitedMap[CurrEntry] = true;
+ VisitedSet.insert(CurrEntry);
// Use Depth First Search on the basic blocks to find CFG edges that are
// considered cold.
@@ -432,9 +432,8 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
BBProfileCount(ThisBB) < MinBlockCounterExecution)
continue;
for (auto SI = succ_begin(ThisBB); SI != succ_end(ThisBB); ++SI) {
- if (VisitedMap[*SI])
+ if (!VisitedSet.insert(*SI).second)
continue;
- VisitedMap[*SI] = true;
DFS.push_back(*SI);
// If branch isn't cold, we skip to the next one.
BranchProbability SuccProb = BPI.getEdgeProbability(ThisBB, *SI);
@@ -492,7 +491,7 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
// at inner regions because the outer region may have live-exit
// variables.
for (auto *BB : DominateVector)
- VisitedMap[BB] = true;
+ VisitedSet.insert(BB);
// ReturnBlock here means the block after the outline call
BasicBlock *ReturnBlock = ExitBlock->getSingleSuccessor();
|
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.
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.
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.