Skip to content

Commit 7864711

Browse files
[nfc][compiler-rt]Remove round-up in __llvm_profile_get_num_data (#83194)
- Update instrprof-basic.c as a regression test.
1 parent 3761ad0 commit 7864711

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

compiler-rt/lib/profile/InstrProfilingBuffer.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,12 @@ uint64_t __llvm_profile_get_size_for_buffer(void) {
6161
NamesBegin, NamesEnd, VTableBegin, VTableEnd, VNamesBegin, VNamesEnd);
6262
}
6363

64+
// NOTE: Caller should guarantee that `Begin` and `End` specifies a half-open
65+
// interval [Begin, End). Namely, `End` is one-byte past the end of the array.
6466
COMPILER_RT_VISIBILITY
6567
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
6668
const __llvm_profile_data *End) {
6769
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
68-
// `sizeof(__llvm_profile_data) - 1` is required in the numerator when
69-
// [Begin, End] represents an inclusive range.
70-
// For ELF, [Begin, End) represents the address of linker-inserted
71-
// symbols `__start__<elf-section>` and `__stop_<elf-section>`.
72-
// Thereby, `End` is one byte past the inclusive range, and
73-
// `sizeof(__llvm_profile_data) - 1` is not necessary in the numerator to get
74-
// the correct number of profile data.
75-
// FIXME: Consider removing `sizeof(__llvm_profile_data) - 1` if this is true
76-
// across platforms.
7770
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
7871
sizeof(__llvm_profile_data);
7972
}

compiler-rt/test/profile/instrprof-basic.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// RUN: %clang_profgen -o %t -O3 %s
22
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
33
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
4+
// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s --check-prefix=PROFCNT
45
// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=ORIG
56
//
67
// RUN: rm -fr %t.dir1
78
// RUN: mkdir -p %t.dir1
89
// RUN: env LLVM_PROFILE_FILE=%t.dir1/profraw_e_%1m %run %t
910
// RUN: env LLVM_PROFILE_FILE=%t.dir1/profraw_e_%1m %run %t
1011
// RUN: llvm-profdata merge -o %t.em.profdata %t.dir1
12+
// RUN: llvm-profdata show --all-functions %t.em.profdata | FileCheck %s --check-prefix=PROFCNT
1113
// RUN: %clang_profuse=%t.em.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=MERGE
1214
//
1315
// RUN: rm -fr %t.dir2
@@ -16,6 +18,7 @@
1618
// RUN: %run %t.merge
1719
// RUN: %run %t.merge
1820
// RUN: llvm-profdata merge -o %t.m.profdata %t.dir2/
21+
// RUN: llvm-profdata show --all-functions %t.m.profdata | FileCheck %s --check-prefix=PROFCNT
1922
// RUN: %clang_profuse=%t.m.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=MERGE
2023
//
2124
// Test that merging is enabled by default with -fprofile-generate=
@@ -27,6 +30,7 @@
2730
// RUN: %run %t.merge3
2831
// RUN: %run %t.merge3
2932
// RUN: llvm-profdata merge -o %t.m3.profdata %t.dir3/
33+
// RUN: llvm-profdata show --all-functions %t.m3.profdata | FileCheck %s --check-prefix=PROFCNT
3034
// RUN: %clang_profuse=%t.m3.profdata -O0 -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=PGOMERGE
3135
//
3236
// Test that merging is enabled by default with -fprofile-generate
@@ -40,6 +44,7 @@
4044
// RUN: %run %t.dir4/merge4
4145
// RUN: rm -f %t.dir4/merge4*
4246
// RUN: llvm-profdata merge -o %t.m4.profdata ./
47+
// RUN: llvm-profdata show --all-functions %t.m4.profdata | FileCheck %s --check-prefix=PROFCNT
4348
// RUN: %clang_profuse=%t.m4.profdata -O0 -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=PGOMERGE
4449

4550
/// Test that the merge pool size can be larger than 10.
@@ -49,6 +54,13 @@
4954
// RUN: not ls %t.dir5/e_%20m.profraw
5055
// RUN: ls %t.dir5/e_*.profraw | count 1
5156

57+
// Test that all three functions have counters in the profile.
58+
// PROFCNT-DAG: begin
59+
// PROFCNT-DAG: end
60+
// PROFCNT-DAG: main
61+
// PROFCNT: Functions shown: 3
62+
// PROFCNT: Total functions: 3
63+
5264
int begin(int i) {
5365
// COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
5466
if (i)

0 commit comments

Comments
 (0)