From 538cdd40d8403e211198bcf18ab645208ed9a025 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 29 Jul 2024 16:16:55 -0400 Subject: [PATCH 1/2] rewrite pdb-buildinfo-cl-cmd to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/pdb-buildinfo-cl-cmd/Makefile | 16 --------- tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs | 35 +++++++++++++++++++ .../pdb-buildinfo-cl-cmd/stringlist.txt | 1 - 4 files changed, 35 insertions(+), 18 deletions(-) delete mode 100644 tests/run-make/pdb-buildinfo-cl-cmd/Makefile create mode 100644 tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs delete mode 100644 tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index a84b89ff4a113..9ee97db74aa09 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -34,7 +34,6 @@ run-make/native-link-modifier-bundle/Makefile run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile -run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile run-make/pgo-indirect-call-promotion/Makefile run-make/print-calling-conventions/Makefile diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/Makefile b/tests/run-make/pdb-buildinfo-cl-cmd/Makefile deleted file mode 100644 index a7be301a5b0d2..0000000000000 --- a/tests/run-make/pdb-buildinfo-cl-cmd/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -include ../tools.mk - -# only-windows-msvc - -# tests if the pdb contains the following information in the LF_BUILDINFO: -# 1. the commandline args to compile it (cmd) -# 2. full path to the compiler (cl) - -# we just do a stringsearch on the pdb, as these need to show up at least once, as the LF_BUILDINFO is created for each cgu -# actual parsing would be better, but this is a simple and good enough solution for now - -all: - $(RUSTC_ORIGINAL) main.rs -g --crate-name my_crate_name --crate-type bin -C metadata=dc9ef878b0a48666 --out-dir $(TMPDIR) - cat '$(TMPDIR)/my_crate_name.pdb' | grep -F '$(RUSTC_ORIGINAL)' -# using a file containing the string so I don't have problems with escaping quotes and spaces - cat '$(TMPDIR)/my_crate_name.pdb' | grep -f 'stringlist.txt' diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs b/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs new file mode 100644 index 0000000000000..347b3d67a2542 --- /dev/null +++ b/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs @@ -0,0 +1,35 @@ +// Check if the pdb file contains the following information in the LF_BUILDINFO: +// 1. full path to the compiler (cl) +// 2. the commandline args to compile it (cmd) +// This is because these used to be missing in #96475. +// See https://github.com/rust-lang/rust/pull/113492 + +//@ only-windows-msvc +// Reason: pdb files are unique to this architecture + +use run_make_support::{assert_contains, env_var, rfs, rustc}; + +fn main() { + rustc() + .input("main.rs") + .arg("-g") + .crate_name("my_crate_name") + .crate_type("bin") + .metadata("dc9ef878b0a48666") + .run(); + assert_contains(rfs::read_to_string("my_crate_name.pdb"), env_var("RUSTC_ORIGINAL")); + let strings = [ + r#""main.rs""#, + r#""-g""#, + r#""--crate-name""#, + r#""my_crate_name""#, + r#""--crate-type""#, + r#""bin""#, + r#""-C""#, + r#""metadata=dc9ef878b0a48666""#, + r#""--out-dir""#, + ]; + for string in strings { + assert_contains(rfs::read_to_string("my_crate_name.pdb"), string); + } +} diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt b/tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt deleted file mode 100644 index 634e9f19e8973..0000000000000 --- a/tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt +++ /dev/null @@ -1 +0,0 @@ -"main.rs" "-g" "--crate-name" "my_crate_name" "--crate-type" "bin" "-C" "metadata=dc9ef878b0a48666" "--out-dir" \ No newline at end of file From c8669591fcdd8abb9493c28e1cb7d1a6a92ecc85 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 29 Jul 2024 16:28:38 -0400 Subject: [PATCH 2/2] rewrite pgo-indirect-call-promotion to rmake --- src/tools/compiletest/src/command-list.rs | 1 + .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../pgo-indirect-call-promotion/Makefile | 23 ------------- .../pgo-indirect-call-promotion/rmake.rs | 33 +++++++++++++++++++ 4 files changed, 34 insertions(+), 24 deletions(-) delete mode 100644 tests/run-make/pgo-indirect-call-promotion/Makefile create mode 100644 tests/run-make/pgo-indirect-call-promotion/rmake.rs diff --git a/src/tools/compiletest/src/command-list.rs b/src/tools/compiletest/src/command-list.rs index c356f4266f016..6d521bddac947 100644 --- a/src/tools/compiletest/src/command-list.rs +++ b/src/tools/compiletest/src/command-list.rs @@ -202,6 +202,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "only-watchos", "only-windows", "only-windows-gnu", + "only-windows-msvc", "only-x86", "only-x86_64", "only-x86_64-fortanix-unknown-sgx", diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 9ee97db74aa09..4fe4e68d0c477 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -35,7 +35,6 @@ run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile run-make/pgo-gen-lto/Makefile -run-make/pgo-indirect-call-promotion/Makefile run-make/print-calling-conventions/Makefile run-make/print-target-list/Makefile run-make/raw-dylib-alt-calling-convention/Makefile diff --git a/tests/run-make/pgo-indirect-call-promotion/Makefile b/tests/run-make/pgo-indirect-call-promotion/Makefile deleted file mode 100644 index 8d1e69c4aba37..0000000000000 --- a/tests/run-make/pgo-indirect-call-promotion/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# needs-profiler-support -# ignore-cross-compile - -include ../tools.mk - -all: - # We don't compile `opaque` with either optimizations or instrumentation. - # We don't compile `opaque` with either optimizations or instrumentation. - $(RUSTC) $(COMMON_FLAGS) opaque.rs - # Compile the test program with instrumentation - mkdir -p "$(TMPDIR)"/prof_data_dir - $(RUSTC) $(COMMON_FLAGS) interesting.rs \ - -Cprofile-generate="$(TMPDIR)"/prof_data_dir -O -Ccodegen-units=1 - $(RUSTC) $(COMMON_FLAGS) main.rs -Cprofile-generate="$(TMPDIR)"/prof_data_dir -O - # The argument below generates to the expected branch weights - $(call RUN,main) || exit 1 - "$(LLVM_BIN_DIR)"/llvm-profdata merge \ - -o "$(TMPDIR)"/prof_data_dir/merged.profdata \ - "$(TMPDIR)"/prof_data_dir - $(RUSTC) $(COMMON_FLAGS) interesting.rs \ - -Cprofile-use="$(TMPDIR)"/prof_data_dir/merged.profdata -O \ - -Ccodegen-units=1 --emit=llvm-ir - cat "$(TMPDIR)"/interesting.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt diff --git a/tests/run-make/pgo-indirect-call-promotion/rmake.rs b/tests/run-make/pgo-indirect-call-promotion/rmake.rs new file mode 100644 index 0000000000000..d0ccfd8a4d7e4 --- /dev/null +++ b/tests/run-make/pgo-indirect-call-promotion/rmake.rs @@ -0,0 +1,33 @@ +// This test checks that indirect call promotion is performed. The test +// programs calls the same function a thousand times through a function pointer. +// Only PGO data provides the information that it actually always is the same +// function. We verify that the indirect call promotion pass inserts a check +// whether it can make a direct call instead of the indirect call. +// See https://github.com/rust-lang/rust/pull/66631 + +//@ needs-profiler-support +// Reason: llvm_profdata is used +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{llvm_filecheck, llvm_profdata, rfs, run, rustc}; + +fn main() { + // We don't compile `opaque` with either optimizations or instrumentation. + rustc().input("opaque.rs").run(); + // Compile the test program with instrumentation + rfs::create_dir("prof_data_dir"); + rustc().input("interesting.rs").profile_generate("prof_data_dir").opt().codegen_units(1).run(); + rustc().input("main.rs").profile_generate("prof_data_dir").opt().run(); + // The argument below generates to the expected branch weights + run("main"); + llvm_profdata().merge().output("prof_data_dir/merged.profdata").input("prof_data_dir").run(); + rustc() + .input("interesting.rs") + .profile_use("prof_data_dir/merged.profdata") + .opt() + .codegen_units(1) + .emit("llvm-ir") + .run(); + llvm_filecheck().patterns("filecheck-patterns.txt").stdin(rfs::read("interesting.ll")).run(); +}