Skip to content

Commit b399924

Browse files
add test data and flag-gated fix for pull request 76312
1 parent 3c10e5b commit b399924

8 files changed

+160
-1
lines changed

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
using namespace llvm;
4040

41+
static cl::opt<bool> SwapFuncPointer("swap-func-ptr", cl::init(false));
42+
4143
// Extracts the variant information from the top 32 bits in the version and
4244
// returns an enum specifying the variants present.
4345
static InstrProfKind getProfileKindFromVersion(uint64_t Version) {
@@ -539,7 +541,7 @@ Error RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {
539541
const IntPtrT FPtr = swap(I->FunctionPointer);
540542
if (!FPtr)
541543
continue;
542-
Symtab.mapAddress(FPtr, I->NameRef);
544+
Symtab.mapAddress(FPtr, SwapFuncPointer ? swap(I->NameRef) : I->NameRef);
543545
}
544546
return success();
545547
}

testdata/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
```
3+
./bin/llvm-profdata show --function=_Z11global_funcv -ic-targets ../testdata/thinlto_indirect_call_promotion_bigendian.profraw
4+
Counters:
5+
_Z11global_funcv:
6+
Hash: 0x07deb612ffffffff
7+
Counters: 1
8+
Indirect Call Site Count: 2
9+
Indirect Target Results:
10+
[ 0, , 1 ] (100.00%)
11+
[ 1, , 1 ] (100.00%)
12+
Instrumentation level: IR entry_first = 0
13+
Functions shown: 1
14+
Total functions: 4
15+
Maximum function count: 1
16+
Maximum internal block count: 0
17+
Statistics for indirect call sites profile:
18+
Total number of sites: 2
19+
Total number of sites with values: 2
20+
Total number of profiled values: 2
21+
Value sites histogram:
22+
NumTargets, SiteCount
23+
1, 2
24+
```
25+
26+
27+
```
28+
./bin/llvm-profdata show --function=_Z11global_funcv -ic-targets -swap-func-ptr ../testdata/thinlto_indirect_call_promotion_bigendian.profraw
29+
Counters:
30+
_Z11global_funcv:
31+
Hash: 0x07deb612ffffffff
32+
Counters: 1
33+
Indirect Call Site Count: 2
34+
Indirect Target Results:
35+
[ 0, lib.cc;_ZL7callee0v, 1 ] (100.00%)
36+
[ 1, _Z7callee1v, 1 ] (100.00%)
37+
Instrumentation level: IR entry_first = 0
38+
Functions shown: 1
39+
Total functions: 4
40+
Maximum function count: 1
41+
Maximum internal block count: 0
42+
Statistics for indirect call sites profile:
43+
Total number of sites: 2
44+
Total number of sites with values: 2
45+
Total number of profiled values: 2
46+
Value sites histogram:
47+
NumTargets, SiteCount
48+
1, 2
49+
```
50+

testdata/src/bigprof.text

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ff6c70726f667281010000000000000900000000000000000000000000000004000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000043ffffffffffffffe0ffffaa23e2bbe748000055dc1d436eb30000000000000001c893b0fd20b3ea110a4d0ad3efffffffffffffffffffffe00000000000000000000055dc1d4399100000000000000000000000010000000000000000000000007c2cd54c6c33995b0a4d0ad3efffffffffffffffffffffa80000000000000000000055dc1d439920000000000000000000000001000000000000000000000000df6ec2613a2825d507deb612ffffffffffffffffffffff700000000000000000000055dc1d439930000055dc1d4419b800000001000200000000000000000000db956436e78dd5fa0a4d0ad3efffffffffffffffffffff380000000000000000000055dc1d4399800000000000000000000000010000000000000000000000000000000000000001000000000000000100000000000000010000000000000001303378da8b8f324f4eccc9494d352c63ccc94cd24b4eb68e8ff2818a199431c647191aa6e7e42725e6c4a795e6259701008f7c10bb040c78dacb4dcccc0300041b01a60000000000000000380000000100000000000000020101000000000000000055dc1d4399200000000000000001000055dc1d4399100000000000000001

