[PGO] simple refactoring (NFC)

llvm-svn: 256695
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index d8e9174..6b2a396 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -155,6 +155,8 @@
 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.
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index df3f8fa..3c75269 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -197,14 +197,18 @@
   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);
 }