-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-profgen] Filter out ambiguous cold profiles during profile generation #81803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
foo:12345:1000 | ||
1: 1000 | ||
4: bar:1000 | ||
1: 1000 | ||
2: __tls_init.llvm.123:1 | ||
1: 1 | ||
3: goo:300 | ||
1: 300 | ||
8: __cxx_global_var_init.4:4 | ||
1: 1 | ||
2: goo:3 | ||
1: 3 | ||
__cxx_global_var_init.1:1:1 | ||
1: 1 | ||
__tls_init.llvm.345:1:1 | ||
1: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
; RUN: llvm-profgen --format=text --llvm-sample-profile=%S/Inputs/filter-ambiguous-profile.prof --binary=%S/Inputs/inline-cs-noprobe.perfbin --csspgo-preinliner=0 --output=%t1 || FileCheck %s --input-file %t1 | ||
|
||
;CHECK: foo:12345:1000 | ||
;CHECK-NEXT 1: 1000 | ||
;CHECK-NEXT 4: bar:1000 | ||
;CHECK-NEXT 1: 1000 | ||
;CHECK-NEXT 3: goo:300 | ||
;CHECK-NEXT 1: 300 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,48 @@ void ProfileGeneratorBase::showDensitySuggestion(double Density) { | |
<< "% total samples: " << format("%.1f", Density) << "\n"; | ||
} | ||
|
||
bool ProfileGeneratorBase::filterAmbiguousProfile(FunctionSamples &FS) { | ||
for (const auto &Prefix : FuncPrefixsToFilter) { | ||
if (FS.getFuncName().starts_with(Prefix)) | ||
return true; | ||
} | ||
|
||
// Filter the function profiles for the inlinees. It's useful for fuzzy | ||
// profile matching which flattens the profile and inlinees' samples are | ||
// merged into top-level function. | ||
for (auto &Callees : | ||
const_cast<CallsiteSampleMap &>(FS.getCallsiteSamples())) { | ||
auto &CalleesMap = Callees.second; | ||
for (auto I = CalleesMap.begin(); I != CalleesMap.end();) { | ||
auto FS = I++; | ||
if (filterAmbiguousProfile(FS->second)) | ||
CalleesMap.erase(FS); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
// For built-in local initialization function such as __cxx_global_var_init, | ||
// __tls_init prefix function, there could be multiple versions of the functions | ||
// in the final binary. However, in the profile generation, we call | ||
// getCanonicalFnName to canonicalize the names which strips the suffixes. | ||
// Therefore, samples from different functions queries the same profile and the | ||
// samples are merged. As the functions are essentially different, entries of | ||
// the merged profile are ambiguous. In sample loader, the IR from one version | ||
// would be attributed towards a merged entries, which is inaccurate. Especially | ||
// for fuzzy profile matching, it gets multiple callsites(from different | ||
// function) but used to match one callsite, which misleads the matching and | ||
// causes a lot of false positives report. Hence, we want to filter them out | ||
// from the profile map during the profile generation time. The profiles are all | ||
// cold functions, it won't have perf impact. | ||
void ProfileGeneratorBase::filterAmbiguousProfile(SampleProfileMap &Profiles) { | ||
for (auto I = ProfileMap.begin(); I != ProfileMap.end();) { | ||
auto FS = I++; | ||
if (filterAmbiguousProfile(FS->second)) | ||
ProfileMap.erase(FS); | ||
} | ||
} | ||
|
||
double ProfileGeneratorBase::calculateDensity(const SampleProfileMap &Profiles, | ||
uint64_t HotCntThreshold) { | ||
double Density = DBL_MAX; | ||
|
@@ -491,6 +533,7 @@ void ProfileGenerator::generateProfile() { | |
void ProfileGenerator::postProcessProfiles() { | ||
computeSummaryAndThreshold(ProfileMap); | ||
trimColdProfiles(ProfileMap, ColdCountThreshold); | ||
filterAmbiguousProfile(ProfileMap); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please comment why we need to filter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added more comments to the function. |
||
calculateAndShowDensity(ProfileMap); | ||
} | ||
|
||
|
@@ -1024,6 +1067,7 @@ void CSProfileGenerator::postProcessProfiles() { | |
CSConverter.convertCSProfiles(); | ||
FunctionSamples::ProfileIsCS = false; | ||
} | ||
filterAmbiguousProfile(ProfileMap); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have it both here and in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
void ProfileGeneratorBase::computeSummaryAndThreshold( | ||
|
Uh oh!
There was an error while loading. Please reload this page.