summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/InstrProf.cpp
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2016-04-01 16:43:30 +0000
committerRong Xu <xur@google.com>2016-04-01 16:43:30 +0000
commit8e8fe859e059ce0d0704596c5c6a7ab02f39c5ee (patch)
tree70df5a8810cf47f3013623517b49b39086c7d799 /llvm/lib/ProfileData/InstrProf.cpp
parenta05e0ff22376f4cbc6707841b3760c6f9f587663 (diff)
downloadbcm5719-llvm-8e8fe859e059ce0d0704596c5c6a7ab02f39c5ee.tar.gz
bcm5719-llvm-8e8fe859e059ce0d0704596c5c6a7ab02f39c5ee.zip
[PGO] Refactor PGOFuncName meta data code to be used in clang
Refactor the code that gets and creates PGOFuncName meta data so that it can be used in clang's value profile annotation. Differential Revision: http://reviews.llvm.org/D18623 llvm-svn: 265149
Diffstat (limited to 'llvm/lib/ProfileData/InstrProf.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp18
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
OpenPOWER on IntegriCloud