[PGO] move names of runtime sections definitions to InstrProfData.inc
authorXinliang David Li <davidxl@google.com>
Sun, 22 Nov 2015 05:42:31 +0000 (05:42 +0000)
committerXinliang David Li <davidxl@google.com>
Sun, 22 Nov 2015 05:42:31 +0000 (05:42 +0000)
In profile runtime implementation for Darwin, Linux and FreeBSD, the
names of sections holding profile control/counter/naming data need
to be known by the runtime in order to locate the start/end of the
data. Moving the name definitions to the common file to specify the
connection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253814 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
include/llvm/ProfileData/InstrProfData.inc
lib/Transforms/Instrumentation/InstrProfiling.cpp

index 4cd4ef9ee8f1d807967ba00497ff5f55dceef925..6eea531e589df317a8b854d3f1377bd7daf6da86 100644 (file)
@@ -37,19 +37,28 @@ class Module;
 
 /// Return the name of data section containing profile counter variables.
 inline StringRef getInstrProfCountersSectionName(bool AddSegment) {
-  return AddSegment ? "__DATA,__llvm_prf_cnts" : "__llvm_prf_cnts";
+  return AddSegment ? "__DATA," INSTR_PROF_CNTS_SECT_NAME_STR
+                    : INSTR_PROF_CNTS_SECT_NAME_STR;
 }
 
 /// Return the name of data section containing names of instrumented
 /// functions.
 inline StringRef getInstrProfNameSectionName(bool AddSegment) {
-  return AddSegment ? "__DATA,__llvm_prf_names" : "__llvm_prf_names";
+  return AddSegment ? "__DATA," INSTR_PROF_NAME_SECT_NAME_STR
+                    : INSTR_PROF_NAME_SECT_NAME_STR;
 }
 
 /// Return the name of the data section containing per-function control
 /// data.
 inline StringRef getInstrProfDataSectionName(bool AddSegment) {
-  return AddSegment ? "__DATA,__llvm_prf_data" : "__llvm_prf_data";
+  return AddSegment ? "__DATA," INSTR_PROF_DATA_SECT_NAME_STR
+                    : INSTR_PROF_DATA_SECT_NAME_STR;
+}
+
+/// Return the name profile runtime entry point to do value profiling
+/// for a given site.
+inline StringRef getInstrProfValueProfFuncName() {
+  return INSTR_PROF_VALUE_PROF_FUNC_STR;
 }
 
 /// Return the name of the section containing function coverage mapping
index 1452baeb06f5c6ae572a6afba6a60a9429589b90..31173cb7ee6d0ed18d785fa7f619a1e48e92efcb 100644 (file)
  * or both.
  *
  * The file has two identical copies. The master copy lives in LLVM and
- * the other one  sits in compiler-rt/lib/profile directory. Changes can only
- * be made directly made in the master copy. Whenever the master copy changes,
- * the compiler-rt copy needs to be kept in sync with the master.
+ * the other one  sits in compiler-rt/lib/profile directory. To make changes
+ * in this file, first modify the master copy and copy it over to compiler-rt.
+ * Testing of any change in this file can start only after the two copies are
+ * synced up.
  *
  * The first part of the file includes macros that defines types, names, and
  * initializers for the member fields of the core data structures. The field
@@ -176,6 +177,13 @@ COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
 #ifndef INSTR_PROF_DATA_INC_
 #define INSTR_PROF_DATA_INC_
 
+/* Helper macros.  */
+#define INSTR_PROF_SIMPLE_QUOTE(x) #x
+#define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
+#define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
+#define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
+
+
 /* Magic number to detect file format and endianness.
  * Use 255 at one end, since no UTF-8 file can use that character.  Avoid 0,             
  * so that utilities, like strings, don't grab it as a string.  129 is also              
@@ -195,6 +203,33 @@ COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
 /* Raw profile format version. */
 #define INSTR_PROF_RAW_VERSION 2
 
+/* Runtime section names and name strings.  */
+#define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
+#define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names
+#define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts
+
+#define INSTR_PROF_DATA_SECT_NAME_STR \
+        INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME)
+#define INSTR_PROF_NAME_SECT_NAME_STR \
+        INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME)
+#define INSTR_PROF_CNTS_SECT_NAME_STR \
+        INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME)
+
+/* Macros to define start/stop section symbol for a given
+ * section on Linux. For instance
+ * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
+ * expand to __start___llvm_prof_data
+ */
+#define INSTR_PROF_SECT_START(Sect) \
+        INSTR_PROF_CONCAT(__start_,Sect)
+#define INSTR_PROF_SECT_STOP(Sect) \
+        INSTR_PROF_CONCAT(__stop_,Sect)
+
+/* Value Profiling API linkage name.  */
+#define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
+#define INSTR_PROF_VALUE_PROF_FUNC_STR \
+        INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
+
 #endif /* INSTR_PROF_DATA_INC_ */
 
 #else
index a70bf27ed7b91dcc22dc90a087536717f5a77289..03b404c1f3b7667c0e779a5a69b4b6773566c117 100644 (file)
@@ -181,7 +181,7 @@ static Constant *getOrInsertValueProfilingCall(Module &M) {
   };
   auto *ValueProfilingCallTy =
       FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false);
-  return M.getOrInsertFunction("__llvm_profile_instrument_target",
+  return M.getOrInsertFunction(getInstrProfValueProfFuncName(),
                                ValueProfilingCallTy);
 }