OSDN Git Service

[PGO] change the interface for createPGOFuncNameMetadata()
authorRong Xu <xur@google.com>
Fri, 22 Apr 2016 21:00:17 +0000 (21:00 +0000)
committerRong Xu <xur@google.com>
Fri, 22 Apr 2016 21:00:17 +0000 (21:00 +0000)
This patch changes the interface for createPGOFuncNameMetadata() where we add
another PGOFuncName argument.

Differential Revision: http://reviews.llvm.org/D19433

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267216 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
lib/ProfileData/InstrProf.cpp
lib/Transforms/Instrumentation/PGOInstrumentation.cpp

index fde4b29..88fc61a 100644 (file)
@@ -253,7 +253,7 @@ MDNode *getPGOFuncNameMetadata(const Function &F);
 /// 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 f1a6ce9..931282b 100644 (file)
@@ -732,13 +732,15 @@ MDNode *getPGOFuncNameMetadata(const Function &F) {
   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 bf2933e..ff8e9b4 100644 (file)
@@ -732,7 +732,7 @@ void PGOUseFunc::annotateIndirectCallSites() {
     return;
 
   // Create the PGOFuncName meta data.
-  createPGOFuncNameMetadata(F);
+  createPGOFuncNameMetadata(F, FuncInfo.FuncName);
 
   unsigned IndirectCallSiteIndex = 0;
   auto IndirectCallSites = findIndirectCallSites(F);