Skip to content

Commit 5af27f8

Browse files
authored
[InstrProf] Fix frontend generated function hash (#165358)
1 parent d1387ed commit 5af27f8

File tree

18 files changed

+38
-27
lines changed

18 files changed

+38
-27
lines changed

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ enum PGOHashVersion : unsigned {
5858
PGO_HASH_V1,
5959
PGO_HASH_V2,
6060
PGO_HASH_V3,
61+
PGO_HASH_V4,
6162

6263
// Keep this set to the latest hash version.
63-
PGO_HASH_LATEST = PGO_HASH_V3
64+
PGO_HASH_LATEST = PGO_HASH_V4
6465
};
6566

6667
namespace {
@@ -152,7 +153,9 @@ static PGOHashVersion getPGOHashVersion(llvm::IndexedInstrProfReader *PGOReader,
152153
return PGO_HASH_V1;
153154
if (PGOReader->getVersion() <= 5)
154155
return PGO_HASH_V2;
155-
return PGO_HASH_V3;
156+
if (PGOReader->getVersion() <= 12)
157+
return PGO_HASH_V3;
158+
return PGO_HASH_V4;
156159
}
157160

158161
/// A RecursiveASTVisitor that fills a map of statements to PGO counters.
@@ -1099,6 +1102,8 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
10991102
assert(Walker.NextCounter > 0 && "no entry counter mapped for decl");
11001103
NumRegionCounters = Walker.NextCounter;
11011104
FunctionHash = Walker.Hash.finalize();
1105+
if (HashVersion >= PGO_HASH_V4)
1106+
FunctionHash &= llvm::NamedInstrProfRecord::FUNC_HASH_MASK;
11021107
}
11031108

11041109
bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {

clang/test/Profile/Inputs/c-counter-overflows.proftext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
main
2-
7779561829442898616
2+
862032801801816760
33
8
44
1
55
68719476720
2.55 KB
Binary file not shown.

clang/test/Profile/Inputs/c-general.proftext

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ simple_loops
77
75
88

99
conditionals
10-
4904767535850050386
10+
293081517422662482
1111
13
1212
1
1313
100
@@ -24,7 +24,7 @@ conditionals
2424
1
2525

2626
early_exits
27-
2880354649761471549
27+
574511640547777597
2828
9
2929
1
3030
0
@@ -37,7 +37,7 @@ early_exits
3737
0
3838

3939
jumps
40-
15051420506203462683
40+
63440946314451995
4141
22
4242
1
4343
1
@@ -86,7 +86,7 @@ switches
8686
0
8787

8888
big_switch
89-
13144136522122330070
89+
461999971447013334
9090
17
9191
1
9292
32
@@ -125,7 +125,7 @@ boolean_operators
125125
33
126126

127127
boolop_loops
128-
12402604614320574815
128+
873389568252105055
129129
13
130130
1
131131
50
@@ -149,7 +149,7 @@ conditional_operator
149149
1
150150

151151
do_fallthrough
152-
8714614136504380050
152+
644163604256451218
153153
4
154154
1
155155
10

clang/test/Profile/Inputs/c-unprofiled-blocks.proftext

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
never_called
2-
6820425066224770721
2+
1055817543190535841
33
9
44
0
55
0
@@ -17,7 +17,7 @@ main
1717
1
1818

1919
dead_code
20-
5254464978620792806
20+
642778960193404902
2121
10
2222
1
2323
0

clang/test/Profile/Inputs/cxx-rangefor.proftext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_Z9range_forv
2-
8789831523895825398
2+
719380991647896566
33
5
44
1
55
4

clang/test/Profile/Inputs/cxx-throws.proftext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_Z6throwsv
2-
18172607911962830854
2+
878785342860126214
33
9
44
1
55
100

clang/test/Profile/Inputs/misexpect-switch-default.proftext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
main
22
# Func Hash:
3-
8734802134600123338
3+
664351602352194506
44
# Num Counters:
55
9
66
# Counter Values:

clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
main
22
# Func Hash:
3-
3721743393642630379
3+
262978879822089451
44
# Num Counters:
55
10
66
# Counter Values:

clang/test/Profile/c-collision.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// RUN: %clang_cc1 -UEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-NOEXTRA
33
// RUN: %clang_cc1 -DEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-EXTRA
44

5-
// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 7156072912471487002,
6-
// CHECK-EXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 -4383447408116050035,
5+
// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 238543884830405146,
6+
// CHECK-EXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 228238610311337869,
77

88
extern int bar;
99
void foo(void) {

0 commit comments

Comments
 (0)