diff options
author | Fangrui Song <i@maskray.me> | 2024-01-17 10:46:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-17 10:46:34 -0800 |
commit | 0c6dc80531ed332e346934019095ad9518f465f3 (patch) | |
tree | d7da41b03b35f61f44eb42a861a756bd218914f6 /llvm/lib/ProfileData | |
parent | bd5d41a3401f2dc31a82bb04deb0f47fd768a270 (diff) | |
download | llvm-0c6dc80531ed332e346934019095ad9518f465f3.zip llvm-0c6dc80531ed332e346934019095ad9518f465f3.tar.gz llvm-0c6dc80531ed332e346934019095ad9518f465f3.tar.bz2 |
BalancedPartitioning: minor updates (#77568)
When LargestTraceSize is a power of two, createBPFunctionNodes does not
allocate a group ID for Trace[LargestTraceSize-1] (as N is off by 1).
Fix
this and change floor+log2 to Log2_64.
BalancedPartitioning::bisect can use unstable sort because `Nodes`
contains distinct `InputOrderIndex`s.
BalancedPartitioning::runIterations: use one DenseMap and simplify the
node renumbering code.
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 4264da8..2640027 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -921,7 +921,7 @@ std::vector<BPFunctionNode> TemporalProfTraceTy::createBPFunctionNodes( if (Timestamp < Trace.FunctionNameRefs.size()) FunctionIds.insert(Trace.FunctionNameRefs[Timestamp]); - int N = std::ceil(std::log2(LargestTraceSize)); + const int N = Log2_64(LargestTraceSize) + 1; // TODO: We need to use the Trace.Weight field to give more weight to more // important utilities @@ -929,8 +929,8 @@ std::vector<BPFunctionNode> TemporalProfTraceTy::createBPFunctionNodes( for (size_t TraceIdx = 0; TraceIdx < Traces.size(); TraceIdx++) { auto &Trace = Traces[TraceIdx].FunctionNameRefs; for (size_t Timestamp = 0; Timestamp < Trace.size(); Timestamp++) { - for (int I = std::floor(std::log2(Timestamp + 1)); I < N; I++) { - auto &FunctionId = Trace[Timestamp]; + for (int I = Log2_64(Timestamp + 1); I < N; I++) { + auto FunctionId = Trace[Timestamp]; UtilityNodeT GroupId = TraceIdx * N + I; FuncGroups[FunctionId].push_back(GroupId); } @@ -938,7 +938,7 @@ std::vector<BPFunctionNode> TemporalProfTraceTy::createBPFunctionNodes( } std::vector<BPFunctionNode> Nodes; - for (auto &Id : FunctionIds) { + for (auto Id : FunctionIds) { auto &UNs = FuncGroups[Id]; llvm::sort(UNs); UNs.erase(std::unique(UNs.begin(), UNs.end()), UNs.end()); |