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 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; }