testdata/src/print.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <stdint.h>
4+
5+
int main() {
6+
FILE* r = fopen("bigprof.profraw", "r");
7+
8+
FILE* w = fopen("bigendian.profout", "wb");
9+
10+
char buffer[5000];
11+
12+
size_t numread = fread(buffer, sizeof(unsigned char), 5000, r);
13+
printf("numread is %zu\n", numread);
14+
15+
int i = 0;
16+
for (i = 0; i < numread; i += 2) {
17+
char hex[5]="0x";
18+
hex[2] = buffer[i];
19+
if (i + 1 < numread) {
20+
hex[3] = buffer[i + 1];
21+
hex[4] = '\0';
22+
} else {
23+
hex[3] = '\0';
24+
}
25+
printf("hex string is %s\n", hex);
26+
int n = strtol(hex, NULL, 16);
27+
uint8_t val = n;
28+
printf("Number %o\n", val);
29+
fwrite(&val, 1, 1, w);
30+
}
31+
printf("numread is %zu\n", numread);
32+
33+
fclose(r);
34+
fclose(w);
35+
36+
return 0;
37+
}
38+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
00000000 ff 6c 70 72 6f 66 72 81 01 00 00 00 00 00 00 09 |.lprofr.........|
2+
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 |................|
3+
*
4+
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
5+
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 |...............C|
6+
00000050 ff ff ff ff ff ff ff e0 ff ff aa 23 e2 bb e7 48 |...........#...H|
7+
00000060 00 00 55 dc 1d 43 6e b3 00 00 00 00 00 00 00 01 |..U..Cn.........|
8+
00000070 c8 93 b0 fd 20 b3 ea 11 0a 4d 0a d3 ef ff ff ff |.... ....M......|
9+
00000080 ff ff ff ff ff ff ff e0 00 00 00 00 00 00 00 00 |................|
10+
00000090 00 00 55 dc 1d 43 99 10 00 00 00 00 00 00 00 00 |..U..C..........|
11+
000000a0 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 |................|
12+
000000b0 7c 2c d5 4c 6c 33 99 5b 0a 4d 0a d3 ef ff ff ff ||,.Ll3.[.M......|
13+
000000c0 ff ff ff ff ff ff ff a8 00 00 00 00 00 00 00 00 |................|
14+
000000d0 00 00 55 dc 1d 43 99 20 00 00 00 00 00 00 00 00 |..U..C. ........|
15+
000000e0 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 |................|
16+
000000f0 df 6e c2 61 3a 28 25 d5 07 de b6 12 ff ff ff ff |.n.a:(%.........|
17+
00000100 ff ff ff ff ff ff ff 70 00 00 00 00 00 00 00 00 |.......p........|
18+
00000110 00 00 55 dc 1d 43 99 30 00 00 55 dc 1d 44 19 b8 |..U..C.0..U..D..|
19+
00000120 00 00 00 01 00 02 00 00 00 00 00 00 00 00 00 00 |................|
20+
00000130 db 95 64 36 e7 8d d5 fa 0a 4d 0a d3 ef ff ff ff |..d6.....M......|
21+
00000140 ff ff ff ff ff ff ff 38 00 00 00 00 00 00 00 00 |.......8........|
22+
00000150 00 00 55 dc 1d 43 99 80 00 00 00 00 00 00 00 00 |..U..C..........|
23+
00000160 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 |................|
24+
00000170 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 |................|
25+
*
26+
00000190 30 33 78 da 8b 8f 32 4f 4e cc c9 49 4d 35 2c 63 |03x...2ON..IM5,c|
27+
000001a0 cc c9 4c d2 4b 4e b6 8e 8f f2 81 8a 19 94 31 c6 |..L.KN........1.|
28+
000001b0 47 19 1a a6 e7 e4 27 25 e6 c4 a7 95 e6 25 97 01 |G.....'%.....%..|
29+
000001c0 00 8f 7c 10 bb 04 0c 78 da cb 4d cc cc 03 00 04 |..|....x..M.....|
30+
000001d0 1b 01 a6 00 00 00 00 00 00 00 00 38 00 00 00 01 |...........8....|
31+
000001e0 00 00 00 00 00 00 00 02 01 01 00 00 00 00 00 00 |................|
32+
000001f0 00 00 55 dc 1d 43 99 20 00 00 00 00 00 00 00 01 |..U..C. ........|
33+
00000200 00 00 55 dc 1d 43 99 10 00 00 00 00 00 00 00 01 |..U..C..........|
34+
00000210
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
00000000 81 72 66 6f 72 70 6c ff 09 00 00 00 00 00 00 01 |.rforpl.........|
2+
00000010 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 |................|
3+
*
4+
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
5+
00000040 00 00 00 00 00 00 00 00 43 00 00 00 00 00 00 00 |........C.......|
6+
00000050 e0 ff ff ff ff ff ff ff 48 e7 bb e2 23 aa ff ff |........H...#...|
7+
00000060 b3 6e 43 1d dc 55 00 00 01 00 00 00 00 00 00 00 |.nC..U..........|
8+
00000070 11 ea b3 20 fd b0 93 c8 ff ff ff ef d3 0a 4d 0a |... ..........M.|
9+
00000080 e0 ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |................|
10+
00000090 10 99 43 1d dc 55 00 00 00 00 00 00 00 00 00 00 |..C..U..........|
11+
000000a0 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
12+
000000b0 5b 99 33 6c 4c d5 2c 7c ff ff ff ef d3 0a 4d 0a |[.3lL.,|......M.|
13+
000000c0 a8 ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |................|
14+
000000d0 20 99 43 1d dc 55 00 00 00 00 00 00 00 00 00 00 | .C..U..........|
15+
000000e0 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
16+
000000f0 d5 25 28 3a 61 c2 6e df ff ff ff ff 12 b6 de 07 |.%(:a.n.........|
17+
00000100 70 ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |p...............|
18+
00000110 30 99 43 1d dc 55 00 00 b8 19 44 1d dc 55 00 00 |0.C..U....D..U..|
19+
00000120 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 |................|
20+
00000130 fa d5 8d e7 36 64 95 db ff ff ff ef d3 0a 4d 0a |....6d........M.|
21+
00000140 38 ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |8...............|
22+
00000150 80 99 43 1d dc 55 00 00 00 00 00 00 00 00 00 00 |..C..U..........|
23+
00000160 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
24+
00000170 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 |................|
25+
*
26+
00000190 30 33 78 da 8b 8f 32 4f 4e cc c9 49 4d 35 2c 63 |03x...2ON..IM5,c|
27+
000001a0 cc c9 4c d2 4b 4e b6 8e 8f f2 81 8a 19 94 31 c6 |..L.KN........1.|
28+
000001b0 47 19 1a a6 e7 e4 27 25 e6 c4 a7 95 e6 25 97 01 |G.....'%.....%..|
29+
000001c0 00 8f 7c 10 bb 04 0c 78 da cb 4d cc cc 03 00 04 |..|....x..M.....|
30+
000001d0 1b 01 a6 00 00 00 00 00 38 00 00 00 01 00 00 00 |........8.......|
31+
000001e0 00 00 00 00 02 00 00 00 01 01 00 00 00 00 00 00 |................|
32+
000001f0 20 99 43 1d dc 55 00 00 01 00 00 00 00 00 00 00 | .C..U..........|
33+
00000200 10 99 43 1d dc 55 00 00 01 00 00 00 00 00 00 00 |..C..U..........|
34+
00000210
528 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)