]> git.proxmox.com Git - rustc.git/blob - src/test/run-make-fulldeps/pgo-branch-weights/Makefile
New upstream version 1.42.0+dfsg1
[rustc.git] / src / test / run-make-fulldeps / pgo-branch-weights / Makefile
1 # needs-profiler-support
2
3 -include ../tools.mk
4
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.
9
10 # LLVM doesn't support instrumenting binaries that use SEH:
11 # https://github.com/rust-lang/rust/issues/61002
12 #
13 # Things work fine with -Cpanic=abort though.
14 ifdef IS_MSVC
15 COMMON_FLAGS=-Cpanic=abort
16 endif
17
18 # For some very small programs GNU ld seems to not properly handle
19 # instrumentation sections correctly. Neither Gold nor LLD have that problem.
20 ifeq ($(UNAME),Linux)
21 ifneq (,$(findstring x86,$(TARGET)))
22 COMMON_FLAGS=-Clink-args=-fuse-ld=gold
23 endif
24 endif
25
26
27 all:
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