Skip to content

Commit be9c54b

Browse files
committed
improve test
1 parent fcf877e commit be9c54b

File tree

2 files changed

+109
-87
lines changed

2 files changed

+109
-87
lines changed

lld/include/lld/Common/BPSectionOrdererBase.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
101101
// Merge sections that are nearly identical
102102
SmallVector<std::pair<unsigned, SmallVector<uint64_t>>> newSectionHashes;
103103
DenseMap<uint64_t, unsigned> wholeHashToSectionIdx;
104+
unsigned threshold = sectionHashes.size() > 10000 ? 5 : 0;
104105
for (auto &[sectionIdx, hashes] : sectionHashes) {
105106
uint64_t wholeHash = 0;
106107
for (auto hash : hashes)
107-
if (hashFrequency[hash] > 5)
108+
if (hashFrequency[hash] > threshold)
108109
wholeHash ^= hash;
109110
auto [it, wasInserted] =
110111
wholeHashToSectionIdx.insert(std::make_pair(wholeHash, sectionIdx));

lld/test/ELF/bp-section-orderer.s

Lines changed: 107 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,32 @@
2323
# STARTUP-FUNC-ORDER: Ordered 3 sections using balanced partitioning
2424
# STARTUP-FUNC-ORDER: Total area under the page fault curve: 3.
2525

26-
# RUN: ld.lld -o - a.o --symbol-ordering-file a.txt --irpgo-profile=a.profdata --bp-startup-sort=function | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE
27-
# RUN: ld.lld -o - a.o --symbol-ordering-file a.txt --bp-compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE
28-
29-
## Rodata
30-
# ORDERFILE: s2
31-
# ORDERFILE-NEXT: s1
32-
# ORDERFILE-NEXT: s3
33-
34-
## Functions
35-
# ORDERFILE-NEXT: A
36-
# ORDERFILE-NEXT: F
37-
# ORDERFILE-NEXT: E
38-
# ORDERFILE-NEXT: D
39-
# ORDERFILE-DAG: B
40-
# ORDERFILE-DAG: C
41-
# ORDERFILE-NEXT: _start
42-
43-
## Data
44-
# ORDERFILE-NEXT: r3
45-
# ORDERFILE-NEXT: r2
46-
# ORDERFILE-NEXT: r1
47-
# ORDERFILE-NEXT: r4
48-
49-
# RUN: ld.lld a.o --verbose-bp-section-orderer --bp-compression-sort=function 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-FUNC
50-
# RUN: ld.lld a.o --verbose-bp-section-orderer --bp-compression-sort=data 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-DATA
51-
# RUN: ld.lld a.o --verbose-bp-section-orderer --bp-compression-sort=both 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-BOTH
52-
# RUN: ld.lld a.o --verbose-bp-section-orderer --bp-compression-sort=both --irpgo-profile=a.profdata --bp-startup-sort=function 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-BOTH
26+
# RUN: ld.lld -o out.s a.o --irpgo-profile=a.profdata --bp-startup-sort=function
27+
# RUN: llvm-nm -jn out.s | tr '\n' , | FileCheck %s --check-prefix=STARTUP
28+
# STARTUP: s5,s4,s3,s2,s1,A,B,C,F,E,D,_start,d4,d3,d2,d1,
29+
30+
# RUN: ld.lld -o out.os a.o --irpgo-profile=a.profdata --bp-startup-sort=function --symbol-ordering-file a.txt
31+
# RUN: llvm-nm -jn out.os | tr '\n' , | FileCheck %s --check-prefix=ORDER-STARTUP
32+
# ORDER-STARTUP: s2,s1,s5,s4,s3,A,F,E,D,B,C,_start,d4,d3,d2,d1,
33+
34+
# RUN: ld.lld -o out.cf a.o --verbose-bp-section-orderer --bp-compression-sort=function 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-FUNC
35+
# RUN: llvm-nm -jn out.cf | tr '\n' , | FileCheck %s --check-prefix=CFUNC
36+
# CFUNC: s5,s4,s3,s2,s1,F,C,E,D,B,A,_start,d4,d3,d2,d1,
37+
38+
# RUN: ld.lld -o out.cd a.o --verbose-bp-section-orderer --bp-compression-sort=data 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-DATA
39+
# RUN: llvm-nm -jn out.cd | tr '\n' , | FileCheck %s --check-prefix=CDATA
40+
# CDATA: s4,s2,s1,s5,s3,F,C,E,D,B,A,_start,d4,d1,d3,d2,
41+
42+
# RUN: ld.lld -o out.cb a.o --verbose-bp-section-orderer --bp-compression-sort=both 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-BOTH
43+
# RUN: llvm-nm -jn out.cb | tr '\n' , | FileCheck %s --check-prefix=CDATA
44+
45+
# RUN: ld.lld -o out.cbs a.o --verbose-bp-section-orderer --bp-compression-sort=both --irpgo-profile=a.profdata --bp-startup-sort=function 2>&1 | FileCheck %s --check-prefix=BP-COMPRESSION-BOTH
46+
# RUN: llvm-nm -jn out.cbs | tr '\n' , | FileCheck %s --check-prefix=CBOTH-STARTUP
47+
# CBOTH-STARTUP: s4,s2,s1,s5,s3,A,B,C,F,E,D,_start,d4,d1,d3,d2,
5348

5449
# BP-COMPRESSION-FUNC: Ordered 7 sections using balanced partitioning
55-
# BP-COMPRESSION-DATA: Ordered 7 sections using balanced partitioning
56-
# BP-COMPRESSION-BOTH: Ordered 14 sections using balanced partitioning
50+
# BP-COMPRESSION-DATA: Ordered 9 sections using balanced partitioning
51+
# BP-COMPRESSION-BOTH: Ordered 16 sections using balanced partitioning
5752

5853
#--- a.proftext
5954
:ir
@@ -109,13 +104,15 @@ r3
109104
r2
110105

111106
#--- a.c
112-
const char s1[] = "hello world";
113-
const char s2[] = "i am a string";
114-
const char s3[] = "this is s3";
115-
const char *r1 = s1;
116-
const char **r2 = &r1;
117-
const char ***r3 = &r2;
118-
const char *r4 = s2;
107+
const char s5[] = "engineering";
108+
const char s4[] = "computer program";
109+
const char s3[] = "hardware engineer";
110+
const char s2[] = "computer software";
111+
const char s1[] = "hello world program";
112+
int d4[] = {1,2,3,4,5,6};
113+
int d3[] = {5,6,7,8};
114+
int d2[] = {7,8,9,10};
115+
int d1[] = {3,4,5,6};
119116

120117
int C(int a);
121118
int B(int a);
@@ -250,65 +247,89 @@ _start: // @_start
250247
.Lfunc_end6:
251248
.size _start, .Lfunc_end6-_start
252249
// -- End function
253-
.type s1,@object // @s1
254-
.section .rodata.s1,"a",@progbits
255-
.globl s1
256-
s1:
257-
.asciz "hello world"
258-
.size s1, 12
250+
.type s5,@object // @s5
251+
.section .rodata.s5,"a",@progbits
252+
.globl s5
253+
s5:
254+
.asciz "engineering"
255+
.size s5, 12
259256

260-
.type s2,@object // @s2
261-
.section .rodata.s2,"a",@progbits
262-
.globl s2
263-
s2:
264-
.asciz "i am a string"
265-
.size s2, 14
257+
.type s4,@object // @s4
258+
.section .rodata.s4,"a",@progbits
259+
.globl s4
260+
s4:
261+
.asciz "computer program"
262+
.size s4, 17
266263

267264
.type s3,@object // @s3
268265
.section .rodata.s3,"a",@progbits
269266
.globl s3
270267
s3:
271-
.asciz "this is s3"
272-
.size s3, 11
273-
274-
.type r1,@object // @r1
275-
.section .data.r1,"aw",@progbits
276-
.globl r1
277-
.p2align 3, 0x0
278-
r1:
279-
.xword s1
280-
.size r1, 8
281-
282-
.type r2,@object // @r2
283-
.section .data.r2,"aw",@progbits
284-
.globl r2
285-
.p2align 3, 0x0
286-
r2:
287-
.xword r1
288-
.size r2, 8
289-
290-
.type r3,@object // @r3
291-
.section .data.r3,"aw",@progbits
292-
.globl r3
293-
.p2align 3, 0x0
294-
r3:
295-
.xword r2
296-
.size r3, 8
297-
298-
.type r4,@object // @r4
299-
.section .data.r4,"aw",@progbits
300-
.globl r4
301-
.p2align 3, 0x0
302-
r4:
303-
.xword s2
304-
.size r4, 8
268+
.asciz "hardware engineer"
269+
.size s3, 18
270+
271+
.type s2,@object // @s2
272+
.section .rodata.s2,"a",@progbits
273+
.globl s2
274+
s2:
275+
.asciz "computer software"
276+
.size s2, 18
277+
278+
.type s1,@object // @s1
279+
.section .rodata.s1,"a",@progbits
280+
.globl s1
281+
s1:
282+
.asciz "hello world program"
283+
.size s1, 20
284+
285+
.type d4,@object // @d4
286+
.section .data.d4,"aw",@progbits
287+
.globl d4
288+
.p2align 2, 0x0
289+
d4:
290+
.word 1 // 0x1
291+
.word 2 // 0x2
292+
.word 3 // 0x3
293+
.word 4 // 0x4
294+
.word 5 // 0x5
295+
.word 6 // 0x6
296+
.size d4, 24
297+
298+
.type d3,@object // @d3
299+
.section .data.d3,"aw",@progbits
300+
.globl d3
301+
.p2align 2, 0x0
302+
d3:
303+
.word 5 // 0x5
304+
.word 6 // 0x6
305+
.word 7 // 0x7
306+
.word 8 // 0x8
307+
.size d3, 16
308+
309+
.type d2,@object // @d2
310+
.section .data.d2,"aw",@progbits
311+
.globl d2
312+
.p2align 2, 0x0
313+
d2:
314+
.word 7 // 0x7
315+
.word 8 // 0x8
316+
.word 9 // 0x9
317+
.word 10 // 0xa
318+
.size d2, 16
319+
320+
.type d1,@object // @d1
321+
.section .data.d1,"aw",@progbits
322+
.globl d1
323+
.p2align 2, 0x0
324+
d1:
325+
.word 3 // 0x3
326+
.word 4 // 0x4
327+
.word 5 // 0x5
328+
.word 6 // 0x6
329+
.size d1, 16
305330

306331
.section ".note.GNU-stack","",@progbits
307332
.addrsig
308333
.addrsig_sym C
309334
.addrsig_sym B
310335
.addrsig_sym A
311-
.addrsig_sym s1
312-
.addrsig_sym s2
313-
.addrsig_sym r1
314-
.addrsig_sym r2

0 commit comments

Comments
 (0)