[llvm] r309907 - Fix the bug when SampleProfileWriter writes out number of callsites.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 17:09:18 PDT 2017


Author: dehao
Date: Wed Aug  2 17:09:18 2017
New Revision: 309907

URL: http://llvm.org/viewvc/llvm-project?rev=309907&view=rev
Log:
Fix the bug when SampleProfileWriter writes out number of callsites.

Summary: As we support multiple callsites for the same location, we need to traverse all locations to get the number of callsites.

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: sanjoy, llvm-commits

Differential Revision: https://reviews.llvm.org/D36246

Modified:
    llvm/trunk/lib/ProfileData/SampleProfWriter.cpp
    llvm/trunk/test/tools/llvm-profdata/Inputs/sample-profile.proftext

Modified: llvm/trunk/lib/ProfileData/SampleProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfWriter.cpp?rev=309907&r1=309906&r2=309907&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfWriter.cpp Wed Aug  2 17:09:18 2017
@@ -222,7 +222,10 @@ std::error_code SampleProfileWriterBinar
   }
 
   // Recursively emit all the callsite samples.
-  encodeULEB128(S.getCallsiteSamples().size(), OS);
+  uint64_t NumCallsites = 0;
+  for (const auto &J : S.getCallsiteSamples())
+    NumCallsites += J.second.size();
+  encodeULEB128(NumCallsites, OS);
   for (const auto &J : S.getCallsiteSamples())
     for (const auto &FS : J.second) {
       LineLocation Loc = J.first;

Modified: llvm/trunk/test/tools/llvm-profdata/Inputs/sample-profile.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/sample-profile.proftext?rev=309907&r1=309906&r2=309907&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/sample-profile.proftext (original)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/sample-profile.proftext Wed Aug  2 17:09:18 2017
@@ -10,3 +10,7 @@ main:184019:0
  6: 2080
  7: 534
  9: 2064 _Z3bari:1471 _Z3fooi:631
+ 10: inline1:1000
+  1: 1000
+ 10: inline2:2000
+  1: 2000




More information about the llvm-commits mailing list