diff --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test index 991602bd2f85..c7657ef348a3 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 3fcc1cb5541c..27019a468a84 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 ea0d7a1c2933..88e96348cba4 100644 --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -33,7 +33,7 @@ cl::opt UseMD5( "meaningful for -extbinary)")); static cl::opt 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 RecursionCompression( @@ -97,16 +97,8 @@ void ProfileGeneratorBase::write(std::unique_ptr 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 e9c18cd4b1fa..43c86106f2a5 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 ba7c70343132..d6e7ba81fef1 100644 --- a/llvm/tools/llvm-profgen/ProfiledBinary.h +++ b/llvm/tools/llvm-profgen/ProfiledBinary.h @@ -382,6 +382,9 @@ public: 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());