[PATCH] D15541: [PGO] generate different version for FE instrumentation and IR level instrumentation profiles

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 14:45:07 PST 2015


xur created this revision.
xur added reviewers: davidxl, silvas, bogner.
xur added a subscriber: llvm-commits.

This patch checks __llvm_profile_ir_level and sets the right version in the generated profiles.
This is related to http://reviews.llvm.org/D15540.

http://reviews.llvm.org/D15541

Files:
  lib/profile/InstrProfData.inc
  lib/profile/InstrProfiling.c

Index: lib/profile/InstrProfiling.c
===================================================================
--- lib/profile/InstrProfiling.c
+++ lib/profile/InstrProfiling.c
@@ -18,6 +18,9 @@
 
 char *(*GetEnvHook)(const char *) = 0;
 
+/* IR level instrumentation declares a strong symbol and sets the value to 1. */
+__attribute__((weak)) int __llvm_profile_ir_level = 0;
+
 LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
   return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)
                                             : (INSTR_PROF_RAW_MAGIC_32);
@@ -32,6 +35,8 @@
 }
 
 LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_version(void) {
+  if (__llvm_profile_ir_level)
+    return SET_IR_LEVEL_PROFILE_FLAG(INSTR_PROF_RAW_VERSION);
   return INSTR_PROF_RAW_VERSION;
 }
 
Index: lib/profile/InstrProfData.inc
===================================================================
--- lib/profile/InstrProfData.inc
+++ lib/profile/InstrProfData.inc
@@ -678,6 +678,15 @@
 /* Raw profile format version. */
 #define INSTR_PROF_RAW_VERSION 2
 
+/* Profile version is always of type uint_64. We set bit 60 to 1 if if this is
+ * an IR-level instrumentaiton generated profile and 0 if this is a Clang FE
+ * generated profile.
+ */
+#define IR_LEVEL_PROFILE_FLAG ((uint64_t)0x1<<60)
+#define SET_IR_LEVEL_PROFILE_FLAG(x) ((x | IR_LEVEL_PROFILE_FLAG))
+#define UNSET_IR_LEVEL_PROFILE_FLAG(x) ((x & ~IR_LEVEL_PROFILE_FLAG))
+#define IS_IR_LEVEL_PROFILE(x) (((x& IR_LEVEL_PROFILE_FLAG) != 0))
+
 /* Runtime section names and name strings.  */
 #define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
 #define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15541.42916.patch
Type: text/x-patch
Size: 1674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151215/50191544/attachment.bin>


More information about the llvm-commits mailing list