1 # needs-profiler-support
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.
9 # This test makes sure that PGO profiling data leads to cold functions being
10 # marked as `cold` and hot functions with `inlinehint`.
11 # The test program contains an `if` were actual execution only ever takes the
12 # `else` branch. Accordingly, we expect the function that is never called to
15 # Disable the pre-inlining pass (i.e. a pass that does some inlining before
16 # it adds the profiling instrumentation). Disabling this pass leads to
17 # rather predictable IR which we need for this test to be stable.
19 COMMON_FLAGS=-Copt-level=2 -Ccodegen-units=1 -Cllvm-args=-disable-preinline
21 ifeq ($(UNAME),Darwin)
22 # macOS does not have the `tac` command, but `tail -r` does the same thing
25 # some other platforms don't support the `-r` flag for `tail`, so use `tac`
30 # Compile the test program with instrumentation
31 $(RUSTC) $(COMMON_FLAGS) -Cprofile-generate="$(TMPDIR)" main.rs
32 # Run it in order to generate some profiling data
33 $(call RUN,main some-argument) || exit 1
34 # Postprocess the profiling data so it can be used by the compiler
35 "$(LLVM_BIN_DIR)"/llvm-profdata merge \
36 -o "$(TMPDIR)"/merged.profdata \
37 "$(TMPDIR)"/default_*.profraw
38 # Compile the test program again, making use of the profiling data
39 $(RUSTC) $(COMMON_FLAGS) -Cprofile-use="$(TMPDIR)"/merged.profdata --emit=llvm-ir main.rs
40 # Check that the generate IR contains some things that we expect
42 # We feed the file into LLVM FileCheck tool *in reverse* so that we see the
43 # line with the function name before the line with the function attributes.
44 # FileCheck only supports checking that something matches on the next line,
45 # but not if something matches on the previous line.
46 $(TAC) "$(TMPDIR)"/main.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt