profile: Avoid name collisions between instrumentation and runtime

The naming scheme we're using for counters in profile data shares a
prefix with some fixed names we use for the runtime, notably
__llvm_profile_data_begin and _end. Embarrassingly, this means a
function called begin() can't be instrumented.

This modifies the runtime names so as not to collide with the
instrumentation.

llvm-svn: 217166
This commit is contained in:
Justin Bogner 2014-09-04 15:45:31 +00:00
parent 7c3d581e8a
commit cc0d7eeb6d
7 changed files with 54 additions and 35 deletions

View File

@ -41,8 +41,8 @@ uint64_t __llvm_profile_get_version(void) {
__attribute__((visibility("hidden")))
void __llvm_profile_reset_counters(void) {
uint64_t *I = __llvm_profile_counters_begin();
uint64_t *E = __llvm_profile_counters_end();
uint64_t *I = __llvm_profile_begin_counters();
uint64_t *E = __llvm_profile_end_counters();
memset(I, 0, sizeof(uint64_t)*(E - I));
}

View File

@ -50,15 +50,15 @@ uint64_t __llvm_profile_get_size_for_buffer(void);
*/
int __llvm_profile_write_buffer(char *Buffer);
const __llvm_profile_data *__llvm_profile_data_begin(void);
const __llvm_profile_data *__llvm_profile_data_end(void);
const char *__llvm_profile_names_begin(void);
const char *__llvm_profile_names_end(void);
uint64_t *__llvm_profile_counters_begin(void);
uint64_t *__llvm_profile_counters_end(void);
const __llvm_profile_data *__llvm_profile_begin_data(void);
const __llvm_profile_data *__llvm_profile_end_data(void);
const char *__llvm_profile_begin_names(void);
const char *__llvm_profile_end_names(void);
uint64_t *__llvm_profile_begin_counters(void);
uint64_t *__llvm_profile_end_counters(void);
#define PROFILE_RANGE_SIZE(Range) \
(__llvm_profile_ ## Range ## _end() - __llvm_profile_ ## Range ## _begin())
(__llvm_profile_end_ ## Range () - __llvm_profile_begin_ ## Range ())
/*!
* \brief Write instrumentation data to the current file.

View File

@ -26,12 +26,12 @@ int __llvm_profile_write_buffer(char *Buffer) {
/* Match logic in __llvm_profile_get_size_for_buffer().
* Match logic in __llvm_profile_write_file().
*/
const __llvm_profile_data *DataBegin = __llvm_profile_data_begin();
const __llvm_profile_data *DataEnd = __llvm_profile_data_end();
const uint64_t *CountersBegin = __llvm_profile_counters_begin();
const uint64_t *CountersEnd = __llvm_profile_counters_end();
const char *NamesBegin = __llvm_profile_names_begin();
const char *NamesEnd = __llvm_profile_names_end();
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
const uint64_t *CountersBegin = __llvm_profile_begin_counters();
const uint64_t *CountersEnd = __llvm_profile_end_counters();
const char *NamesBegin = __llvm_profile_begin_names();
const char *NamesEnd = __llvm_profile_end_names();
/* Calculate size of sections. */
const uint64_t DataSize = DataEnd - DataBegin;

View File

@ -16,12 +16,12 @@
static int writeFile(FILE *File) {
/* Match logic in __llvm_profile_write_buffer(). */
const __llvm_profile_data *DataBegin = __llvm_profile_data_begin();
const __llvm_profile_data *DataEnd = __llvm_profile_data_end();
const uint64_t *CountersBegin = __llvm_profile_counters_begin();
const uint64_t *CountersEnd = __llvm_profile_counters_end();
const char *NamesBegin = __llvm_profile_names_begin();
const char *NamesEnd = __llvm_profile_names_end();
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
const uint64_t *CountersBegin = __llvm_profile_begin_counters();
const uint64_t *CountersEnd = __llvm_profile_end_counters();
const char *NamesBegin = __llvm_profile_begin_names();
const char *NamesEnd = __llvm_profile_end_names();
/* Calculate size of sections. */
const uint64_t DataSize = DataEnd - DataBegin;

View File

@ -25,19 +25,19 @@ __attribute__((visibility("hidden")))
extern uint64_t CountersEnd __asm("section$end$__DATA$__llvm_prf_cnts");
__attribute__((visibility("hidden")))
const __llvm_profile_data *__llvm_profile_data_begin(void) {
const __llvm_profile_data *__llvm_profile_begin_data(void) {
return &DataStart;
}
__attribute__((visibility("hidden")))
const __llvm_profile_data *__llvm_profile_data_end(void) {
const __llvm_profile_data *__llvm_profile_end_data(void) {
return &DataEnd;
}
__attribute__((visibility("hidden")))
const char *__llvm_profile_names_begin(void) { return &NamesStart; }
const char *__llvm_profile_begin_names(void) { return &NamesStart; }
__attribute__((visibility("hidden")))
const char *__llvm_profile_names_end(void) { return &NamesEnd; }
const char *__llvm_profile_end_names(void) { return &NamesEnd; }
__attribute__((visibility("hidden")))
uint64_t *__llvm_profile_counters_begin(void) { return &CountersStart; }
uint64_t *__llvm_profile_begin_counters(void) { return &CountersStart; }
__attribute__((visibility("hidden")))
uint64_t *__llvm_profile_counters_end(void) { return &CountersEnd; }
uint64_t *__llvm_profile_end_counters(void) { return &CountersEnd; }
#endif

View File

@ -56,19 +56,19 @@ void __llvm_profile_register_function(void *Data_) {
}
__attribute__((visibility("hidden")))
const __llvm_profile_data *__llvm_profile_data_begin(void) {
const __llvm_profile_data *__llvm_profile_begin_data(void) {
return DataFirst;
}
__attribute__((visibility("hidden")))
const __llvm_profile_data *__llvm_profile_data_end(void) {
const __llvm_profile_data *__llvm_profile_end_data(void) {
return DataLast;
}
__attribute__((visibility("hidden")))
const char *__llvm_profile_names_begin(void) { return NamesFirst; }
const char *__llvm_profile_begin_names(void) { return NamesFirst; }
__attribute__((visibility("hidden")))
const char *__llvm_profile_names_end(void) { return NamesLast; }
const char *__llvm_profile_end_names(void) { return NamesLast; }
__attribute__((visibility("hidden")))
uint64_t *__llvm_profile_counters_begin(void) { return CountersFirst; }
uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
__attribute__((visibility("hidden")))
uint64_t *__llvm_profile_counters_end(void) { return CountersLast; }
uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
#endif

View File

@ -3,10 +3,29 @@
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
int main(int argc, const char *argv[]) {
int begin(int i) {
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !1
if (i)
return 0;
return 1;
}
int end(int i) {
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !2
if (i)
return 0;
return 1;
}
int main(int argc, const char *argv[]) {
begin(0);
end(1);
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !2
if (argc)
return 0;
return 1;
}
// CHECK: !1 = metadata !{metadata !"branch_weights", i32 2, i32 1}
// CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 2}
// CHECK: !2 = metadata !{metadata !"branch_weights", i32 2, i32 1}