]> granicus.if.org Git - llvm/commitdiff
Fix the bug when SampleProfileWriter writes out number of callsites.
authorDehao Chen <dehao@google.com>
Thu, 3 Aug 2017 00:09:18 +0000 (00:09 +0000)
committerDehao Chen <dehao@google.com>
Thu, 3 Aug 2017 00:09:18 +0000 (00:09 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309907 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b45026140c99ae8f2519a57be653f21f12c97838..b9d357ab15ef116bca84974c2c86c74d4113f8dc 100644 (file)
@@ -222,7 +222,10 @@ std::error_code SampleProfileWriterBinary::writeBody(const FunctionSamples &S) {
   }
 
   // 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;
index 54c821243afa46d5f8b0e5515c79553d0dede4a9..e34128faabcfc5a333fd829f0ea4a8eb822b014e 100644 (file)
@@ -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