summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-01-08 23:31:57 +0000
committerXinliang David Li <davidxl@google.com>2016-01-08 23:31:57 +0000
commit90d94bf77c2500124fc93f020d14b412036c058a (patch)
tree073a81e1bd6602323244771103f4fb2029e40f56 /lib
parent6ad1f2b89ae795158aa96558f06038ecb2fc4d4e (diff)
[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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@257230 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/profile/InstrProfiling.c5
-rw-r--r--lib/profile/InstrProfilingFile.c9
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/profile/InstrProfiling.c b/lib/profile/InstrProfiling.c
index 58778aeec..711f2b608 100644
--- a/lib/profile/InstrProfiling.c
+++ b/lib/profile/InstrProfiling.c
@@ -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(uint64_t SizeInBytes) {
}
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_profile_reset_counters(void) {
}
}
}
-
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c
index bf50c0276..98d85d9c1 100644
--- a/lib/profile/InstrProfilingFile.c
+++ b/lib/profile/InstrProfilingFile.c
@@ -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)