[llvm] fd29a4d - [Pseudo Probe] Use the name from debug info to compute GUID in probe desc
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 22 22:49:06 PDT 2023
Author: wlei
Date: 2023-03-22T22:47:23-07:00
New Revision: fd29a4d24267eef0f11d238cb4a32b07d56d6c5c
URL: https://github.com/llvm/llvm-project/commit/fd29a4d24267eef0f11d238cb4a32b07d56d6c5c
DIFF: https://github.com/llvm/llvm-project/commit/fd29a4d24267eef0f11d238cb4a32b07d56d6c5c.diff
LOG: [Pseudo Probe] Use the name from debug info to compute GUID in probe desc
This is to fix a GUID mismatch while decoding pseudo probe, a GUID from the inline tree is not in the GUID2FuncDescMap. It turned out that frontend could change the function name making it different from the one in debug info(https://reviews.llvm.org/D111009). Here change to use the function name from debug info to be consistent with the probe name from the inline stack.
Reviewed By: hoy, wenlei
Differential Revision: https://reviews.llvm.org/D146657
Added:
Modified:
llvm/include/llvm/IR/MDBuilder.h
llvm/lib/IR/MDBuilder.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/MDBuilder.h b/llvm/include/llvm/IR/MDBuilder.h
index bd542bd0d2b2b..39165453de16b 100644
--- a/llvm/include/llvm/IR/MDBuilder.h
+++ b/llvm/include/llvm/IR/MDBuilder.h
@@ -78,7 +78,7 @@ class MDBuilder {
MDNode *createFunctionSectionPrefix(StringRef Prefix);
/// Return metadata containing the pseudo probe descriptor for a function.
- MDNode *createPseudoProbeDesc(uint64_t GUID, uint64_t Hash, Function *F);
+ MDNode *createPseudoProbeDesc(uint64_t GUID, uint64_t Hash, StringRef FName);
/// Return metadata containing llvm statistics.
MDNode *
diff --git a/llvm/lib/IR/MDBuilder.cpp b/llvm/lib/IR/MDBuilder.cpp
index 38ab1d3d10244..2490b3012bdc2 100644
--- a/llvm/lib/IR/MDBuilder.cpp
+++ b/llvm/lib/IR/MDBuilder.cpp
@@ -336,12 +336,12 @@ MDNode *MDBuilder::createIrrLoopHeaderWeight(uint64_t Weight) {
}
MDNode *MDBuilder::createPseudoProbeDesc(uint64_t GUID, uint64_t Hash,
- Function *F) {
+ StringRef FName) {
auto *Int64Ty = Type::getInt64Ty(Context);
SmallVector<Metadata *, 3> Ops(3);
Ops[0] = createConstant(ConstantInt::get(Int64Ty, GUID));
Ops[1] = createConstant(ConstantInt::get(Int64Ty, Hash));
- Ops[2] = createString(F->getName());
+ Ops[2] = createString(FName);
return MDNode::get(Context, Ops);
}
diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index 7a40ddee81798..ed1d5575db69a 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -286,9 +286,16 @@ uint32_t SampleProfileProber::getCallsiteId(const Instruction *Call) const {
void SampleProfileProber::instrumentOneFunc(Function &F, TargetMachine *TM) {
Module *M = F.getParent();
MDBuilder MDB(F.getContext());
- // Compute a GUID without considering the function's linkage type. This is
- // fine since function name is the only key in the profile database.
- uint64_t Guid = Function::getGUID(F.getName());
+ // Since the GUID from probe desc and inline stack are computed seperately, we
+ // need to make sure their names are consistent, so here also use the name
+ // from debug info.
+ StringRef FName = F.getName();
+ if (auto *SP = F.getSubprogram()) {
+ FName = SP->getLinkageName();
+ if (FName.empty())
+ FName = SP->getName();
+ }
+ uint64_t Guid = Function::getGUID(FName);
// Assign an artificial debug line to a probe that doesn't come with a real
// line. A probe not having a debug line will get an incomplete inline
@@ -371,7 +378,7 @@ void SampleProfileProber::instrumentOneFunc(Function &F, TargetMachine *TM) {
// - FunctionHash.
// - FunctionName
auto Hash = getFunctionHash();
- auto *MD = MDB.createPseudoProbeDesc(Guid, Hash, &F);
+ auto *MD = MDB.createPseudoProbeDesc(Guid, Hash, FName);
auto *NMD = M->getNamedMetadata(PseudoProbeDescMetadataName);
assert(NMD && "llvm.pseudo_probe_desc should be pre-created");
NMD->addOperand(MD);
More information about the llvm-commits
mailing list