[llvm] [SampleProfile] Fix bug where intentionally constructed function with empty name asserts. (PR #71479)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 18:43:27 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: William Junda Huang (huangjd)
<details>
<summary>Changes</summary>
Normally SampleContext does not allow using an empty StirngRef to construct an object, this is to prevent bugs reading the profile. However empty names may be emitted by a function which its name is intentionally set to empty, or a bug in the remapper (which should be investigated separately) that remaps a non-empty name to an empty string. Regardless, converting it to FunctionId first will prevent the assert, and that assert check is unnecessary, which will be addressed in another patch
---
Full diff: https://github.com/llvm/llvm-project/pull/71479.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/IPO/SampleProfile.cpp (+3-3)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index a7773737ef16bd3..063f7b42022ff83 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1630,7 +1630,7 @@ void SampleProfileLoader::promoteMergeNotInlinedContextSamples(
// separate map so that it does not rehash the original profile.
if (!OutlineFS)
OutlineFS = &OutlineFunctionSamples[
- FunctionSamples::getCanonicalFnName(Callee->getName())];
+ FunctionId(FunctionSamples::getCanonicalFnName(Callee->getName()))];
OutlineFS->merge(*FS, 1);
// Set outlined profile to be synthetic to not bias the inliner.
OutlineFS->SetContextSynthetic();
@@ -2675,12 +2675,12 @@ bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM)
// into base.
if (!Samples) {
StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
- auto It = OutlineFunctionSamples.find(CanonName);
+ auto It = OutlineFunctionSamples.find(FunctionId(CanonName));
if (It != OutlineFunctionSamples.end()) {
Samples = &It->second;
} else if (auto Remapper = Reader->getRemapper()) {
if (auto RemppedName = Remapper->lookUpNameInProfile(CanonName)) {
- It = OutlineFunctionSamples.find(*RemppedName);
+ It = OutlineFunctionSamples.find(FunctionId(*RemppedName));
if (It != OutlineFunctionSamples.end())
Samples = &It->second;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/71479
More information about the llvm-commits
mailing list