about summary refs log tree commit diff
path: root/tests/run-make
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-13 02:46:23 +0000
committerbors <bors@rust-lang.org>2024-06-13 02:46:23 +0000
commitf6b4b71ef10307201b52c17b0f9dcf9557cd90ba (patch)
tree64f0b75aa4f67448e33e40de8ce1063c6c9ac593 /tests/run-make
parent8cf5101d77cd9eeb12751c563d8098aba2c604d0 (diff)
parent17b07716f823cd7cbbd848216002c1fee53707f9 (diff)
downloadrust-f6b4b71ef10307201b52c17b0f9dcf9557cd90ba.tar.gz
rust-f6b4b71ef10307201b52c17b0f9dcf9557cd90ba.zip
Auto merge of #125165 - Oneirical:pgo-branch-weights, r=jieyouxu
Migrate `run-make/pgo-branch-weights` to `rmake`

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

This is a scary one and I expect things to break. Set as draft, because this isn't ready.

- [x] There is this comment here, which suggests the test is excluded from the testing process due to a platform specific issue? I can't see anything here that would cause this test to not run...
> // FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works
// properly. Since we only have GCC on the CI ignore the test for now."

EDIT: This is specific to Windows-gnu.

- [x] The Makefile has this line:
```
ifneq (,$(findstring x86,$(TARGET)))
COMMON_FLAGS=-Clink-args=-fuse-ld=gold
```
I honestly can't tell whether this is checking if the target IS x86, or IS NOT. EDIT: It's checking if it IS x86.

- [x] I don't know why the Makefile was trying to pass an argument directly in the Makefile instead of setting that "aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc" input as a variable in the Rust program directly. I changed that, let me know if that was wrong.

- [x] Trying to rewrite `cat "$(TMPDIR)/interesting.ll" | "$(LLVM_FILECHECK)" filecheck-patterns.txt` resulted in some butchery. For starters, in `tools.mk`, LLVM_FILECHECK corrects its own backslashes on Windows distributions, but there is no further mention of it, so I assume this is a preset environment variable... but is it really? Then, the command itself uses a Standard Input and a passed input file as an argument simultaneously, according to the [documentation](https://llvm.org/docs/CommandGuide/FileCheck.html#synopsis).

try-job: aarch64-gnu
Diffstat (limited to 'tests/run-make')
-rw-r--r--tests/run-make/pgo-branch-weights/Makefile35
-rw-r--r--tests/run-make/pgo-branch-weights/rmake.rs45
2 files changed, 45 insertions, 35 deletions
diff --git a/tests/run-make/pgo-branch-weights/Makefile b/tests/run-make/pgo-branch-weights/Makefile
deleted file mode 100644
index 4c9f8b2493a..00000000000
--- a/tests/run-make/pgo-branch-weights/Makefile
+++ /dev/null
@@ -1,35 +0,0 @@
-# needs-profiler-support
-# ignore-windows-gnu
-# ignore-cross-compile
-
-# FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works
-# properly. Since we only have GCC on the CI ignore the test for now.
-
-include ../tools.mk
-
-# For some very small programs GNU ld seems to not properly handle
-# instrumentation sections correctly. Neither Gold nor LLD have that problem.
-ifeq ($(UNAME),Linux)
-ifneq (,$(findstring x86,$(TARGET)))
-COMMON_FLAGS=-Clink-args=-fuse-ld=gold
-endif
-endif
-
-
-all:
-	# We don't compile `opaque` with either optimizations or instrumentation.
-	$(RUSTC) $(COMMON_FLAGS) opaque.rs || exit 1
-	# Compile the test program with instrumentation
-	mkdir -p "$(TMPDIR)/prof_data_dir" || exit 1
-	$(RUSTC) $(COMMON_FLAGS) interesting.rs \
-		-Cprofile-generate="$(TMPDIR)/prof_data_dir" -O -Ccodegen-units=1 || exit 1
-	$(RUSTC) $(COMMON_FLAGS) main.rs -Cprofile-generate="$(TMPDIR)/prof_data_dir" -O || exit 1
-	# The argument below generates to the expected branch weights
-	$(call RUN,main aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc) || exit 1
-	"$(LLVM_BIN_DIR)/llvm-profdata" merge \
-		-o "$(TMPDIR)/prof_data_dir/merged.profdata" \
-		"$(TMPDIR)/prof_data_dir" || exit 1
-	$(RUSTC) $(COMMON_FLAGS) interesting.rs \
-		-Cprofile-use="$(TMPDIR)/prof_data_dir/merged.profdata" -O \
-		-Ccodegen-units=1 --emit=llvm-ir || exit 1
-	cat "$(TMPDIR)/interesting.ll" | "$(LLVM_FILECHECK)" filecheck-patterns.txt
diff --git a/tests/run-make/pgo-branch-weights/rmake.rs b/tests/run-make/pgo-branch-weights/rmake.rs
new file mode 100644
index 00000000000..55f6e7e56c5
--- /dev/null
+++ b/tests/run-make/pgo-branch-weights/rmake.rs
@@ -0,0 +1,45 @@
+// This test generates an instrumented binary - a program which
+// will keep track of how many times it calls each function, a useful
+// feature for optimization. Then, an argument (aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc)
+// is passed into the instrumented binary, which should react with a number of function calls
+// fully known in advance. (For example, the letter 'a' results in calling f1())
+
+// If the test passes, the expected function call count was added to the use-phase LLVM-IR.
+// See https://github.com/rust-lang/rust/pull/66631
+
+//@ needs-profiler-support
+//@ ignore-cross-compile
+
+// FIXME(Oneirical): This test has problems generating profdata on mingw.
+// For more information, see https://github.com/rust-lang/rust/pull/122613
+//@ ignore-windows-gnu
+
+use run_make_support::{fs_wrapper, llvm_filecheck, llvm_profdata, run_with_args, rustc};
+use std::path::Path;
+
+fn main() {
+    let path_prof_data_dir = Path::new("prof_data_dir");
+    let path_merged_profdata = path_prof_data_dir.join("merged.profdata");
+    rustc().input("opaque.rs").run();
+    fs_wrapper::create_dir_all(&path_prof_data_dir);
+    rustc()
+        .input("interesting.rs")
+        .profile_generate(&path_prof_data_dir)
+        .opt()
+        .codegen_units(1)
+        .run();
+    rustc().input("main.rs").profile_generate(&path_prof_data_dir).opt().run();
+    run_with_args("main", &["aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc"]);
+    llvm_profdata().merge().output(&path_merged_profdata).input(path_prof_data_dir).run();
+    rustc()
+        .input("interesting.rs")
+        .profile_use(path_merged_profdata)
+        .opt()
+        .codegen_units(1)
+        .emit("llvm-ir")
+        .run();
+    llvm_filecheck()
+        .patterns("filecheck-patterns.txt")
+        .stdin(fs_wrapper::read("interesting.ll"))
+        .run();
+}