]>
Commit | Line | Data |
---|---|---|
60c5eb7d | 1 | # needs-profiler-support |
1b1a35ee XL |
2 | # ignore-windows-gnu |
3 | ||
4 | # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works | |
5 | # properly. Since we only have GCC on the CI ignore the test for now. | |
60c5eb7d XL |
6 | |
7 | -include ../tools.mk | |
8 | ||
9 | # This test makes sure that instrumented binaries record the right counts for | |
10 | # functions being called and branches being taken. We run an instrumented binary | |
11 | # with an argument that causes a know path through the program and then check | |
12 | # that the expected counts get added to the use-phase LLVM IR. | |
13 | ||
14 | # LLVM doesn't support instrumenting binaries that use SEH: | |
15 | # https://github.com/rust-lang/rust/issues/61002 | |
16 | # | |
17 | # Things work fine with -Cpanic=abort though. | |
18 | ifdef IS_MSVC | |
19 | COMMON_FLAGS=-Cpanic=abort | |
20 | endif | |
21 | ||
dfeec247 XL |
22 | # For some very small programs GNU ld seems to not properly handle |
23 | # instrumentation sections correctly. Neither Gold nor LLD have that problem. | |
24 | ifeq ($(UNAME),Linux) | |
25 | ifneq (,$(findstring x86,$(TARGET))) | |
26 | COMMON_FLAGS=-Clink-args=-fuse-ld=gold | |
27 | endif | |
28 | endif | |
29 | ||
30 | ||
60c5eb7d XL |
31 | all: |
32 | # We don't compile `opaque` with either optimizations or instrumentation. | |
dfeec247 | 33 | $(RUSTC) $(COMMON_FLAGS) opaque.rs || exit 1 |
60c5eb7d | 34 | # Compile the test program with instrumentation |
dfeec247 | 35 | mkdir -p "$(TMPDIR)/prof_data_dir" || exit 1 |
60c5eb7d | 36 | $(RUSTC) $(COMMON_FLAGS) interesting.rs \ |
dfeec247 XL |
37 | -Cprofile-generate="$(TMPDIR)/prof_data_dir" -O -Ccodegen-units=1 || exit 1 |
38 | $(RUSTC) $(COMMON_FLAGS) main.rs -Cprofile-generate="$(TMPDIR)/prof_data_dir" -O || exit 1 | |
60c5eb7d XL |
39 | # The argument below generates to the expected branch weights |
40 | $(call RUN,main aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc) || exit 1 | |
dfeec247 XL |
41 | "$(LLVM_BIN_DIR)/llvm-profdata" merge \ |
42 | -o "$(TMPDIR)/prof_data_dir/merged.profdata" \ | |
43 | "$(TMPDIR)/prof_data_dir" || exit 1 | |
60c5eb7d | 44 | $(RUSTC) $(COMMON_FLAGS) interesting.rs \ |
dfeec247 XL |
45 | -Cprofile-use="$(TMPDIR)/prof_data_dir/merged.profdata" -O \ |
46 | -Ccodegen-units=1 --emit=llvm-ir || exit 1 | |
47 | cat "$(TMPDIR)/interesting.ll" | "$(LLVM_FILECHECK)" filecheck-patterns.txt |