Skip to content

Commit 1e48795

Browse files
author
spupyrev
committed
more reviews
1 parent 73be288 commit 1e48795

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

llvm/include/llvm/Support/BalancedPartitioning.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ class BPFunctionNode {
6464
UtilityNodeT(uint32_t Id, uint32_t Weight = 1) : Id(Id), Weight(Weight) {}
6565
uint32_t Id;
6666
uint32_t Weight;
67+
68+
// Deduplicate utility nodes for a given function.
69+
// TODO: One may experiment with accumulating the weights of duplicates.
70+
static void sortAndDeduplicate(SmallVector<UtilityNodeT, 4> &UNs) {
71+
llvm::sort(UNs, [](const UtilityNodeT &L, const UtilityNodeT &R) {
72+
return L.Id < R.Id;
73+
});
74+
UNs.erase(std::unique(UNs.begin(), UNs.end(),
75+
[](const UtilityNodeT &L, const UtilityNodeT &R) {
76+
return L.Id == R.Id;
77+
}),
78+
UNs.end());
79+
}
6780
};
6881

6982
/// \param UtilityNodes the set of utility nodes (must be unique'd)

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -905,20 +905,6 @@ void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
905905
ValueSites.emplace_back(VData, VData + N);
906906
}
907907

908-
// Deduplicate utility nodes for a given function.
909-
// TODO: One may experiment with accumulating the weights of duplicates.
910-
void sortAndDeduplicate(SmallVector<BPFunctionNode::UtilityNodeT, 4> &UNs) {
911-
using UtilityNodeT = BPFunctionNode::UtilityNodeT;
912-
llvm::sort(UNs, [](const UtilityNodeT &L, const UtilityNodeT &R) {
913-
return L.Id < R.Id;
914-
});
915-
UNs.erase(std::unique(UNs.begin(), UNs.end(),
916-
[](const UtilityNodeT &L, const UtilityNodeT &R) {
917-
return L.Id == R.Id;
918-
}),
919-
UNs.end());
920-
}
921-
922908
std::vector<BPFunctionNode> TemporalProfTraceTy::createBPFunctionNodes(
923909
ArrayRef<TemporalProfTraceTy> Traces) {
924910
using IDT = BPFunctionNode::IDT;
@@ -954,7 +940,7 @@ std::vector<BPFunctionNode> TemporalProfTraceTy::createBPFunctionNodes(
954940
std::vector<BPFunctionNode> Nodes;
955941
for (auto Id : FunctionIds) {
956942
auto &UNs = FuncGroups[Id];
957-
sortAndDeduplicate(UNs);
943+
UtilityNodeT::sortAndDeduplicate(UNs);
958944
Nodes.emplace_back(Id, UNs);
959945
}
960946
return Nodes;

llvm/lib/Support/BalancedPartitioning.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ void BalancedPartitioning::runIterations(const FunctionNodeRange Nodes,
203203
Signatures[UN.Id].RightCount++;
204204
// Identical utility nodes (having the same UN.Id) have the same weight
205205
// (unless there are hash collisions mapping utilities to the same Id);
206-
// thus, we can get a new weight only when the signature is uninitialized.
207-
if (Signatures[UN.Id].Weight != UN.Weight)
208-
Signatures[UN.Id].Weight = UN.Weight;
206+
// thus, we get a new weight only when the signature is uninitialized.
207+
Signatures[UN.Id].Weight = UN.Weight;
209208
}
210209
}
211210

0 commit comments

Comments
 (0)