fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1# needs-profiler-support 2# ignore-windows-gnu 3# ignore-cross-compile 4 5# FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works 6# properly. Since we only have GCC on the CI ignore the test for now. 7 8include ../tools.mk 9 10# This test makes sure that PGO profiling data leads to cold functions being 11# marked as `cold` and hot functions with `inlinehint`. 12# The test program contains an `if` were actual execution only ever takes the 13# `else` branch. Accordingly, we expect the function that is never called to 14# be marked as cold. 15# 16# Disable the pre-inlining pass (i.e. a pass that does some inlining before 17# it adds the profiling instrumentation). Disabling this pass leads to 18# rather predictable IR which we need for this test to be stable. 19 20COMMON_FLAGS=-Copt-level=2 -Ccodegen-units=1 -Cllvm-args=-disable-preinline 21 22ifeq ($(UNAME),Darwin) 23# macOS does not have the `tac` command, but `tail -r` does the same thing 24TAC := tail -r 25else 26# some other platforms don't support the `-r` flag for `tail`, so use `tac` 27TAC := tac 28endif 29 30all: 31 # Compile the test program with instrumentation 32 $(RUSTC) $(COMMON_FLAGS) -Cprofile-generate="$(TMPDIR)" main.rs 33 # Run it in order to generate some profiling data 34 $(call RUN,main some-argument) || exit 1 35 # Postprocess the profiling data so it can be used by the compiler 36 "$(LLVM_BIN_DIR)"/llvm-profdata merge \ 37 -o "$(TMPDIR)"/merged.profdata \ 38 "$(TMPDIR)"/default_*.profraw 39 # Compile the test program again, making use of the profiling data 40 $(RUSTC) $(COMMON_FLAGS) -Cprofile-use="$(TMPDIR)"/merged.profdata --emit=llvm-ir main.rs 41 # Check that the generate IR contains some things that we expect 42 # 43 # We feed the file into LLVM FileCheck tool *in reverse* so that we see the 44 # line with the function name before the line with the function attributes. 45 # FileCheck only supports checking that something matches on the next line, 46 # but not if something matches on the previous line. 47 $(TAC) "$(TMPDIR)"/main.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt