]> git.proxmox.com Git - rustc.git/blob - src/test/run-make-fulldeps/pgo-branch-weights/Makefile
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / test / run-make-fulldeps / pgo-branch-weights / Makefile
1 # needs-profiler-support
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.
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
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
31 all:
32 # We don't compile `opaque` with either optimizations or instrumentation.
33 $(RUSTC) $(COMMON_FLAGS) opaque.rs || exit 1
34 # Compile the test program with instrumentation
35 mkdir -p "$(TMPDIR)/prof_data_dir" || exit 1
36 $(RUSTC) $(COMMON_FLAGS) interesting.rs \
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
39 # The argument below generates to the expected branch weights
40 $(call RUN,main aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc) || exit 1
41 "$(LLVM_BIN_DIR)/llvm-profdata" merge \
42 -o "$(TMPDIR)/prof_data_dir/merged.profdata" \
43 "$(TMPDIR)/prof_data_dir" || exit 1
44 $(RUSTC) $(COMMON_FLAGS) interesting.rs \
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