From b16264a7841663710e27c87e04db83bfca30e767 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 15 May 2024 11:58:06 -0400 Subject: [PATCH 1/4] rewrite pgo-branch-weights (1/2) --- src/tools/run-make-support/src/lib.rs | 6 +- src/tools/run-make-support/src/llvm.rs | 152 ++++++++++++++++++ src/tools/run-make-support/src/run.rs | 23 ++- src/tools/run-make-support/src/rustc.rs | 18 +++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/pgo-branch-weights/Makefile | 35 ---- tests/run-make/pgo-branch-weights/rmake.rs | 41 +++++ 7 files changed, 234 insertions(+), 42 deletions(-) create mode 100644 src/tools/run-make-support/src/llvm.rs delete mode 100644 tests/run-make/pgo-branch-weights/Makefile create mode 100644 tests/run-make/pgo-branch-weights/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index b920f9a07db87..a683063db7936 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -9,7 +9,7 @@ mod command; pub mod diff; mod drop_bomb; pub mod fs_wrapper; -pub mod llvm_readobj; +pub mod llvm; pub mod run; pub mod rustc; pub mod rustdoc; @@ -29,8 +29,8 @@ pub use wasmparser; pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use diff::{diff, Diff}; -pub use llvm_readobj::{llvm_readobj, LlvmReadobj}; -pub use run::{cmd, run, run_fail}; +pub use llvm::{llvm_profdata, llvm_readobj, llvm_filecheck, LlvmProfdata, LlvmReadobj, LlvmFilecheck}; +pub use run::{cmd, run, run_fail, run_with_args}; pub use rustc::{aux_build, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs new file mode 100644 index 0000000000000..f4fc323409563 --- /dev/null +++ b/src/tools/run-make-support/src/llvm.rs @@ -0,0 +1,152 @@ +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; +use std::io::{BufReader, Read, Write}; +use std::fs::File; + +use crate::{env_var, handle_failed_output}; + +/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available +/// at `$LLVM_BIN_DIR/llvm-readobj`. +pub fn llvm_readobj() -> LlvmReadobj { + LlvmReadobj::new() +} + +/// Construct a new `llvm-profdata` invocation. This assumes that `llvm-profdata` is available +/// at `$LLVM_BIN_DIR/llvm-profdata`. +pub fn llvm_profdata() -> LlvmProfdata { + LlvmProfdata::new() +} + +/// Construct a new `llvm-filecheck` invocation. This assumes that `llvm-filecheck` is available +/// at `$LLVM_FILECHECK`. +pub fn llvm_filecheck() -> LlvmFilecheck { + LlvmFilecheck::new() +} + +/// A `llvm-readobj` invocation builder. +#[derive(Debug)] +pub struct LlvmReadobj { + cmd: Command, +} + +/// A `llvm-profdata` invocation builder. +#[derive(Debug)] +pub struct LlvmProfdata { + cmd: Command, +} + +/// A `llvm-filecheck` invocation builder. +#[derive(Debug)] +pub struct LlvmFilecheck { + cmd: Command, +} + +crate::impl_common_helpers!(LlvmReadobj); + +/// Generate the path to the bin directory of LLVM. +pub fn llvm_bin_dir() -> PathBuf { + let llvm_bin_dir = env_var("LLVM_BIN_DIR") + .expect("`LLVM_BIN_DIR` not specified, but this is required to find `llvm-readobj`"); + PathBuf::from(llvm_bin_dir) +} + +impl LlvmReadobj { + /// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available + /// at `$LLVM_BIN_DIR/llvm-readobj`. + pub fn new() -> Self { + let llvm_readobj = llvm_bin_dir().join("llvm-readobj"); + let cmd = Command::new(llvm_readobj); + Self { cmd } + } + + /// Provide an input file. + pub fn input>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } + + /// Pass `--file-header` to display file headers. + pub fn file_header(&mut self) -> &mut Self { + self.cmd.arg("--file-header"); + self + } + + /// Get the [`Output`][::std::process::Output] of the finished process. + #[track_caller] + pub fn command_output(&mut self) -> Output { + self.cmd.output().expect("failed to get output of finished process") + } +} + +impl LlvmProfdata { + /// Construct a new `llvm-profdata` invocation. This assumes that `llvm-profdata` is available + /// at `$LLVM_BIN_DIR/llvm-profdata`. + pub fn new() -> Self { + let llvm_profdata = llvm_bin_dir().join("llvm-profdata"); + let cmd = Command::new(llvm_profdata); + Self { cmd } + } + + /// Provide an input file. + pub fn input>(&mut self, path: P) -> &mut Self { + self.cmd.arg("-o"); + self.cmd.arg(path.as_ref()); + self + } + + /// Specify the output file path. + pub fn output>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } + + /// Take several profile data files generated by PGO instrumentation and merge them + /// together into a single indexed profile data file. + pub fn merge(&mut self) -> &mut Self { + self.cmd.arg("merge"); + self + } + + /// Get the [`Output`][::std::process::Output] of the finished process. + #[track_caller] + pub fn command_output(&mut self) -> Output { + self.cmd.output().expect("failed to get output of finished process") + } +} + +impl LlvmFilecheck { + /// Construct a new `llvm-filecheck` invocation. This assumes that `llvm-filecheck` is available + /// at `$LLVM_FILECHECK`. + pub fn new() -> Self { + let llvm_filecheck = env_var("LLVM_FILECHECK").expect("LLVM_FILECHECK env var not specified"); + let cmd = Command::new(llvm_filecheck); + Self { cmd } + } + + /// Pipe a file into standard input containing patterns that will be matched against the .patterns(path) call. + pub fn stdin>(&mut self, path: P) -> &mut Self { + let file = File::open(path).unwrap(); + let reader = BufReader::new(file); + let byte_vec = read_bytes(reader).expect("failed to read bytes of standard input"); + let byte_slice = byte_vec.as_slice(); + self.cmd.stdin(std::process::Stdio::piped()); + let mut child = self.cmd.spawn().unwrap(); + let mut stdin = child.stdin.take().unwrap(); + stdin.write_all(byte_slice).unwrap(); + stdin.flush().unwrap(); + child.wait_with_output().unwrap(); + self + } + + /// Provide the patterns that need to be matched. + pub fn patterns>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } +} + +fn read_bytes(mut reader: R) -> Result, std::io::Error> { + let mut buffer = Vec::new(); + reader.read_to_end(&mut buffer)?; + Ok(buffer) +} diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs index 6fa1a75363c9e..e9159e6afcc8e 100644 --- a/src/tools/run-make-support/src/run.rs +++ b/src/tools/run-make-support/src/run.rs @@ -9,12 +9,17 @@ use crate::{cwd, env_var, is_windows, set_host_rpath}; use super::handle_failed_output; #[track_caller] -fn run_common(name: &str) -> Command { +fn run_common(name: &str, args: Option<&[&str]>) -> Command { let mut bin_path = PathBuf::new(); bin_path.push(cwd()); bin_path.push(name); let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR"); let mut cmd = Command::new(bin_path); + if let Some(args) = args { + for arg in args { + cmd.arg(arg); + } + } cmd.env(&ld_lib_path_envvar, { let mut paths = vec![]; paths.push(cwd()); @@ -43,7 +48,19 @@ fn run_common(name: &str) -> Command { #[track_caller] pub fn run(name: &str) -> CompletedProcess { let caller = panic::Location::caller(); - let mut cmd = run_common(name); + let mut cmd = run_common(name, None); + let output = cmd.run(); + if !output.status().success() { + handle_failed_output(&cmd, output, caller.line()); + } + output +} + +/// Run a built binary with one or more argument(s) and make sure it succeeds. +#[track_caller] +pub fn run_with_args(name: &str, args: &[&str]) -> CompletedProcess { + let caller = std::panic::Location::caller(); + let mut cmd = run_common(name, Some(args)); let output = cmd.run(); if !output.status().success() { handle_failed_output(&cmd, output, caller.line()); @@ -55,7 +72,7 @@ pub fn run(name: &str) -> CompletedProcess { #[track_caller] pub fn run_fail(name: &str) -> CompletedProcess { let caller = panic::Location::caller(); - let mut cmd = run_common(name); + let mut cmd = run_common(name, None); let output = cmd.run_fail(); if output.status().success() { handle_failed_output(&cmd, output, caller.line()); diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 32fa5018d800f..4a47ac2ed685a 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -146,6 +146,24 @@ impl Rustc { self } + /// Specify directory path used for profile generation + pub fn profile_generate>(&mut self, path: P) -> &mut Self { + let mut arg = OsString::new(); + arg.push("-Cprofile-generate="); + arg.push(path.as_ref()); + self.cmd.arg(&arg); + self + } + + /// Specify directory path used for profile usage + pub fn profile_use>(&mut self, path: P) -> &mut Self { + let mut arg = OsString::new(); + arg.push("-Cprofile-use="); + arg.push(path.as_ref()); + self.cmd.arg(&arg); + self + } + /// Specify error format to use pub fn error_format(&mut self, format: &str) -> &mut Self { self.cmd.arg(format!("--error-format={format}")); diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index b07e012a1b8af..912895fecd486 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -168,7 +168,6 @@ run-make/pass-linker-flags/Makefile run-make/pass-non-c-like-enum-to-c/Makefile run-make/pdb-alt-path/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile -run-make/pgo-branch-weights/Makefile run-make/pgo-gen-lto/Makefile run-make/pgo-gen-no-imp-symbols/Makefile run-make/pgo-gen/Makefile diff --git a/tests/run-make/pgo-branch-weights/Makefile b/tests/run-make/pgo-branch-weights/Makefile deleted file mode 100644 index 4c9f8b2493ab8..0000000000000 --- 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 0000000000000..3fea042de089c --- /dev/null +++ b/tests/run-make/pgo-branch-weights/rmake.rs @@ -0,0 +1,41 @@ +// 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 + +// (This test has problems generating profdata on mingw. This could use further investigation.) +//@ ignore-windows-gnu + +use run_make_support::{llvm_filecheck, llvm_profdata, run_with_args, rustc, rustdoc, target}; +use std::fs; + +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::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("interesting_ll").run(); +} From ab3b00d57a70570f84dd7a811d2191344197d089 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 27 May 2024 11:00:59 -0400 Subject: [PATCH 2/4] Try run() instead of command_output() --- src/tools/run-make-support/src/llvm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs index f4fc323409563..c7a0a3414f94e 100644 --- a/src/tools/run-make-support/src/llvm.rs +++ b/src/tools/run-make-support/src/llvm.rs @@ -118,7 +118,7 @@ impl LlvmFilecheck { /// Construct a new `llvm-filecheck` invocation. This assumes that `llvm-filecheck` is available /// at `$LLVM_FILECHECK`. pub fn new() -> Self { - let llvm_filecheck = env_var("LLVM_FILECHECK").expect("LLVM_FILECHECK env var not specified"); + let llvm_filecheck = env_var("LLVM_FILECHECK"); let cmd = Command::new(llvm_filecheck); Self { cmd } } From 12393254bd977e5df6ad1b3f9231ab37f80a0966 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 27 May 2024 11:51:24 -0400 Subject: [PATCH 3/4] add command_output to llvmfilecheck --- src/tools/run-make-support/src/lib.rs | 4 +++- src/tools/run-make-support/src/llvm.rs | 26 ++++++---------------- src/tools/run-make-support/src/run.rs | 2 +- tests/run-make/pgo-branch-weights/rmake.rs | 9 +++++--- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index a683063db7936..b7a936a1e115d 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -29,7 +29,9 @@ pub use wasmparser; pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use diff::{diff, Diff}; -pub use llvm::{llvm_profdata, llvm_readobj, llvm_filecheck, LlvmProfdata, LlvmReadobj, LlvmFilecheck}; +pub use llvm::{ + llvm_filecheck, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmProfdata, LlvmReadobj, +}; pub use run::{cmd, run, run_fail, run_with_args}; pub use rustc::{aux_build, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs index c7a0a3414f94e..4a69fe6032999 100644 --- a/src/tools/run-make-support/src/llvm.rs +++ b/src/tools/run-make-support/src/llvm.rs @@ -1,9 +1,8 @@ -use std::path::{Path, PathBuf}; -use std::process::{Command, Output}; -use std::io::{BufReader, Read, Write}; use std::fs::File; +use std::io::{BufReader, Read, Write}; +use std::path::{Path, PathBuf}; -use crate::{env_var, handle_failed_output}; +use crate::{env_var, Command}; /// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available /// at `$LLVM_BIN_DIR/llvm-readobj`. @@ -42,11 +41,12 @@ pub struct LlvmFilecheck { } crate::impl_common_helpers!(LlvmReadobj); +crate::impl_common_helpers!(LlvmProfdata); +crate::impl_common_helpers!(LlvmFilecheck); /// Generate the path to the bin directory of LLVM. pub fn llvm_bin_dir() -> PathBuf { - let llvm_bin_dir = env_var("LLVM_BIN_DIR") - .expect("`LLVM_BIN_DIR` not specified, but this is required to find `llvm-readobj`"); + let llvm_bin_dir = env_var("LLVM_BIN_DIR"); PathBuf::from(llvm_bin_dir) } @@ -70,12 +70,6 @@ impl LlvmReadobj { self.cmd.arg("--file-header"); self } - - /// Get the [`Output`][::std::process::Output] of the finished process. - #[track_caller] - pub fn command_output(&mut self) -> Output { - self.cmd.output().expect("failed to get output of finished process") - } } impl LlvmProfdata { @@ -89,13 +83,13 @@ impl LlvmProfdata { /// Provide an input file. pub fn input>(&mut self, path: P) -> &mut Self { - self.cmd.arg("-o"); self.cmd.arg(path.as_ref()); self } /// Specify the output file path. pub fn output>(&mut self, path: P) -> &mut Self { + self.cmd.arg("-o"); self.cmd.arg(path.as_ref()); self } @@ -106,12 +100,6 @@ impl LlvmProfdata { self.cmd.arg("merge"); self } - - /// Get the [`Output`][::std::process::Output] of the finished process. - #[track_caller] - pub fn command_output(&mut self) -> Output { - self.cmd.output().expect("failed to get output of finished process") - } } impl LlvmFilecheck { diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs index e9159e6afcc8e..54730bb7de736 100644 --- a/src/tools/run-make-support/src/run.rs +++ b/src/tools/run-make-support/src/run.rs @@ -59,7 +59,7 @@ pub fn run(name: &str) -> CompletedProcess { /// Run a built binary with one or more argument(s) and make sure it succeeds. #[track_caller] pub fn run_with_args(name: &str, args: &[&str]) -> CompletedProcess { - let caller = std::panic::Location::caller(); + let caller = panic::Location::caller(); let mut cmd = run_common(name, Some(args)); let output = cmd.run(); if !output.status().success() { diff --git a/tests/run-make/pgo-branch-weights/rmake.rs b/tests/run-make/pgo-branch-weights/rmake.rs index 3fea042de089c..a06573c51ee55 100644 --- a/tests/run-make/pgo-branch-weights/rmake.rs +++ b/tests/run-make/pgo-branch-weights/rmake.rs @@ -13,14 +13,17 @@ // (This test has problems generating profdata on mingw. This could use further investigation.) //@ ignore-windows-gnu -use run_make_support::{llvm_filecheck, llvm_profdata, run_with_args, rustc, rustdoc, target}; +use run_make_support::{llvm_filecheck, llvm_profdata, run_with_args, rustc}; use std::fs; +use std::path::Path; + +//FIXME(Oneirical): Edit this test to use fs_wrapper and rmake_out_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::create_dir_all(&path_prof_data_dir); + fs::create_dir_all(&path_prof_data_dir).unwrap(); rustc() .input("interesting.rs") .profile_generate(&path_prof_data_dir) @@ -37,5 +40,5 @@ fn main() { .codegen_units(1) .emit("llvm-ir") .run(); - llvm_filecheck().patterns("filecheck-patterns.txt").stdin("interesting_ll").run(); + llvm_filecheck().patterns("filecheck-patterns.txt").stdin("interesting.ll").run(); } From 0bb84af020794435a5ae8c8f8215c24f35403da7 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 11 Jun 2024 13:03:45 -0400 Subject: [PATCH 4/4] simplify llvm helper functions in run_make_support --- src/tools/run-make-support/src/llvm.rs | 23 +++------------------- tests/run-make/pgo-branch-weights/rmake.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs index 4a69fe6032999..408dac4dd4bae 100644 --- a/src/tools/run-make-support/src/llvm.rs +++ b/src/tools/run-make-support/src/llvm.rs @@ -1,5 +1,3 @@ -use std::fs::File; -use std::io::{BufReader, Read, Write}; use std::path::{Path, PathBuf}; use crate::{env_var, Command}; @@ -111,18 +109,9 @@ impl LlvmFilecheck { Self { cmd } } - /// Pipe a file into standard input containing patterns that will be matched against the .patterns(path) call. - pub fn stdin>(&mut self, path: P) -> &mut Self { - let file = File::open(path).unwrap(); - let reader = BufReader::new(file); - let byte_vec = read_bytes(reader).expect("failed to read bytes of standard input"); - let byte_slice = byte_vec.as_slice(); - self.cmd.stdin(std::process::Stdio::piped()); - let mut child = self.cmd.spawn().unwrap(); - let mut stdin = child.stdin.take().unwrap(); - stdin.write_all(byte_slice).unwrap(); - stdin.flush().unwrap(); - child.wait_with_output().unwrap(); + /// Pipe a read file into standard input containing patterns that will be matched against the .patterns(path) call. + pub fn stdin>(&mut self, input: I) -> &mut Self { + self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice()); self } @@ -132,9 +121,3 @@ impl LlvmFilecheck { self } } - -fn read_bytes(mut reader: R) -> Result, std::io::Error> { - let mut buffer = Vec::new(); - reader.read_to_end(&mut buffer)?; - Ok(buffer) -} diff --git a/tests/run-make/pgo-branch-weights/rmake.rs b/tests/run-make/pgo-branch-weights/rmake.rs index a06573c51ee55..33a3dce77c300 100644 --- a/tests/run-make/pgo-branch-weights/rmake.rs +++ b/tests/run-make/pgo-branch-weights/rmake.rs @@ -13,17 +13,15 @@ // (This test has problems generating profdata on mingw. This could use further investigation.) //@ ignore-windows-gnu -use run_make_support::{llvm_filecheck, llvm_profdata, run_with_args, rustc}; +use run_make_support::{fs_wrapper, llvm_filecheck, llvm_profdata, run_with_args, rustc}; use std::fs; use std::path::Path; -//FIXME(Oneirical): Edit this test to use fs_wrapper and rmake_out_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::create_dir_all(&path_prof_data_dir).unwrap(); + fs_wrapper::create_dir_all(&path_prof_data_dir); rustc() .input("interesting.rs") .profile_generate(&path_prof_data_dir) @@ -40,5 +38,8 @@ fn main() { .codegen_units(1) .emit("llvm-ir") .run(); - llvm_filecheck().patterns("filecheck-patterns.txt").stdin("interesting.ll").run(); + llvm_filecheck() + .patterns("filecheck-patterns.txt") + .stdin(fs_wrapper::read("interesting.ll")) + .run(); }