[llvm] [InstrProf] Adding utility weights to BalancedPartitioning (PR #72717)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 11:56:56 PST 2023
================
@@ -167,37 +176,38 @@ void BalancedPartitioning::runIterations(const FunctionNodeRange Nodes,
unsigned RightBucket,
std::mt19937 &RNG) const {
unsigned NumNodes = std::distance(Nodes.begin(), Nodes.end());
- DenseMap<BPFunctionNode::UtilityNodeT, unsigned> UtilityNodeDegree;
+ DenseMap<uint32_t, unsigned> UtilityNodeDegree;
for (auto &N : Nodes)
for (auto &UN : N.UtilityNodes)
- ++UtilityNodeDegree[UN];
+ ++UtilityNodeDegree[UN.id];
// Remove utility nodes if they have just one edge or are connected to all
// functions
for (auto &N : Nodes)
llvm::erase_if(N.UtilityNodes, [&](auto &UN) {
- return UtilityNodeDegree[UN] <= 1 || UtilityNodeDegree[UN] >= NumNodes;
+ return UtilityNodeDegree[UN.id] <= 1 ||
+ UtilityNodeDegree[UN.id] >= NumNodes;
});
// Renumber utility nodes so they can be used to index into Signatures
- DenseMap<BPFunctionNode::UtilityNodeT, unsigned> UtilityNodeIndex;
+ DenseMap<uint32_t, unsigned> UtilityNodeIndex;
for (auto &N : Nodes)
for (auto &UN : N.UtilityNodes)
- if (!UtilityNodeIndex.count(UN))
- UtilityNodeIndex[UN] = UtilityNodeIndex.size();
+ if (!UtilityNodeIndex.count(UN.id))
+ UtilityNodeIndex[UN.id] = UtilityNodeIndex.size();
for (auto &N : Nodes)
for (auto &UN : N.UtilityNodes)
- UN = UtilityNodeIndex[UN];
+ UN.id = UtilityNodeIndex[UN.id];
// Initialize signatures
SignaturesT Signatures(/*Size=*/UtilityNodeIndex.size());
for (auto &N : Nodes) {
for (auto &UN : N.UtilityNodes) {
- assert(UN < Signatures.size());
- if (N.Bucket == LeftBucket) {
- Signatures[UN].LeftCount++;
- } else {
- Signatures[UN].RightCount++;
- }
+ assert(UN.id < Signatures.size());
+ if (N.Bucket == LeftBucket)
+ Signatures[UN.id].LeftCount++;
+ else
+ Signatures[UN.id].RightCount++;
+ Signatures[UN.id].Weight = UN.weight;
----------------
spupyrev wrote:
All utility nodes with the same id must have the same weight -- we just store the weight together with the utility.
I re-wrote the code, please see if the new version makes more sense.
https://github.com/llvm/llvm-project/pull/72717
More information about the llvm-commits
mailing list