Skip to content

Commit 39a1b28

Browse files
committed
[ELF] Improve ThinLTO tests
1 parent fcb8342 commit 39a1b28

File tree

2 files changed

+76
-68
lines changed

2 files changed

+76
-68
lines changed

lld/test/ELF/lto/cache.ll

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,106 @@
22
; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
33
; UNSUPPORTED: system-netbsd
44

5-
; RUN: opt -module-hash -module-summary %s -o %t.o
6-
; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
5+
; RUN: rm -rf %t && mkdir %t && cd %t
6+
; RUN: opt -module-hash -module-summary %s -o a.bc
7+
; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o b.bc
78

8-
; RUN: rm -Rf %t.cache && mkdir %t.cache
9+
; RUN: mkdir cache
910
; Create two files that would be removed by cache pruning due to age.
1011
; We should only remove files matching the pattern "llvmcache-*".
11-
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
12-
; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy prune_after=1h:prune_interval=0s -o %t3 %t2.o %t.o
12+
; RUN: touch -t 197001011200 cache/llvmcache-foo cache/foo
13+
; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy prune_after=1h:prune_interval=0s -o out b.bc a.bc
1314

1415
; Two cached objects, plus a timestamp file and "foo", minus the file we removed.
15-
; RUN: ls %t.cache | count 4
16+
; RUN: ls cache | count 4
1617

1718
; Create a file of size 64KB.
18-
; RUN: %python -c "print(' ' * 65536)" > %t.cache/llvmcache-foo
19+
; RUN: %python -c "print(' ' * 65536)" > cache/llvmcache-foo
1920

2021
; This should leave the file in place.
21-
; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=128k:prune_interval=0s -o %t3 %t2.o %t.o
22-
; RUN: ls %t.cache | count 5
22+
; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy cache_size_bytes=128k:prune_interval=0s -o out b.bc a.bc
23+
; RUN: ls cache | count 5
2324

2425
; Increase the age of llvmcache-foo, which will give it the oldest time stamp
2526
; so that it is processed and removed first.
26-
; RUN: %python -c 'import os,sys,time; t=time.time()-120; os.utime(sys.argv[1],(t,t))' %t.cache/llvmcache-foo
27+
; RUN: %python -c 'import os,sys,time; t=time.time()-120; os.utime(sys.argv[1],(t,t))' cache/llvmcache-foo
2728

2829
; This should remove it.
29-
; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=32k:prune_interval=0s -o %t3 %t2.o %t.o
30-
; RUN: ls %t.cache | count 4
30+
; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy cache_size_bytes=32k:prune_interval=0s -o out b.bc a.bc
31+
; RUN: ls cache | count 4
3132

3233
; Setting max number of files to 0 should disable the limit, not delete everything.
33-
; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy prune_after=0s:cache_size=0%:cache_size_files=0:prune_interval=0s -o %t3 %t2.o %t.o
34-
; RUN: ls %t.cache | count 4
34+
; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy prune_after=0s:cache_size=0%:cache_size_files=0:prune_interval=0s -o out b.bc a.bc
35+
; RUN: ls cache | count 4
3536

3637
; Delete everything except for the timestamp, "foo" and one cache file.
37-
; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy prune_after=0s:cache_size=0%:cache_size_files=1:prune_interval=0s -o %t3 %t2.o %t.o
38-
; RUN: ls %t.cache | count 3
38+
; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy prune_after=0s:cache_size=0%:cache_size_files=1:prune_interval=0s -o out b.bc a.bc
39+
; RUN: ls cache | count 3
3940

4041
; Check that we remove the least recently used file first.
41-
; RUN: rm -fr %t.cache && mkdir %t.cache
42-
; RUN: echo xyz > %t.cache/llvmcache-old
43-
; RUN: touch -t 198002011200 %t.cache/llvmcache-old
44-
; RUN: echo xyz > %t.cache/llvmcache-newer
45-
; RUN: touch -t 198002021200 %t.cache/llvmcache-newer
46-
; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy prune_after=0s:cache_size=0%:cache_size_files=3:prune_interval=0s -o %t3 %t2.o %t.o
47-
; RUN: ls %t.cache | FileCheck %s
42+
; RUN: rm -fr cache && mkdir cache
43+
; RUN: echo xyz > cache/llvmcache-old
44+
; RUN: touch -t 198002011200 cache/llvmcache-old
45+
; RUN: echo xyz > cache/llvmcache-newer
46+
; RUN: touch -t 198002021200 cache/llvmcache-newer
47+
; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy prune_after=0s:cache_size=0%:cache_size_files=3:prune_interval=0s -o out b.bc a.bc
48+
; RUN: ls cache | FileCheck %s
4849

