| 1 |
REQUIRES: x86-registered-target, ld.lld |
| 2 |
|
| 3 |
# Show that the ThinLTO cache works with DTLTO. |
| 4 |
|
| 5 |
RUN: rm -rf %t && split-file %s %t && cd %t |
| 6 |
|
| 7 |
# Compile source files into bitcode files. |
| 8 |
RUN: %clang -O2 --target=x86_64-linux-gnu -flto=thin -c foo.c main.c |
| 9 |
|
| 10 |
# Execute the linker and check that the cache is populated. |
| 11 |
RUN: %clang -O2 --target=x86_64-linux-gnu -Werror -flto=thin -fuse-ld=lld -nostdlib -e main \ |
| 12 |
RUN: main.o foo.o -o populate1.elf \ |
| 13 |
RUN: -Wl,--thinlto-distributor=%python \ |
| 14 |
RUN: -Wl,--thinlto-distributor-arg=%llvm_src_root/utils/dtlto/local.py \ |
| 15 |
RUN: -Wl,--thinlto-remote-compiler=%clang \ |
| 16 |
RUN: -Wl,--thinlto-cache-dir=cache.dir \ |
| 17 |
RUN: -Wl,--save-temps |
| 18 |
|
| 19 |
# Check that there are two backend compilation jobs occurred. |
| 20 |
RUN: grep -wo args populate1.*.dist-file.json | wc -l | grep -qx "\s*3" |
| 21 |
RUN: ls cache.dir/llvmcache.timestamp |
| 22 |
RUN: ls cache.dir | count 3 |
| 23 |
|
| 24 |
# Execute the linker again and check that a fully populated cache is used correctly, |
| 25 |
# i.e., no additional cache entries are created for cache hits. |
| 26 |
RUN: %clang -O2 --target=x86_64-linux-gnu -Werror -flto=thin -fuse-ld=lld -nostdlib -e main \ |
| 27 |
RUN: main.o foo.o -o populate2.elf \ |
| 28 |
RUN: -Wl,--thinlto-distributor=%python \ |
| 29 |
RUN: -Wl,--thinlto-distributor-arg=%llvm_src_root/utils/dtlto/local.py \ |
| 30 |
RUN: -Wl,--thinlto-remote-compiler=%clang \ |
| 31 |
RUN: -Wl,--thinlto-cache-dir=cache.dir \ |
| 32 |
RUN: -Wl,--save-temps |
| 33 |
|
| 34 |
# Check that there are no backend compilation jobs occurred. |
| 35 |
RUN: grep -wo args populate2.*.dist-file.json | wc -l | grep -qx "\s*1" |
| 36 |
RUN: ls cache.dir | count 3 |
| 37 |
|
| 38 |
RUN: %clang -O0 --target=x86_64-linux-gnu -flto=thin -c foo.c -o foo.O0.o |
| 39 |
RUN: %clang -O0 --target=x86_64-linux-gnu -flto=thin -c main.c -o main.O0.o |
| 40 |
|
| 41 |
# Execute the linker again and check that the cache is populated correctly when there |
| 42 |
# are no cache hits but there are existing cache entries. |
| 43 |
# As a side effect, this also verifies that the optimization level is considered when |
| 44 |
# evaluating the cache entry key. |
| 45 |
|
| 46 |
RUN: %clang -O2 --target=x86_64-linux-gnu -Werror -flto=thin -fuse-ld=lld -nostdlib -e main \ |
| 47 |
RUN: main.O0.o foo.O0.o -o populate3.elf \ |
| 48 |
RUN: -Wl,--thinlto-distributor=%python \ |
| 49 |
RUN: -Wl,--thinlto-distributor-arg=%llvm_src_root/utils/dtlto/local.py \ |
| 50 |
RUN: -Wl,--thinlto-remote-compiler=%clang \ |
| 51 |
RUN: -Wl,--thinlto-cache-dir=cache.dir \ |
| 52 |
RUN: -Wl,--save-temps |
| 53 |
|
| 54 |
# Check that there are two new backend compilation jobs occurred. |
| 55 |
RUN: grep -wo args populate3.*.dist-file.json | wc -l | grep -qx "\s*3" |
| 56 |
RUN: ls cache.dir | count 5 |
| 57 |
|
| 58 |
RUN: %clang -O2 --target=x86_64-linux-gnu -flto=thin -c main-partial.c |
| 59 |
|
| 60 |
# Execute the linker and check that everything works correctly with the partially populated cache; |
| 61 |
# One more cache entry should be generated after this run. |
| 62 |
|
| 63 |
RUN: %clang -O2 --target=x86_64-linux-gnu -Werror -flto=thin -fuse-ld=lld -nostdlib -e main \ |
| 64 |
RUN: main-partial.o foo.o -o main-partial.elf \ |
| 65 |
RUN: -Wl,--thinlto-distributor=%python \ |
| 66 |
RUN: -Wl,--thinlto-distributor-arg=%llvm_src_root/utils/dtlto/local.py \ |
| 67 |
RUN: -Wl,--thinlto-remote-compiler=%clang \ |
| 68 |
RUN: -Wl,--thinlto-cache-dir=cache.dir \ |
| 69 |
RUN: -Wl,--save-temps |
| 70 |
|
| 71 |
# Check that there is one new backend compilation jobs occurred. |
| 72 |
RUN: grep -wo args main-partial.*.dist-file.json | wc -l | grep -qx "\s*2" |
| 73 |
RUN: ls cache.dir | count 6 |
| 74 |
|
| 75 |
#--- foo.c |
| 76 |
volatile int foo_int; |
| 77 |
__attribute__((retain)) int foo(int x) { return x + foo_int; } |
| 78 |
|
| 79 |
#--- main.c |
| 80 |
extern int foo(int x); |
| 81 |
__attribute__((retain)) int main(int argc, char** argv) { |
| 82 |
return foo(argc); |
| 83 |
} |
| 84 |
|
| 85 |
#--- main-partial.c |
| 86 |
extern int foo(int x); |
| 87 |
__attribute__((retain)) int main(int argc, char** argv) { |
| 88 |
return foo(argc+1); |
| 89 |
} |