xref: /llvm-project/lld/test/ELF/lto/cache.ll (revision f7669ba3d9443bc95dd63fa25beea13e6265fdc5)
1; REQUIRES: x86
2; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
3; UNSUPPORTED: system-netbsd
4
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
8
9; RUN: mkdir cache
10; Create two files that would be removed by cache pruning due to age.
11; We should only remove files matching the pattern "llvmcache-*".
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
14
15; Two cached objects, plus a timestamp file and "foo", minus the file we removed.
16; RUN: ls cache | count 4
17
18; Create a file of size 64KB.
19; RUN: %python -c "print(' ' * 65536)" > cache/llvmcache-foo
20
21; This should leave the file in place.
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
24
25; Increase the age of llvmcache-foo, which will give it the oldest time stamp
26; so that it is processed and removed first.
27; RUN: %python -c 'import os,sys,time; t=time.time()-120; os.utime(sys.argv[1],(t,t))' cache/llvmcache-foo
28
29; This should remove it.
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
32
33; Setting max number of files to 0 should disable the limit, not delete everything.
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
36
37; Delete everything except for the timestamp, "foo" and one cache file.
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
40
41; Check that we remove the least recently used file first.
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
49
50; CHECK-NOT: llvmcache-old
51; CHECK: llvmcache-newer
52; CHECK-NOT: llvmcache-old
53
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 out.lto.a.o a.bc.0.preopt.bc b.bc.0.preopt.bc
57
58; MAP: out.lto.b.o:(.text)
59; MAP: out.lto.a.o:(.text)
60
61;; Check that mllvm options participate in the cache key
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
67
68;; Adding another option resuls in 2 more cache entries
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
76
77;; Changing order may matter - e.g. if overriding -mllvm options - so we get 2 more entries
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
80
81;; Going back to a pre-cached order doesn't create more entries.
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
84
85;; Different flag values matter
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
91
92;; Same flag value passed to different flags matters, and switching the order
93;; of the two flags matters.
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
105
106target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
107target triple = "x86_64-unknown-linux-gnu"
108
109define void @globalfunc() #0 {
110entry:
111  ret void
112}
113