[PGO] Fix remaining bugs in ProfData template file (when used by compiler-rt)
[oota-llvm.git] / include / llvm / ProfileData / InstrProfData.inc
index 1452baeb06f5c6ae572a6afba6a60a9429589b90..63447ce8ca73b4c089ede1197267fa8d0d40b97f 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
@@ -93,16 +94,16 @@ INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
 #else
 #define INSTR_PROF_DATA_DEFINED
 #endif
-INSTR_PROF_RAW_HEADER(const uint64_t, Magic, __llvm_profile_get_magic())
-INSTR_PROF_RAW_HEADER(const uint64_t, Version, __llvm_profile_get_version())
-INSTR_PROF_RAW_HEADER(const uint64_t, DataSize, DataSize)
-INSTR_PROF_RAW_HEADER(const uint64_t, CountersSize, CountersSize)
-INSTR_PROF_RAW_HEADER(const uint64_t, NamesSize,  NameSize)
-INSTR_PROF_RAW_HEADER(const uint64_t, CountersDelta, (uintptr_t)CountersBegin)
-INSTR_PROF_RAW_HEADER(const uint64_t, NamesDelta, (uintptr_t)NamesBegin)
-INSTR_PROF_RAW_HEADER(const uint64_t, ValueKindLast, IPVK_Last)
-INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataSize, ValueDataSize)
-INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataDelta, (uintptr_t)ValueDataBegin)
+INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
+INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
+INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize)
+INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize)
+INSTR_PROF_RAW_HEADER(uint64_t, NamesSize,  NamesSize)
+INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
+INSTR_PROF_RAW_HEADER(int64_t, NamesDelta, (uintptr_t)NamesBegin)
+INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
+INSTR_PROF_RAW_HEADER(uint64_t, ValueDataSize, ValueDataSize)
+INSTR_PROF_RAW_HEADER(uint64_t, ValueDataDelta, (uintptr_t)ValueDataBegin)
 #undef INSTR_PROF_RAW_HEADER
 /* INSTR_PROF_RAW_HEADER  end */
 
@@ -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              
@@ -185,16 +193,43 @@ COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
  * The magic and version need to be kept in sync with                                    
  * projects/compiler-rt/lib/profile/InstrProfiling.c                                     
  */
-#define INSTR_PROF_RAW_MAGIC_64 uint64_t(255) << 56 | uint64_t('l') << 48 | \
-       uint64_t('p') << 40 | uint64_t('r') << 32 | uint64_t('o') << 24 |  \
-        uint64_t('f') << 16 | uint64_t('r') << 8 | uint64_t(129)
-#define INSTR_PROF_RAW_MAGIC_32 uint64_t(255) << 56 | uint64_t('l') << 48 | \
-       uint64_t('p') << 40 | uint64_t('r') << 32 | uint64_t('o') << 24 |  \
-        uint64_t('f') << 16 | uint64_t('R') << 8 | uint64_t(129)
+#define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
+       (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
+        (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
+#define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
+       (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
+        (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
 
 /* 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