[lld] 39a1b28 - [ELF] Improve ThinLTO tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 22:51:49 PST 2024


Author: Fangrui Song
Date: 2024-01-22T22:51:44-08:00
New Revision: 39a1b280a170ff8e0e605693f8386b8dd161cf94

URL: https://github.com/llvm/llvm-project/commit/39a1b280a170ff8e0e605693f8386b8dd161cf94
DIFF: https://github.com/llvm/llvm-project/commit/39a1b280a170ff8e0e605693f8386b8dd161cf94.diff

LOG: [ELF] Improve ThinLTO tests

Added: 
    

Modified: 
    lld/test/ELF/lto/cache.ll
    lld/test/ELF/lto/thinlto.ll

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/lto/cache.ll b/lld/test/ELF/lto/cache.ll
index 603bfce3bc12af1..95c68ab2315e6b3 100644
--- a/lld/test/ELF/lto/cache.ll
+++ b/lld/test/ELF/lto/cache.ll
@@ -2,98 +2,106 @@
 ; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
 ; UNSUPPORTED: system-netbsd
 
-; RUN: opt -module-hash -module-summary %s -o %t.o
-; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
+; RUN: rm -rf %t && mkdir %t && cd %t
+; RUN: opt -module-hash -module-summary %s -o a.bc
+; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o b.bc
 
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: mkdir cache
 ; Create two files that would be removed by cache pruning due to age.
 ; We should only remove files matching the pattern "llvmcache-*".
-; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
-; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy prune_after=1h:prune_interval=0s -o %t3 %t2.o %t.o
+; RUN: touch -t 197001011200 cache/llvmcache-foo cache/foo
+; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy prune_after=1h:prune_interval=0s -o out b.bc a.bc
 
 ; Two cached objects, plus a timestamp file and "foo", minus the file we removed.
-; RUN: ls %t.cache | count 4
+; RUN: ls cache | count 4
 
 ; Create a file of size 64KB.
-; RUN: %python -c "print(' ' * 65536)" > %t.cache/llvmcache-foo
+; RUN: %python -c "print(' ' * 65536)" > cache/llvmcache-foo
 
 ; This should leave the file in place.
-; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=128k:prune_interval=0s -o %t3 %t2.o %t.o
-; RUN: ls %t.cache | count 5
+; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy cache_size_bytes=128k:prune_interval=0s -o out b.bc a.bc
+; RUN: ls cache | count 5
 
 ; Increase the age of llvmcache-foo, which will give it the oldest time stamp
 ; so that it is processed and removed first.
-; RUN: %python -c 'import os,sys,time; t=time.time()-120; os.utime(sys.argv[1],(t,t))' %t.cache/llvmcache-foo
+; RUN: %python -c 'import os,sys,time; t=time.time()-120; os.utime(sys.argv[1],(t,t))' cache/llvmcache-foo
 
 ; This should remove it.
-; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=32k:prune_interval=0s -o %t3 %t2.o %t.o
-; RUN: ls %t.cache | count 4
+; RUN: ld.lld --thinlto-cache-dir=cache --thinlto-cache-policy cache_size_bytes=32k:prune_interval=0s -o out b.bc a.bc
+; RUN: ls cache | count 4
 
 ; Setting max number of files to 0 should disable the limit, not delete everything.
-; 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
-; RUN: ls %t.cache | count 4
+; 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
+; RUN: ls cache | count 4
 
 ; Delete everything except for the timestamp, "foo" and one cache file.
-; 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
-; RUN: ls %t.cache | count 3
+; 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
+; RUN: ls cache | count 3
 
 ; Check that we remove the least recently used file first.
-; RUN: rm -fr %t.cache && mkdir %t.cache
-; RUN: echo xyz > %t.cache/llvmcache-old
-; RUN: touch -t 198002011200 %t.cache/llvmcache-old
-; RUN: echo xyz > %t.cache/llvmcache-newer
-; RUN: touch -t 198002021200 %t.cache/llvmcache-newer
-; 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
-; RUN: ls %t.cache | FileCheck %s
+; RUN: rm -fr cache && mkdir cache
+; RUN: echo xyz > cache/llvmcache-old
+; RUN: touch -t 198002011200 cache/llvmcache-old
+; RUN: echo xyz > cache/llvmcache-newer
+; RUN: touch -t 198002021200 cache/llvmcache-newer
+; 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
+; RUN: ls cache | FileCheck %s
 
 ; CHECK-NOT: llvmcache-old
 ; CHECK: llvmcache-newer
 ; CHECK-NOT: llvmcache-old
 
+; RUN: rm -fr cache && mkdir cache
+; RUN: ld.lld --thinlto-cache-dir=cache --save-temps -o out b.bc a.bc -M | FileCheck %s --check-prefix=MAP
+; RUN: ls out1.lto.o a.bc.0.preopt.bc b.bc.0.preopt.bc
+
+; MAP: llvmcache-{{.*}}:(.text)
+; MAP: llvmcache-{{.*}}:(.text)
+
 ;; Check that mllvm options participate in the cache key
