[PATCH] D83852: [llvm-profdata] Implement llvm-profdata overlap for sample profiles

Wei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 21:58:27 PDT 2020


weihe added inline comments.


================
Comment at: llvm/tools/llvm-profdata/llvm-profdata.cpp:966-967
+  ///    function A, given BS(i) returned by computeBlockSimilarity(), compute
+  ///    FIS(A) = 2.0 - sum_i(1.0 - BS(i)), ranging in [0.0f to 2.0f] with 0.0
+  ///    meaning no overlap.
+  double computeSampleFunctionInternalOverlap(
----------------
wmi wrote:
> Can we make the similarity within range 0~1 to be consistent with  Block and profile similarity? It is more natural to reason the similarity with range 0~1.
Thank you for the suggestion! I have changed the function `computeSampleFunctionInternalOverlap()` to return a double in range 0~1.


================
Comment at: llvm/tools/llvm-profdata/llvm-profdata.cpp:1068-1074
+  auto BaseSample = BaseFunc.getBodySamples().cbegin();
+  auto TestSample = TestFunc.getBodySamples().cbegin();
+  auto BaseSampleEnd = BaseFunc.getBodySamples().cend();
+  auto TestSampleEnd = TestFunc.getBodySamples().cend();
+  uint64_t BaseSampleValue = 0;
+  uint64_t TestSampleValue = 0;
+  while (BaseSample != BaseSampleEnd || TestSample != TestSampleEnd) {
----------------
wmi wrote:
> Seemly a lot of complexity of the function comes from lock step iteration of the maps from two profiles at the same time. Could you extract the lock step iteration logic into a separate class? This way we don't have to deal with the logic multiple times in iterating BodySampleMap, CallsiteSamplesMap and FunctionSamplesMap.
I have extracted the logic of lock step iteration to class `MatchStep`. This is a great suggestion. Thank you very much!


================
Comment at: llvm/tools/llvm-profdata/llvm-profdata.cpp:1093-1098
+      FuncOverlap.UnionSample += std::max(BaseSampleValue, TestSampleValue);
+      FuncOverlap.OverlapSample += std::min(BaseSampleValue, TestSampleValue);
+      ++FuncOverlap.OverlapCount;
+      Difference += 1.0 - computeBlockSimilarity(BaseSampleValue,
+                                                 TestSampleValue, FuncOverlap);
+      updateHotBlockOverlap(BaseSampleValue, TestSampleValue, 1);
----------------
wmi wrote:
> updateForUnmatchedBlock is a special case of the block above. We may be able to share the code.
Thank you for the suggestion! I combined this code with `updateForUnmatchedBlock()` into a new function `updateOverlapStatsForFunction()`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83852/new/

https://reviews.llvm.org/D83852



More information about the llvm-commits mailing list