Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InstrProf] Add options to profile function groups
Add two options, `-fprofile-function-groups=N` and `-fprofile-selected-function-group=i` used to partition functions into `N` groups and only instrument the functions in group `i`. Similar options were added to xray in https://reviews.llvm.org/D87953 and the goal is the same; to reduce instrumented size overhead by spreading the overhead across multiple builds. Raw profiles from different groups can be added like normal using the `llvm-profdata merge` command. Reviewed By: ianlevesque Differential Revision: https://reviews.llvm.org/D129594
- Loading branch information
Showing
10 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=0 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT0 | ||
// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=1 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT1 | ||
// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=2 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT2 | ||
|
||
// Group 0 | ||
// SELECT0-NOT: noprofile | ||
// SELECT1: noprofile | ||
// SELECT2: noprofile | ||
// CHECK: define {{.*}} @hoo() | ||
void hoo() {} | ||
|
||
// Group 1 | ||
// SELECT0: noprofile | ||
// SELECT1-NOT: noprofile | ||
// SELECT2: noprofile | ||
// CHECK: define {{.*}} @goo() | ||
void goo() {} | ||
|
||
// Group 2 | ||
// SELECT0: noprofile | ||
// SELECT1: noprofile | ||
// SELECT2-NOT: noprofile | ||
// CHECK: define {{.*}} @boo() | ||
void boo() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=0 %s -o %t.0.out | ||
// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=1 %s -o %t.1.out | ||
// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=2 %s -o %t.2.out | ||
// RUN: env LLVM_PROFILE_FILE=%t.0.profraw %run %t.0.out | ||
// RUN: env LLVM_PROFILE_FILE=%t.1.profraw %run %t.1.out | ||
// RUN: env LLVM_PROFILE_FILE=%t.2.profraw %run %t.2.out | ||
// RUN: llvm-profdata merge -o %t.profdata %t.*.profraw | ||
// RUN: llvm-profdata show %t.profdata --all-functions | FileCheck %s | ||
|
||
int foo(int i) { return 4 * i + 1; } | ||
int bar(int i) { return 4 * i + 2; } | ||
int goo(int i) { return 4 * i + 3; } | ||
|
||
int main(int argc, char *argv[]) { | ||
foo(5); | ||
bar(6); | ||
goo(7); | ||
return 0; | ||
} | ||
|
||
// Even though we ran this code three times, we expect all counts to be one if | ||
// functions were partitioned into groups correctly. | ||
|
||
// CHECK: Counters: 1 | ||
// CHECK: Counters: 1 | ||
// CHECK: Counters: 1 | ||
// CHECK: Counters: 1 | ||
// CHECK: Total functions: 4 |