[compiler-rt] r257230 - [PGO] Add runtime hook so that IR instrumentation can override version

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 8 15:31:57 PST 2016


Author: davidxl
Date: Fri Jan  8 17:31:57 2016
New Revision: 257230

URL: http://llvm.org/viewvc/llvm-project?rev=257230&view=rev
Log:
[PGO] Add runtime hook so that IR instrumentation can override version

IR level instrumentation needs to override version with variant bits.
No change for FE instrumentation is needed. Test case is added to
detect version mismatch.


Added:
    compiler-rt/trunk/test/profile/instrprof-version-mismatch.c
Modified:
    compiler-rt/trunk/lib/profile/InstrProfiling.c
    compiler-rt/trunk/lib/profile/InstrProfilingFile.c

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=257230&r1=257229&r2=257230&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Fri Jan  8 17:31:57 2016
@@ -18,6 +18,8 @@
 
 char *(*GetEnvHook)(const char *) = 0;
 
+COMPILER_RT_WEAK uint64_t __llvm_profile_raw_version = INSTR_PROF_RAW_VERSION;
+
 COMPILER_RT_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,7 +34,7 @@ __llvm_profile_get_num_padding_bytes(uin
 }
 
 COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_version(void) {
-  return INSTR_PROF_RAW_VERSION;
+  return __llvm_profile_raw_version;
 }
 
 COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
@@ -65,4 +67,3 @@ COMPILER_RT_VISIBILITY void __llvm_profi
     }
   }
 }
-

Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=257230&r1=257229&r2=257230&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Fri Jan  8 17:31:57 2016
@@ -214,6 +214,15 @@ int __llvm_profile_write_file(void) {
     return -1;
   }
 
+  /* Check if there is llvm/runtime versino mismatch.  */
+  if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) {
+    PROF_ERR("LLVM Profile: runtime and instrumentation version mismatch : "
+             "expected %d, but get %d\n",
+             INSTR_PROF_RAW_VERSION,
+             (int)GET_VERSION(__llvm_profile_get_version()));
+    return -1;
+  }
+
   /* Write the file. */
   rc = writeFileWithName(__llvm_profile_CurrentFilename);
   if (rc)

Added: compiler-rt/trunk/test/profile/instrprof-version-mismatch.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-version-mismatch.c?rev=257230&view=auto
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-version-mismatch.c (added)
+++ compiler-rt/trunk/test/profile/instrprof-version-mismatch.c Fri Jan  8 17:31:57 2016
@@ -0,0 +1,11 @@
+// RUN: %clang_profgen -o %t -O3 %s
+// RUN: LLVM_PROFILE_VERBOSE_ERRORS=1 %run %t 1 2>&1 | FileCheck %s
+
+// override the version variable with a bogus version:
+unsigned long long __llvm_profile_raw_version = 10000;
+int main(int argc, const char *argv[]) {
+  if (argc < 2)
+    return 1;
+  return 0;
+}
+// CHECK: LLVM Profile: runtime and instrumentation version mismatch




More information about the llvm-commits mailing list