fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #72883 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum49cae55760d

1.44.0
2.0 KiB51 linesraw
1# needs-profiler-support
2
3-include ../tools.mk
4
5# This test makes sure that PGO profiling data leads to cold functions being
6# marked as `cold` and hot functions with `inlinehint`.
7# The test program contains an `if` were actual execution only ever takes the
8# `else` branch. Accordingly, we expect the function that is never called to
9# be marked as cold.
10#
11# The program is compiled with `-Copt-level=s` because this setting disables
12# LLVM's pre-inlining pass (i.e. a pass that does some inlining before it adds
13# the profiling instrumentation). Disabling this pass leads to rather
14# predictable IR which we need for this test to be stable.
15
16COMMON_FLAGS=-Copt-level=s -Ccodegen-units=1
17
18# LLVM doesn't support instrumenting binaries that use SEH:
19# https://github.com/rust-lang/rust/issues/61002
20#
21# Things work fine with -Cpanic=abort though.
22ifdef IS_MSVC
23COMMON_FLAGS+= -Cpanic=abort
24endif
25
26ifeq ($(UNAME),Darwin)
27# macOS does not have the `tac` command, but `tail -r` does the same thing
28TAC := tail -r
29else
30# some other platforms don't support the `-r` flag for `tail`, so use `tac`
31TAC := tac
32endif
33
34all:
35	# Compile the test program with instrumentation
36	$(RUSTC) $(COMMON_FLAGS) -Cprofile-generate="$(TMPDIR)" main.rs
37	# Run it in order to generate some profiling data
38	$(call RUN,main some-argument) || exit 1
39	# Postprocess the profiling data so it can be used by the compiler
40	"$(LLVM_BIN_DIR)"/llvm-profdata merge \
41		-o "$(TMPDIR)"/merged.profdata \
42		"$(TMPDIR)"/default_*.profraw
43	# Compile the test program again, making use of the profiling data
44	$(RUSTC) $(COMMON_FLAGS) -Cprofile-use="$(TMPDIR)"/merged.profdata --emit=llvm-ir main.rs
45	# Check that the generate IR contains some things that we expect
46	#
47	# We feed the file into LLVM FileCheck tool *in reverse* so that we see the
48	# line with the function name before the line with the function attributes.
49	# FileCheck only supports checking that something matches on the next line,
50	# but not if something matches on the previous line.
51	$(TAC) "$(TMPDIR)"/main.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt