[llvm] 2f8196d - [llvm-profgen] Fix bug of populating profile symbol list

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 09:59:56 PDT 2021


Author: wlei
Date: 2021-10-29T09:59:12-07:00
New Revision: 2f8196db9206d9a848ed706d5846196d3fc5db63

URL: https://github.com/llvm/llvm-project/commit/2f8196db9206d9a848ed706d5846196d3fc5db63
DIFF: https://github.com/llvm/llvm-project/commit/2f8196db9206d9a848ed706d5846196d3fc5db63.diff

LOG: [llvm-profgen] Fix bug of populating profile symbol list

Previous implementation of populating profile symbol list is wrong, it only included the profiled symbols. Actually it should use all symbols, here this switches to use the symbols from debug info. Also turned the flag off by default.

Reviewed By: wenlei, hoy

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
    llvm/test/tools/llvm-profgen/inline-noprobe2.test
    llvm/tools/llvm-profgen/ProfileGenerator.cpp
    llvm/tools/llvm-profgen/ProfiledBinary.cpp
    llvm/tools/llvm-profgen/ProfiledBinary.h

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
index 991602bd2f85c..c7657ef348a35 100644
--- a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
@@ -11,6 +11,7 @@
 ; CHECK-SYM-LIST: Dump profile symbol list
 ; CHECK-SYM-LIST: bar
 ; CHECK-SYM-LIST: foo
+; CHECK-SYM-LIST: main
 
 ; CHECK:[main:1 @ foo]:225:0
 ; CHECK: 2.1: 14

diff  --git a/llvm/test/tools/llvm-profgen/inline-noprobe2.test b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
index 3fcc1cb5541c2..27019a468a842 100644
--- a/llvm/test/tools/llvm-profgen/inline-noprobe2.test
+++ b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
@@ -5,7 +5,7 @@
 ; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t1 --use-offset=0
 ; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK
 
-; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
+; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t --populate-profile-symbol-list=1
 ; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST
 
 ; CHECK-ARTIFICIAL-BRANCH: 3
@@ -21,6 +21,7 @@
 ; CHECK-SYM-LIST: partition_pivot_first
 ; CHECK-SYM-LIST: partition_pivot_last
 ; CHECK-SYM-LIST: quick_sort
+; CHECK-SYM-LIST: swap
 
 
 ;CHECK-RAW-PROFILE-NOT: 7f7448e889e4

diff  --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index ea0d7a1c29339..88e96348cba4f 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -33,7 +33,7 @@ cl::opt<bool> UseMD5(
              "meaningful for -extbinary)"));
 
 static cl::opt<bool> PopulateProfileSymbolList(
-    "populate-profile-symbol-list", cl::init(true), cl::Hidden,
+    "populate-profile-symbol-list", cl::init(false), cl::Hidden,
     cl::desc("Populate profile symbol list (only meaningful for -extbinary)"));
 
 static cl::opt<int32_t, true> RecursionCompression(
@@ -97,16 +97,8 @@ void ProfileGeneratorBase::write(std::unique_ptr<SampleProfileWriter> Writer,
   // Populate profile symbol list if extended binary format is used.
   ProfileSymbolList SymbolList;
 
-  // Turn it off temporarily for CS profile.
-  if (FunctionSamples::ProfileIsCS &&
-      !PopulateProfileSymbolList.getNumOccurrences())
-    PopulateProfileSymbolList = false;
-
   if (PopulateProfileSymbolList && OutputFormat == SPF_Ext_Binary) {
-    for (const auto &Item : ProfileMap) {
-      auto &Profile = Item.second;
-      SymbolList.add(Profile.getName(), true);
-    }
+    Binary->populateSymbolListFromDWARF(SymbolList);
     Writer->setProfileSymbolList(&SymbolList);
   }
 

diff  --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index e9c18cd4b1fac..43c86106f2a54 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -10,6 +10,7 @@
 #include "ErrorHandling.h"
 #include "ProfileGenerator.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/MC/TargetRegistry.h"
@@ -599,6 +600,12 @@ void ProfiledBinary::loadSymbolsFromDWARF(ObjectFile &Obj) {
   assert(!StartOffset2FuncRangeMap.empty() && "Misssing debug info.");
 }
 
+void ProfiledBinary::populateSymbolListFromDWARF(
+    ProfileSymbolList &SymbolList) {
+  for (auto &I : StartOffset2FuncRangeMap)
+    SymbolList.add(I.second.getFuncName());
+}
+
 void ProfiledBinary::setupSymbolizer() {
   symbolize::LLVMSymbolizer::Options SymbolizerOpts;
   SymbolizerOpts.PrintFunctions =

diff  --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index ba7c70343132c..d6e7ba81fef19 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -382,6 +382,9 @@ class ProfiledBinary {
     return FuncSizeTracker.getFuncSizeForContext(Context);
   }
 
+  // Load the symbols from debug table and populate into symbol list.
+  void populateSymbolListFromDWARF(ProfileSymbolList &SymbolList);
+
   const SampleContextFrameVector &
   getFrameLocationStack(uint64_t Offset, bool UseProbeDiscriminator = false) {
     auto I = Offset2LocStackMap.emplace(Offset, SampleContextFrameVector());


        


More information about the llvm-commits mailing list