summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ProfileData/InstrProf.h2
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp12
2 files changed, 10 insertions, 4 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index d8e9174196d..6b2a396f9b1 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -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.
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index df3f8fade3b..3c752699a27 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -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);
}
OpenPOWER on IntegriCloud