Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3831,7 +3831,6 @@ dependencies = [
"rustc_metadata",
"rustc_middle",
"rustc_mir_build",
"rustc_mir_transform",
"rustc_parse",
"rustc_public",
"rustc_resolve",
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_middle = { path = "../rustc_middle" }
rustc_mir_build = { path = "../rustc_mir_build" }
rustc_mir_transform = { path = "../rustc_mir_transform" }
rustc_parse = { path = "../rustc_parse" }
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
rustc_resolve = { path = "../rustc_resolve" }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// tidy-alphabetical-start
#![feature(decl_macro)]
#![feature(file_buffered)]
#![feature(panic_backtrace_config)]
#![feature(panic_update_hook)]
#![feature(trim_prefix_suffix)]
Expand Down Expand Up @@ -333,7 +334,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
}

if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
if let Err(error) = pretty::emit_mir(tcx) {
tcx.dcx().emit_fatal(CantEmitMIR { error });
}
}
Expand Down
22 changes: 21 additions & 1 deletion compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use std::cell::Cell;
use std::fmt::Write;
use std::fs::File;
use std::io;

use rustc_ast as ast;
use rustc_ast_pretty::pprust as pprust_ast;
Expand All @@ -12,7 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
use rustc_public::rustc_internal::pretty::write_smir_pretty;
use rustc_session::Session;
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
use rustc_session::config::{OutFileName, OutputType, PpHirMode, PpMode, PpSourceMode};
use rustc_span::{FileName, Ident};
use tracing::debug;

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

write_or_print(&out, sess);
}

/// Implementation of `--emit=mir`.
pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
match tcx.output_filenames(()).path(OutputType::Mir) {
OutFileName::Stdout => {
let mut f = io::stdout();
write_mir_pretty(tcx, &mut f)?;
}
OutFileName::Real(path) => {
let mut f = File::create_buffered(&path)?;
write_mir_pretty(tcx, &mut f)?;
if tcx.sess.opts.json_artifact_notifications {
tcx.dcx().emit_artifact_notification(&path, "mir");
}
}
}
Ok(())
}
39 changes: 0 additions & 39 deletions compiler/rustc_mir_transform/src/dump_mir.rs

This file was deleted.

