/// Create the PGOFuncName meta data if PGOFuncName is different from
/// function's raw name. This should only apply to internal linkage functions
/// declared by users only.
-void createPGOFuncNameMetadata(Function &F);
+void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName);
const std::error_category &instrprof_category();
return F.getMetadata(getPGOFuncNameMetadataName());
}
-void createPGOFuncNameMetadata(Function &F) {
- const std::string &FuncName = getPGOFuncName(F);
- if (FuncName == F.getName())
+void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName) {
+ // Only for internal linkage functions.
+ if (PGOFuncName == F.getName())
+ return;
+ // Don't create duplicated meta-data.
+ if (getPGOFuncNameMetadata(F))
return;
-
LLVMContext &C = F.getContext();
- MDNode *N = MDNode::get(C, MDString::get(C, FuncName.c_str()));
+ MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName.c_str()));
F.setMetadata(getPGOFuncNameMetadataName(), N);
}
return;
// Create the PGOFuncName meta data.
- createPGOFuncNameMetadata(F);
+ createPGOFuncNameMetadata(F, FuncInfo.FuncName);
unsigned IndirectCallSiteIndex = 0;
auto IndirectCallSites = findIndirectCallSites(F);