|
| 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 | + |
| 16 | +COMMON_FLAGS=-Copt-level=s -Ccodegen-units=1 |
| 17 | + |
| 18 | +all: |
| 19 | + # Compile the test program with instrumentation |
| 20 | + $(RUSTC) $(COMMON_FLAGS) -Z pgo-gen="$(TMPDIR)" main.rs |
| 21 | + # Run it in order to generate some profiling data |
| 22 | + $(call RUN,main some-argument) || exit 1 |
| 23 | + # Postprocess the profiling data so it can be used by the compiler |
| 24 | + $(LD_LIB_PATH_ENVVAR)=$(REAL_LD_LIBRARY_PATH) llvm-profdata merge \ |
| 25 | + -o "$(TMPDIR)"/merged.profdata \ |
| 26 | + "$(TMPDIR)"/default_*.profraw |
| 27 | + # Compile the test program again, making use of the profiling data |
| 28 | + $(RUSTC) $(COMMON_FLAGS) -Z pgo-use="$(TMPDIR)"/merged.profdata --emit=llvm-ir main.rs |
| 29 | + # Check that the generate IR contains some things that we expect |
| 30 | + # |
| 31 | + # We feed the file into LLVM FileCheck tool *in reverse* so that we see the |
| 32 | + # line with the function name before the line with the function attributes. |
| 33 | + # FileCheck only supports checking that something matches on the next line, |
| 34 | + # but not if something matches on the previous line. |
| 35 | + tac "$(TMPDIR)"/main.ll | $(LLVM_FILECHECK) filecheck-patterns.txt |
0 commit comments