4950
; CHECK-NOT: llvmcache-old
5051
; CHECK: llvmcache-newer
5152
; CHECK-NOT: llvmcache-old
5253

54+
; RUN: rm -fr cache && mkdir cache
55+
; RUN: ld.lld --thinlto-cache-dir=cache --save-temps -o out b.bc a.bc -M | FileCheck %s --check-prefix=MAP
56+
; RUN: ls out1.lto.o a.bc.0.preopt.bc b.bc.0.preopt.bc
57+
58+
; MAP: llvmcache-{{.*}}:(.text)
59+
; MAP: llvmcache-{{.*}}:(.text)
60+
5361
;; Check that mllvm options participate in the cache key
54-
; RUN: rm -rf %t.cache && mkdir %t.cache
55-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o
56-
; RUN: ls %t.cache | count 3
57-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
58-
; RUN: ls %t.cache | count 5
62+
; RUN: rm -rf cache && mkdir cache
63+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc
64+
; RUN: ls cache | count 3
65+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
66+
; RUN: ls cache | count 5
5967

6068
;; Adding another option resuls in 2 more cache entries
61-
; RUN: rm -rf %t.cache && mkdir %t.cache
62-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o
63-
; RUN: ls %t.cache | count 3
64-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
65-
; RUN: ls %t.cache | count 5
66-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
67-
; RUN: ls %t.cache | count 7
69+
; RUN: rm -rf cache && mkdir cache
70+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc
71+
; RUN: ls cache | count 3
72+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
73+
; RUN: ls cache | count 5
74+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
75+
; RUN: ls cache | count 7
6876

6977
;; Changing order may matter - e.g. if overriding -mllvm options - so we get 2 more entries
70-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -max-devirt-iterations=1 -mllvm -enable-ml-inliner=default
71-
; RUN: ls %t.cache | count 9
78+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -max-devirt-iterations=1 -mllvm -enable-ml-inliner=default
79+
; RUN: ls cache | count 9
7280

7381
;; Going back to a pre-cached order doesn't create more entries.
74-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
75-
; RUN: ls %t.cache | count 9
82+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
83+
; RUN: ls cache | count 9
7684

7785
;; Different flag values matter
78-
; RUN: rm -rf %t.cache && mkdir %t.cache
79-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=2
80-
; RUN: ls %t.cache | count 3
81-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
82-
; RUN: ls %t.cache | count 5
86+
; RUN: rm -rf cache && mkdir cache
87+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=2
88+
; RUN: ls cache | count 3
89+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
90+
; RUN: ls cache | count 5
8391

8492
;; Same flag value passed to different flags matters, and switching the order
8593
;; of the two flags matters.
86-
; RUN: rm -rf %t.cache && mkdir %t.cache
87-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
88-
; RUN: ls %t.cache | count 3
89-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -emit-dwarf-unwind=default
90-
; RUN: ls %t.cache | count 5
91-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
92-
; RUN: ls %t.cache | count 5
93-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -emit-dwarf-unwind=default
94-
; RUN: ls %t.cache | count 7
95-
; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -emit-dwarf-unwind=default -mllvm -enable-ml-inliner=default
96-
; RUN: ls %t.cache | count 9
94+
; RUN: rm -rf cache && mkdir cache
95+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
96+
; RUN: ls cache | count 3
97+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -emit-dwarf-unwind=default
98+
; RUN: ls cache | count 5
99+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
100+
; RUN: ls cache | count 5
101+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -emit-dwarf-unwind=default
102+
; RUN: ls cache | count 7
103+
; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -emit-dwarf-unwind=default -mllvm -enable-ml-inliner=default
104+
; RUN: ls cache | count 9
97105

98106
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
99107
target triple = "x86_64-unknown-linux-gnu"

