[PATCH] D19433: [PGO] change the interface for createPGOFuncNameMetadata()

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 13:32:29 PDT 2016


xur created this revision.
xur added a reviewer: davidxl.
xur added subscribers: llvm-commits, anemet, xur.

This patch changes the interface for createPGOFuncNameMetadata() where we add another PGOFuncName argument. This is needed because clang instrumentation and IR instrumentation use slight different prefix in PGOFuncName if the source file name containing directories:
(1) clang instrumentation strips out all the directories.
(2) IR instrumentation keeps the directories path.
To accommodate both usage, we need to have this extra argument.

http://reviews.llvm.org/D19433

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

Index: lib/ProfileData/InstrProf.cpp
===================================================================
--- lib/ProfileData/InstrProf.cpp
+++ 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: include/llvm/ProfileData/InstrProf.h
===================================================================
--- include/llvm/ProfileData/InstrProf.h
+++ 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: lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19433.54709.patch
Type: text/x-patch
Size: 1948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160422/41f1659b/attachment.bin>


More information about the llvm-commits mailing list