Index: lib/profile/InstrProfData.inc =================================================================== --- lib/profile/InstrProfData.inc +++ lib/profile/InstrProfData.inc @@ -678,6 +678,18 @@ /* Raw profile format version. */ #define INSTR_PROF_RAW_VERSION 2 +/* Profile version is always of type uint_64_t. Reserve the upper 8 bits in the + * version for other variants of profile. We set the lowest bit of the upper 8 + * bits (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentaiton + * generated profile, and 0 if this is a Clang FE generated profile. + */ +#define VARIANT_MASKS_ALL 0xff00000000000000ULL +#define VARIANT_MASK_IR_PROF (0x1ULL << 56) +#define GET_VERSION(V) ((V)&~VARIANT_MASKS_ALL) +#define IR_LEVEL_PROF_VARNAME __llvm_profile_ir_level +#define IR_LEVEL_PROF_STRINGFY(s) #s +#define IR_LEVEL_PROF_STRING(s) IR_LEVEL_PROF_STRINGFY(s) + /* 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. */ +COMPILER_RT_WEAK int IR_LEVEL_PROF_VARNAME = 0; + 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,6 +35,8 @@ } COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_version(void) { + if (IR_LEVEL_PROF_VARNAME) + return INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF; return INSTR_PROF_RAW_VERSION; }