-; RUN: rm -rf %t.cache && mkdir %t.cache
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o
-; RUN: ls %t.cache | count 3
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
-; RUN: ls %t.cache | count 5
+; RUN: rm -rf cache && mkdir cache
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc
+; RUN: ls cache | count 3
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
+; RUN: ls cache | count 5
 
 ;; Adding another option resuls in 2 more cache entries
-; RUN: rm -rf %t.cache && mkdir %t.cache
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o
-; RUN: ls %t.cache | count 3
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
-; RUN: ls %t.cache | count 5
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
-; RUN: ls %t.cache | count 7
+; RUN: rm -rf cache && mkdir cache
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc
+; RUN: ls cache | count 3
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
+; RUN: ls cache | count 5
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
+; RUN: ls cache | count 7
 
 ;; Changing order may matter - e.g. if overriding -mllvm options - so we get 2 more entries
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -max-devirt-iterations=1 -mllvm -enable-ml-inliner=default
-; RUN: ls %t.cache | count 9
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -max-devirt-iterations=1 -mllvm -enable-ml-inliner=default
+; RUN: ls cache | count 9
 
 ;; Going back to a pre-cached order doesn't create more entries.
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
-; RUN: ls %t.cache | count 9
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
+; RUN: ls cache | count 9
 
 ;; Different flag values matter
-; RUN: rm -rf %t.cache && mkdir %t.cache
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=2
-; RUN: ls %t.cache | count 3
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
-; RUN: ls %t.cache | count 5
+; RUN: rm -rf cache && mkdir cache
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=2
+; RUN: ls cache | count 3
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
+; RUN: ls cache | count 5
 
 ;; Same flag value passed to 
diff erent flags matters, and switching the order
 ;; of the two flags matters.
-; RUN: rm -rf %t.cache && mkdir %t.cache
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
-; RUN: ls %t.cache | count 3
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -emit-dwarf-unwind=default
-; RUN: ls %t.cache | count 5
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
-; RUN: ls %t.cache | count 5
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -emit-dwarf-unwind=default
-; RUN: ls %t.cache | count 7
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -emit-dwarf-unwind=default -mllvm -enable-ml-inliner=default
-; RUN: ls %t.cache | count 9
+; RUN: rm -rf cache && mkdir cache
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
+; RUN: ls cache | count 3
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -emit-dwarf-unwind=default
+; RUN: ls cache | count 5
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default
+; RUN: ls cache | count 5
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -enable-ml-inliner=default -mllvm -emit-dwarf-unwind=default
+; RUN: ls cache | count 7
+; RUN: ld.lld --thinlto-cache-dir=cache -o out b.bc a.bc -mllvm -emit-dwarf-unwind=default -mllvm -enable-ml-inliner=default
+; RUN: ls cache | count 9
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"

diff  --git a/lld/test/ELF/lto/thinlto.ll b/lld/test/ELF/lto/thinlto.ll
index 4145007d9b20166..f42a0323ff0448a 100644
--- a/lld/test/ELF/lto/thinlto.ll
+++ b/lld/test/ELF/lto/thinlto.ll
@@ -3,66 +3,66 @@
 ; Basic ThinLTO tests.
 ; RUN: rm -rf %t && mkdir %t && cd %t
 ; RUN: mkdir d e
-; RUN: opt -module-summary %s -o 1.o
-; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/2.o
+; RUN: opt -module-summary %s -o a.o
+; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/b.o
 
 ; First force single-threaded mode
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ; Next force multi-threaded mode
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ;; --plugin-opt=jobs= is an alias.
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --plugin-opt=jobs=2 -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --plugin-opt=jobs=2 -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ;; --thinlto-jobs= defaults to --threads=.
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --threads=2 -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --threads=2 -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ;; --thinlto-jobs= overrides --threads=.
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --threads=1 --plugin-opt=jobs=2 -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --threads=1 --plugin-opt=jobs=2 -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ; Test with all threads, on all cores, on all CPU sockets
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=all -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --thinlto-jobs=all -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ; Test with many more threads than the system has
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=100 -shared 1.o d/2.o -o e/out
+; RUN: ld.lld -save-temps --thinlto-jobs=100 -shared a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ; Test with a bad value
 ; RUN: rm -f e/out1.lto.o e/out2.lto.o
-; 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
+; 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
 ; BAD-JOBS: error: --thinlto-jobs: invalid job count: foo
 
 ; Then check without --thinlto-jobs (which currently defaults to heavyweight_hardware_concurrency, meanning one thread per hardware core -- not SMT)
-; RUN: ld.lld -shared -save-temps 1.o d/2.o -o e/out
+; RUN: ld.lld -shared -save-temps a.o d/b.o -o e/out
 ; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
 ; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
 
 ; Check that -save-temps is usable with thin archives
 ; RUN: mkdir dir
-; RUN: cp d/2.o dir/t.o
+; RUN: cp d/b.o dir/t.o
 ; RUN: llvm-ar rcsT dir/t.a dir/t.o
-; RUN: ld.lld -save-temps 1.o dir/t.a -o %t.null
+; RUN: ld.lld -save-temps a.o dir/t.a -o %t.null
 ; RUN: ls dir/t.a*.0.preopt.bc
 
 ; NM1: T f


        


More information about the llvm-commits mailing list