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 *
}
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);
}
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
// - 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);