[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
This commit is contained in:
wlei 2021-10-21 20:56:06 -07:00
parent 40ca411251
commit 2f8196db92
5 changed files with 15 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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 =

View File

@ -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());