lld/test/ELF/lto/thinlto.ll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,66 @@
33
; Basic ThinLTO tests.
44
; RUN: rm -rf %t && mkdir %t && cd %t
55
; RUN: mkdir d e
6-
; RUN: opt -module-summary %s -o 1.o
7-
; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/2.o
6+
; RUN: opt -module-summary %s -o a.o
7+
; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/b.o
88

99
; First force single-threaded mode
1010
; RUN: rm -f e/out1.lto.o e/out2.lto.o
11-
; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared 1.o d/2.o -o e/out
11+
; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared a.o d/b.o -o e/out
1212
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
1313
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
1414

1515
; Next force multi-threaded mode
1616
; RUN: rm -f e/out1.lto.o e/out2.lto.o
17-
; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared 1.o d/2.o -o e/out
17+
; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared a.o d/b.o -o e/out
1818
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
1919
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
2020

2121
;; --plugin-opt=jobs= is an alias.
2222
; RUN: rm -f e/out1.lto.o e/out2.lto.o
23-
; RUN: ld.lld -save-temps --plugin-opt=jobs=2 -shared 1.o d/2.o -o e/out
23+
; RUN: ld.lld -save-temps --plugin-opt=jobs=2 -shared a.o d/b.o -o e/out
2424
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
2525
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
2626

2727
;; --thinlto-jobs= defaults to --threads=.
2828
; RUN: rm -f e/out1.lto.o e/out2.lto.o
29-
; RUN: ld.lld -save-temps --threads=2 -shared 1.o d/2.o -o e/out
29+
; RUN: ld.lld -save-temps --threads=2 -shared a.o d/b.o -o e/out
3030
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
3131
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
3232

3333
;; --thinlto-jobs= overrides --threads=.
3434
; RUN: rm -f e/out1.lto.o e/out2.lto.o
35-
; RUN: ld.lld -save-temps --threads=1 --plugin-opt=jobs=2 -shared 1.o d/2.o -o e/out
35+
; RUN: ld.lld -save-temps --threads=1 --plugin-opt=jobs=2 -shared a.o d/b.o -o e/out
3636
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
3737
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
3838

3939
; Test with all threads, on all cores, on all CPU sockets
4040
; RUN: rm -f e/out1.lto.o e/out2.lto.o
41-
; RUN: ld.lld -save-temps --thinlto-jobs=all -shared 1.o d/2.o -o e/out
41+
; RUN: ld.lld -save-temps --thinlto-jobs=all -shared a.o d/b.o -o e/out
4242
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
4343
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
4444

4545
; Test with many more threads than the system has
4646
; RUN: rm -f e/out1.lto.o e/out2.lto.o
47-
; RUN: ld.lld -save-temps --thinlto-jobs=100 -shared 1.o d/2.o -o e/out
47+
; RUN: ld.lld -save-temps --thinlto-jobs=100 -shared a.o d/b.o -o e/out
4848
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
4949
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
5050

5151
; Test with a bad value
5252
; RUN: rm -f e/out1.lto.o e/out2.lto.o
53-
; RUN: not ld.lld -save-temps --thinlto-jobs=foo -shared 1.o d/2.o -o e/out 2>&1 | FileCheck %s --check-prefix=BAD-JOBS
53+
; RUN: not ld.lld -save-temps --thinlto-jobs=foo -shared a.o d/b.o -o e/out 2>&1 | FileCheck %s --check-prefix=BAD-JOBS
5454
; BAD-JOBS: error: --thinlto-jobs: invalid job count: foo
5555

5656
; Then check without --thinlto-jobs (which currently defaults to heavyweight_hardware_concurrency, meanning one thread per hardware core -- not SMT)
57-
; RUN: ld.lld -shared -save-temps 1.o d/2.o -o e/out
57+
; RUN: ld.lld -shared -save-temps a.o d/b.o -o e/out
5858
; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
5959
; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
6060

6161
; Check that -save-temps is usable with thin archives
6262
; RUN: mkdir dir
63-
; RUN: cp d/2.o dir/t.o
63+
; RUN: cp d/b.o dir/t.o
6464
; RUN: llvm-ar rcsT dir/t.a dir/t.o
65-
; RUN: ld.lld -save-temps 1.o dir/t.a -o %t.null
65+
; RUN: ld.lld -save-temps a.o dir/t.a -o %t.null
6666
; RUN: ls dir/t.a*.0.preopt.bc
6767

6868
; NM1: T f

0 commit comments

Comments
 (0)