-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
[CodeLayout] CDSortImpl: remove HotChains and remove linear-time erase_value from mergeChains #69276
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Fangrui Song (MaskRay) ChangesAfter mergeChainPairs initializes a priority queue, HotChains is unused Full diff: https://github.com/llvm/llvm-project/pull/69276.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/CodeLayout.cpp b/llvm/lib/Transforms/Utils/CodeLayout.cpp
index d9e302d8b4fa54d..d2f39b0284c6799 100644
--- a/llvm/lib/Transforms/Utils/CodeLayout.cpp
+++ b/llvm/lib/Transforms/Utils/CodeLayout.cpp
@@ -1027,7 +1027,7 @@ class CDSortImpl {
LLVM_DEBUG(dbgs() << "Cache-directed function sorting reduced the number"
<< " of chains from " << NumNodes << " to "
- << HotChains.size() << "\n");
+ << NumHotChains << "\n");
// Collect nodes from all the chains.
return concatChains();
@@ -1085,6 +1085,7 @@ class CDSortImpl {
if (Node.ExecutionCount > 0)
HotChains.push_back(&AllChains.back());
}
+ NumHotChains = HotChains.size();
// Initialize chain edges.
AllEdges.reserve(AllJumps.size());
@@ -1152,6 +1153,7 @@ class CDSortImpl {
MergeGainT BestGain = BestEdge->getMergeGain();
mergeChains(BestSrcChain, BestDstChain, BestGain.mergeOffset(),
BestGain.mergeType());
+ --NumHotChains;
// Insert newly created edges into the queue.
for (const auto &[_, Edge] : BestSrcChain->Edges) {
@@ -1301,9 +1303,6 @@ class CDSortImpl {
// Merge the edges.
Into->mergeEdges(From);
From->clear();
-
- // Remove the chain from the list of active chains.
- llvm::erase_value(HotChains, From);
}
/// Concatenate all chains into the final order.
@@ -1372,6 +1371,7 @@ class CDSortImpl {
/// Active chains. The vector gets updated at runtime when chains are merged.
std::vector<ChainT *> HotChains;
+ size_t NumHotChains = 0;
/// The total number of samples in the graph.
uint64_t TotalSamples{0};
|
@@ -1152,6 +1153,7 @@ class CDSortImpl { | |||
MergeGainT BestGain = BestEdge->getMergeGain(); | |||
mergeChains(BestSrcChain, BestDstChain, BestGain.mergeOffset(), | |||
BestGain.mergeType()); | |||
--NumHotChains; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the list, HotChains, is not used in the algorithm. Can we get rid of it altogether?
Instead of for (ChainT *ChainPred : HotChains) {...
we'd have something like
for (NodeT &Node : AllNodes) {
if (Node.ExecutionCount > 0) {
ChainT *ChainPred = Node.CurChain;
...
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I'll optimize out HotChains
and rename NumHotChains
to NumActiveChains
.
@@ -1027,7 +1027,7 @@ class CDSortImpl { | |||
|
|||
LLVM_DEBUG(dbgs() << "Cache-directed function sorting reduced the number" | |||
<< " of chains from " << NumNodes << " to " | |||
<< HotChains.size() << "\n"); | |||
<< NumHotChains << "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One can move the debug statement to concatChains()
where we have access to the number of remaining chains, SortedChains.size()
. So this variable, NumHotChains, won't be needed
6f0afe8
to
299bbc6
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
…e_value from mergeChains After mergeChainPairs initializes a priority queue, HotChains is unused except a HotChains.size() use in LLVM_DEBUG. Optimize it out.
7ceeecd
to
a0686cf
Compare
Thanks for the review! This is not a bottleneck.
|
Local branch amd-gfx 010f535 Merged main:6eee238975e4 into amd-gfx:4d4ec95d174b Remote branch main beffc82 [CodeLayout] CDSortImpl: remove HotChains and remove linear-time erase_value from mergeChains (llvm#69276)
After mergeChainPairs initializes a priority queue, HotChains is unused
except a HotChains.size() use in LLVM_DEBUG. Optimize it out.