diff options
Diffstat (limited to 'llvm/lib/ProfileData/InstrProf.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 4a023f7b2ad..618bcebbdc4 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -98,9 +98,8 @@ std::string getPGOFuncName(const Function &F, bool InLTO, uint64_t Version) { return getPGOFuncName(F.getName(), F.getLinkage(), F.getParent()->getName(), Version); - // InLTO mode. First check if these is a meta data. - MDNode *MD = F.getMetadata("PGOFuncName"); - if (MD != nullptr) { + // In LTO mode (when InLTO is true), first check if there is a meta data. + if (MDNode *MD = getPGOFuncNameMetadata(F)) { StringRef S = cast<MDString>(MD->getOperand(0))->getString(); return S.str(); } @@ -108,7 +107,7 @@ std::string getPGOFuncName(const Function &F, bool InLTO, uint64_t Version) { // If there is no meta data, the function must be a global before the value // profile annotation pass. Its current linkage may be internal if it is // internalized in LTO mode. - return getPGOFuncName (F.getName(), GlobalValue::ExternalLinkage, ""); + return getPGOFuncName(F.getName(), GlobalValue::ExternalLinkage, ""); } StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { @@ -720,4 +719,15 @@ bool getValueProfDataFromInst(const Instruction &Inst, } return true; } + +void createPGOFuncNameMetadata(Function &F) { + const std::string &FuncName = getPGOFuncName(F); + if (FuncName == F.getName()) + return; + + LLVMContext &C = F.getContext(); + MDNode *N = MDNode::get(C, MDString::get(C, FuncName.c_str())); + F.setMetadata(getPGOFuncNameMetadataName(), N); +} + } // end namespace llvm |