6 changes: 0 additions & 6 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![feature(box_patterns)]
#![feature(const_type_name)]
#![feature(cow_is_borrowed)]
#![feature(file_buffered)]
#![feature(impl_trait_in_assoc_type)]
#![feature(iterator_try_collect)]
#![feature(try_blocks)]
Expand Down Expand Up @@ -91,8 +90,6 @@ macro_rules! declare_passes {

static PASS_NAMES: LazyLock<FxIndexSet<&str>> = LazyLock::new(|| {
let mut set = FxIndexSet::default();
// Fake marker pass
set.insert("PreCodegen");
$(
$(
set.extend(pass_names!($mod_name : $pass_name $( { $($ident),* } )? ));
Expand Down Expand Up @@ -145,7 +142,6 @@ declare_passes! {
};
mod deref_separator : Derefer;
mod dest_prop : DestinationPropagation;
pub mod dump_mir : Marker;
mod early_otherwise_branch : EarlyOtherwiseBranch;
mod erase_deref_temps : EraseDerefTemps;
mod elaborate_box_derefs : ElaborateBoxDerefs;
Expand Down Expand Up @@ -771,8 +767,6 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
// Cleanup for human readability, off by default.
&prettify::ReorderBasicBlocks,
&prettify::ReorderLocals,
// Dump the end result for testing and debugging purposes.
&dump_mir::Marker("PreCodegen"),
],
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
optimizations,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `foo` after PreCodegen
// MIR for `foo` after runtime-optimized

fn foo(_1: Option<String>) -> i32 {
debug s => _1;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/match/deref-patterns/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![feature(deref_patterns)]
#![crate_type = "lib"]

// EMIT_MIR string.foo.PreCodegen.after.mir
// EMIT_MIR string.foo.runtime-optimized.after.mir
pub fn foo(s: Option<String>) -> i32 {
match s {
Some("a") => 1234,
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/while_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn get_bool(c: bool) -> bool {
c
}

// EMIT_MIR while_storage.while_loop.PreCodegen.after.mir
// EMIT_MIR while_storage.while_loop.runtime-optimized.after.mir
fn while_loop(c: bool) {
// CHECK-LABEL: fn while_loop(
// CHECK: bb0: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `while_loop` after PreCodegen
// MIR for `while_loop` after runtime-optimized

fn while_loop(_1: bool) -> () {
debug c => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `while_loop` after PreCodegen
// MIR for `while_loop` after runtime-optimized

fn while_loop(_1: bool) -> () {
debug c => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `hello` before PreCodegen
// MIR for `hello` after runtime-optimized

fn hello() -> () {
let mut _0: ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `hello` before PreCodegen
// MIR for `hello` after runtime-optimized

fn hello() -> () {
let mut _0: ();
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/control_flow_simplification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait NeedsDrop: Sized {
impl<This> NeedsDrop for This {}

// EMIT_MIR control_flow_simplification.hello.GVN.diff
// EMIT_MIR control_flow_simplification.hello.PreCodegen.before.mir
// EMIT_MIR control_flow_simplification.hello.runtime-optimized.after.mir
fn hello<T>() {
// CHECK-LABEL: fn hello(
// CHECK: bb0:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `add` before PreCodegen
// MIR for `add` after runtime-optimized

fn add() -> u32 {
let mut _0: u32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `add` before PreCodegen
// MIR for `add` after runtime-optimized

fn add() -> u32 {
let mut _0: u32;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/return_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ compile-flags: -C overflow-checks=on -Zdump-mir-exclude-alloc-bytes

// EMIT_MIR return_place.add.GVN.diff
// EMIT_MIR return_place.add.PreCodegen.before.mir
// EMIT_MIR return_place.add.runtime-optimized.after.mir
fn add() -> u32 {
// CHECK-LABEL: fn add(
// CHECK: _0 = const 4_u32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `caller` after PreCodegen
// MIR for `caller` after runtime-optimized

fn caller() -> () {
let mut _0: ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `caller` after PreCodegen
// MIR for `caller` after runtime-optimized

fn caller() -> () {
let mut _0: ();
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/inline/rustc_no_mir_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
pub fn callee() {}

// EMIT_MIR rustc_no_mir_inline.caller.Inline.diff
// EMIT_MIR rustc_no_mir_inline.caller.PreCodegen.after.mir
// EMIT_MIR rustc_no_mir_inline.caller.runtime-optimized.after.mir
pub fn caller() {
// CHECK-LABEL: fn caller(
// CHECK: callee()
Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/inline/unchecked_shifts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
// After MCP#693, though, that's the backend's problem, not something in MIR.

// EMIT_MIR unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.diff
// EMIT_MIR unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.mir
// EMIT_MIR unchecked_shifts.unchecked_shl_unsigned_smaller.runtime-optimized.after.mir
pub unsafe fn unchecked_shl_unsigned_smaller(a: u16, b: u32) -> u16 {
// CHECK-LABEL: fn unchecked_shl_unsigned_smaller(
// CHECK: (inlined #[track_caller] core::num::<impl u16>::unchecked_shl)
a.unchecked_shl(b)
}

// EMIT_MIR unchecked_shifts.unchecked_shr_signed_bigger.Inline.diff
// EMIT_MIR unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.mir
// EMIT_MIR unchecked_shifts.unchecked_shr_signed_bigger.runtime-optimized.after.mir
pub unsafe fn unchecked_shr_signed_bigger(a: i64, b: u32) -> i64 {
// CHECK-LABEL: fn unchecked_shr_signed_bigger(
// CHECK: (inlined #[track_caller] core::num::<impl i64>::unchecked_shr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `unchecked_shl_unsigned_smaller` after PreCodegen
// MIR for `unchecked_shl_unsigned_smaller` after runtime-optimized

fn unchecked_shl_unsigned_smaller(_1: u16, _2: u32) -> u16 {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `unchecked_shl_unsigned_smaller` after PreCodegen
// MIR for `unchecked_shl_unsigned_smaller` after runtime-optimized

fn unchecked_shl_unsigned_smaller(_1: u16, _2: u32) -> u16 {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `unchecked_shr_signed_bigger` after PreCodegen
// MIR for `unchecked_shr_signed_bigger` after runtime-optimized

fn unchecked_shr_signed_bigger(_1: i64, _2: u32) -> i64 {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `unchecked_shr_signed_bigger` after PreCodegen
// MIR for `unchecked_shr_signed_bigger` after runtime-optimized

fn unchecked_shr_signed_bigger(_1: i64, _2: u32) -> i64 {
debug a => _1;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/inline/unwrap_unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ compile-flags: -Zmir-opt-level=2 -Zinline-mir

// EMIT_MIR unwrap_unchecked.unwrap_unchecked.Inline.diff
// EMIT_MIR unwrap_unchecked.unwrap_unchecked.PreCodegen.after.mir
// EMIT_MIR unwrap_unchecked.unwrap_unchecked.runtime-optimized.after.mir
pub unsafe fn unwrap_unchecked<T>(slf: Option<T>) -> T {
// CHECK-LABEL: fn unwrap_unchecked(
// CHECK: (inlined #[track_caller] Option::<T>::unwrap_unchecked)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `unwrap_unchecked` after PreCodegen
// MIR for `unwrap_unchecked` after runtime-optimized

fn unwrap_unchecked(_1: Option<T>) -> T {
debug slf => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `unwrap_unchecked` after PreCodegen
// MIR for `unwrap_unchecked` after runtime-optimized

fn unwrap_unchecked(_1: Option<T>) -> T {
debug slf => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `num_to_digit` after PreCodegen
// MIR for `num_to_digit` after runtime-optimized

fn num_to_digit(_1: char) -> u32 {
debug num => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `num_to_digit` after PreCodegen
// MIR for `num_to_digit` after runtime-optimized

fn num_to_digit(_1: char) -> u32 {
debug num => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `num_to_digit` after PreCodegen
// MIR for `num_to_digit` after runtime-optimized

fn num_to_digit(_1: char) -> u32 {
debug num => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `num_to_digit` after PreCodegen
// MIR for `num_to_digit` after runtime-optimized

fn num_to_digit(_1: char) -> u32 {
debug num => _1;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/issues/issue_59352.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Once the optimizer can do that, this test case will need to be updated and codegen/issue-59352.rs
// removed.

// EMIT_MIR issue_59352.num_to_digit.PreCodegen.after.mir
// EMIT_MIR issue_59352.num_to_digit.runtime-optimized.after.mir
//@ compile-flags: -Z mir-opt-level=3 -Z span_free_formats

pub fn num_to_digit(num: char) -> u32 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after PreCodegen
// MIR for `main` after runtime-optimized

fn main() -> () {
let mut _0: ();
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/pattern_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::pat::pattern_type;

// EMIT_MIR pattern_types.main.PreCodegen.after.mir
// EMIT_MIR pattern_types.main.runtime-optimized.after.mir
fn main() {
// CHECK: debug x => const 2_u32 is 1..
let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `eq_ipv4` after PreCodegen
// MIR for `eq_ipv4` after runtime-optimized

fn eq_ipv4(_1: &[u8; 4], _2: &[u8; 4]) -> bool {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `eq_ipv4` after PreCodegen
// MIR for `eq_ipv4` after runtime-optimized

fn eq_ipv4(_1: &[u8; 4], _2: &[u8; 4]) -> bool {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `eq_ipv6` after PreCodegen
// MIR for `eq_ipv6` after runtime-optimized

fn eq_ipv6(_1: &[u16; 8], _2: &[u16; 8]) -> bool {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `eq_ipv6` after PreCodegen
// MIR for `eq_ipv6` after runtime-optimized

fn eq_ipv6(_1: &[u16; 8], _2: &[u16; 8]) -> bool {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `eq_odd_length` after PreCodegen
// MIR for `eq_odd_length` after runtime-optimized

fn eq_odd_length(_1: &[u8; 3], _2: &[u8; 3]) -> bool {
debug a => _1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `eq_odd_length` after PreCodegen
// MIR for `eq_odd_length` after runtime-optimized

fn eq_odd_length(_1: &[u8; 3], _2: &[u8; 3]) -> bool {
debug a => _1;
Expand Down
Loading
Loading