Index: llvm/trunk/include/llvm/ProfileData/InstrProf.h =================================================================== --- llvm/trunk/include/llvm/ProfileData/InstrProf.h +++ llvm/trunk/include/llvm/ProfileData/InstrProf.h @@ -253,7 +253,7 @@ /// 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(); Index: llvm/trunk/lib/ProfileData/InstrProf.cpp =================================================================== --- llvm/trunk/lib/ProfileData/InstrProf.cpp +++ llvm/trunk/lib/ProfileData/InstrProf.cpp @@ -732,13 +732,15 @@ 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); } Index: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp =================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -732,7 +732,7 @@ return; // Create the PGOFuncName meta data. - createPGOFuncNameMetadata(F); + createPGOFuncNameMetadata(F, FuncInfo.FuncName); unsigned IndirectCallSiteIndex = 0; auto IndirectCallSites = findIndirectCallSites(F);