[PGO] simple refactoring (NFC)
authorXinliang David Li <davidxl@google.com>
Sun, 3 Jan 2016 04:38:13 +0000 (04:38 +0000)
committerXinliang David Li <davidxl@google.com>
Sun, 3 Jan 2016 04:38:13 +0000 (04:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256695 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
lib/ProfileData/InstrProf.cpp

index d8e9174..6b2a396 100644 (file)
@@ -155,6 +155,8 @@ GlobalVariable *createPGOFuncNameVar(Function &F, StringRef FuncName);
 GlobalVariable *createPGOFuncNameVar(Module &M,
                                      GlobalValue::LinkageTypes Linkage,
                                      StringRef FuncName);
+/// Return the initializer in string of the PGO name var \c NameVar.
+StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar);
 
 /// Given a PGO function name, remove the filename prefix and return
 /// the original (static) function name.
index df3f8fa..3c75269 100644 (file)
@@ -197,14 +197,18 @@ int collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
   return 0;
 }
 
+StringRef getPGOFuncNameInitializer(GlobalVariable *NameVar) {
+  auto *Arr = cast<ConstantDataArray>(NameVar->getInitializer());
+  StringRef NameStr =
+      Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
+  return NameStr;
+}
+
 int collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
                               std::string &Result) {
   std::vector<std::string> NameStrs;
   for (auto *NameVar : NameVars) {
-    auto *Arr = cast<ConstantDataArray>(NameVar->getInitializer());
-    StringRef NameStr =
-        Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
-    NameStrs.push_back(NameStr.str());
+    NameStrs.push_back(getPGOFuncNameInitializer(NameVar));
   }
   return collectPGOFuncNameStrings(NameStrs, zlib::isAvailable(), Result);
 }