[PATCH] D18623: [PGO] refactor PGOFuncName meta data code to be used in clang
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 30 14:26:22 PDT 2016
xur created this revision.
xur added reviewers: davidxl, joker.eph.
xur added subscribers: llvm-commits, bogner, vsk, xur.
Refactor the code that gets and creates PGOFuncName meta data so that it can be used in clang's value profile annotation.
http://reviews.llvm.org/D18623
Files:
include/llvm/ProfileData/InstrProf.h
lib/ProfileData/InstrProf.cpp
lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -750,14 +750,8 @@
if (DisableValueProfiling)
return;
- // Write out the PGOFuncName if this is different from it's raw name.
- // This should only apply to internal linkage functions only.
- const std::string &FuncName = getPGOFuncName(F);
- if (FuncName != F.getName()) {
- LLVMContext &C = F.getContext();
- MDNode *N = MDNode::get(C, MDString::get(C, FuncName.c_str()));
- F.setMetadata("PGOFuncName", N);
- }
+ // Write out the PGOFuncName meta data.
+ createPGOFuncNameMetaData(F);
unsigned IndirectCallSiteIndex = 0;
PGOIndirectCallSiteVisitor ICV;
Index: lib/ProfileData/InstrProf.cpp
===================================================================
--- lib/ProfileData/InstrProf.cpp
+++ lib/ProfileData/InstrProf.cpp
@@ -99,16 +99,15 @@
Version);
// InLTO mode. First check if these is a meta data.
- MDNode *MD = F.getMetadata("PGOFuncName");
- if (MD != nullptr) {
+ if (MDNode *MD = getPGOFuncNameMetaData(F)) {
StringRef S = cast<MDString>(MD->getOperand(0))->getString();
return S.str();
}
// If there is no meta data, the function must be a global before the value
// profile annotation pass. Its current linkage may be internal if it is
// internalized in LTO mode.
- return getPGOFuncName (F.getName(), GlobalValue::ExternalLinkage, "");
+ return getPGOFuncName(F.getName(), GlobalValue::ExternalLinkage, "");
}
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) {
Index: include/llvm/ProfileData/InstrProf.h
===================================================================
--- include/llvm/ProfileData/InstrProf.h
+++ include/llvm/ProfileData/InstrProf.h
@@ -19,6 +19,8 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/ProfileData/InstrProfData.inc"
#include "llvm/ProfileData/ProfileCommon.h"
@@ -245,6 +247,29 @@
InstrProfValueData ValueData[],
uint32_t &ActualNumValueData, uint64_t &TotalC);
+inline StringRef PGOFuncNameMetaData(){
+ return "PGOFuncName";
+}
+
+/// Return the PGOFuncName meta data associated with a function.
+inline MDNode *getPGOFuncNameMetaData(const Function &F) {
+ return F.getMetadata(PGOFuncNameMetaData());
+}
+
+/// Write out the PGOFuncName meta data if PGOFuncName is different from
+/// function's raw name. This should only apply to internal linkage functions
+/// only. Return true if the meta data is written out, and false if not.
+inline bool createPGOFuncNameMetaData(Function &F) {
+ const std::string &FuncName = getPGOFuncName(F);
+ if (FuncName == F.getName())
+ return false;
+
+ LLVMContext &C = F.getContext();
+ MDNode *N = MDNode::get(C, MDString::get(C, FuncName.c_str()));
+ F.setMetadata(PGOFuncNameMetaData(), N);
+ return true;
+}
+
const std::error_category &instrprof_category();
enum class instrprof_error {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18623.52123.patch
Type: text/x-patch
Size: 3310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160330/4b8b0d03/attachment.bin>
More information about the llvm-commits
mailing list