Skip to content

Commit eab3d97

Browse files
committed
Auto merge of rust-lang#156535 - JonathanBrouwer:rollup-9oxBSQK, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - rust-lang#156472 (Add support for Zprint-codegen-stats-json) - rust-lang#156504 (bootstrap: remap windows-style OUT_DIR paths) - rust-lang#156513 (miri subtree update) - rust-lang#156524 (Remove the dummy `PreCodegen` mir-opt pass, and use `runtime-optimized` instead) - rust-lang#156325 (Don't treat const param default as projection)
2 parents c8c4c83 + f6faa05 commit eab3d97

234 files changed

Lines changed: 2430 additions & 1147 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 259 additions & 23 deletions
Large diffs are not rendered by default.

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ impl CodegenBackend for LlvmCodegenBackend {
373373
print!("{stats}");
374374
}
375375

376+
fn print_statistics_json(&self) -> String {
377+
llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatisticsJSON(s) }).unwrap()
378+
}
379+
376380
fn link(
377381
&self,
378382
sess: &Session,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,9 @@ unsafe extern "C" {
21142114
/// Prints the statistics collected by `-Zprint-codegen-stats`.
21152115
pub(crate) fn LLVMRustPrintStatistics(OutStr: &RustString);
21162116

2117+
/// Save the statistics collected by `-Zprint-codegen-stats-json`
2118+
pub(crate) fn LLVMRustPrintStatisticsJSON(OutStr: &RustString);
2119+
21172120
pub(crate) fn LLVMRustInlineAsmVerify(
21182121
Ty: &Type,
21192122
Constraints: *const c_uchar, // See "PTR_LEN_STR".

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ unsafe fn configure_llvm(sess: &Session) {
120120
// Use non-zero `import-instr-limit` multiplier for cold callsites.
121121
add("-import-cold-multiplier=0.1", false);
122122

123-
if sess.print_llvm_stats() {
123+
if sess.print_llvm_stats() || sess.print_llvm_stats_json().is_some() {
124124
add("-stats", false);
125125
}
126126

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ pub trait CodegenBackend {
131131

132132
fn print_statistics(&self) {}
133133

134+
fn print_statistics_json(&self) -> String {
135+
String::new()
136+
}
137+
134138
/// This is called on the returned [`CompiledModules`] from [`join_codegen`](Self::join_codegen).
135139
fn link(
136140
&self,

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_macros = { path = "../rustc_macros" }
2727
rustc_metadata = { path = "../rustc_metadata" }
2828
rustc_middle = { path = "../rustc_middle" }
2929
rustc_mir_build = { path = "../rustc_mir_build" }
30-
rustc_mir_transform = { path = "../rustc_mir_transform" }
3130
rustc_parse = { path = "../rustc_parse" }
3231
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
3332
rustc_resolve = { path = "../rustc_resolve" }

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
// tidy-alphabetical-start
88
#![feature(decl_macro)]
9+
#![feature(file_buffered)]
910
#![feature(panic_backtrace_config)]
1011
#![feature(panic_update_hook)]
1112
#![feature(trim_prefix_suffix)]
@@ -333,7 +334,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
333334
}
334335

335336
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
336-
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
337+
if let Err(error) = pretty::emit_mir(tcx) {
337338
tcx.dcx().emit_fatal(CantEmitMIR { error });
338339
}
339340
}

compiler/rustc_driver_impl/src/pretty.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::cell::Cell;
44
use std::fmt::Write;
5+
use std::fs::File;
6+
use std::io;
57

68
use rustc_ast as ast;
79
use rustc_ast_pretty::pprust as pprust_ast;
@@ -12,7 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
1214
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
1315
use rustc_public::rustc_internal::pretty::write_smir_pretty;
1416
use rustc_session::Session;
15-
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
17+
use rustc_session::config::{OutFileName, OutputType, PpHirMode, PpMode, PpSourceMode};
1618
use rustc_span::{FileName, Ident};
1719
use tracing::debug;
1820

@@ -340,3 +342,21 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
340342

341343
write_or_print(&out, sess);
342344
}
345+
346+
/// Implementation of `--emit=mir`.
347+
pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
348+
match tcx.output_filenames(()).path(OutputType::Mir) {
349+
OutFileName::Stdout => {
350+
let mut f = io::stdout();
351+
write_mir_pretty(tcx, &mut f)?;
352+
}
353+
OutFileName::Real(path) => {
354+
let mut f = File::create_buffered(&path)?;
355+
write_mir_pretty(tcx, &mut f)?;
356+
if tcx.sess.opts.json_artifact_notifications {
357+
tcx.dcx().emit_artifact_notification(&path, "mir");
358+
}
359+
}
360+
}
361+
Ok(())
362+
}

compiler/rustc_interface/src/queries.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ impl Linker {
7070
codegen_backend.print_statistics()
7171
}
7272

73+
if let Some(out_path) = sess.print_llvm_stats_json() {
74+
let llvm_stats_json = codegen_backend.print_statistics_json();
75+
76+
if !llvm_stats_json.is_empty() {
77+
if let Err(e) = std::fs::write(&out_path, llvm_stats_json) {
78+
sess.dcx().err(format!("failed to write stats to {}: {}", out_path, e));
79+
}
80+
} else {
81+
sess.dcx().warn(format!(
82+
"requested to print LLVM statistics to JSON file {}, but the codegen backend \
83+
did not provide any statistics",
84+
out_path,
85+
));
86+
}
87+
}
88+
7389
sess.timings.end_section(sess.dcx(), TimingSection::Codegen);
7490

7591
if sess.opts.incremental.is_some()

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ extern "C" void LLVMRustPrintStatistics(RustStringRef OutBuf) {
155155
llvm::PrintStatistics(OS);
156156
}
157157

158+
extern "C" void LLVMRustPrintStatisticsJSON(RustStringRef OutBuf) {
159+
auto OS = RawRustStringOstream(OutBuf);
160+
llvm::PrintStatisticsJSON(OS);
161+
}
162+
158163
// Some of the functions here rely on LLVM modules that may not always be
159164
// available. As such, we only try to build it in the first place, if
160165
// llvm.offload is enabled.

0 commit comments

Comments
 (0)