1 # needs-profiler-support
5 # This test makes sure that instrumented binaries record the right counts for
6 # functions being called and branches being taken. We run an instrumented binary
7 # with an argument that causes a know path through the program and then check
8 # that the expected counts get added to the use-phase LLVM IR.
10 # LLVM doesn't support instrumenting binaries that use SEH:
11 # https://github.com/rust-lang/rust/issues/61002
13 # Things work fine with -Cpanic=abort though.
15 COMMON_FLAGS
=-Cpanic
=abort
18 # For some very small programs GNU ld seems to not properly handle
19 # instrumentation sections correctly. Neither Gold nor LLD have that problem.
21 ifneq (,$(findstring x86
,$(TARGET
)))
22 COMMON_FLAGS
=-Clink-args
=-fuse-ld
=gold
28 # We don't compile `opaque` with either optimizations or instrumentation.
29 $(RUSTC
) $(COMMON_FLAGS
) opaque.rs || exit
1
30 # Compile the test program with instrumentation
31 mkdir
-p
"$(TMPDIR)/prof_data_dir" || exit
1
32 $(RUSTC
) $(COMMON_FLAGS
) interesting.rs \
33 -Cprofile-generate
="$(TMPDIR)/prof_data_dir" -O
-Ccodegen-units
=1 || exit
1
34 $(RUSTC
) $(COMMON_FLAGS
) main.rs
-Cprofile-generate
="$(TMPDIR)/prof_data_dir" -O || exit
1
35 # The argument below generates to the expected branch weights
36 $(call RUN
,main aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc
) || exit
1
37 "$(LLVM_BIN_DIR)/llvm-profdata" merge \
38 -o
"$(TMPDIR)/prof_data_dir/merged.profdata" \
39 "$(TMPDIR)/prof_data_dir" || exit
1
40 $(RUSTC
) $(COMMON_FLAGS
) interesting.rs \
41 -Cprofile-use
="$(TMPDIR)/prof_data_dir/merged.profdata" -O \
42 -Ccodegen-units
=1 --emit
=llvm-ir || exit
1
43 cat
"$(TMPDIR)/interesting.ll" |
"$(LLVM_FILECHECK)" filecheck-patterns.txt