Rollup merge of #122656 - RalfJung:simplify-cfg, r=compiler-errors

simplify_cfg: rename some passes so that they make more sense

I was extremely confused by `SimplifyCfg::ElaborateDrops`, since it runs way later than drop elaboration. It is used e.g. in `mir-opt/retag.rs` even though that pass doesn't care about drop elaboration at all.

"Early opt" is also very confusing since that makes it sounds like it runs early during optimizations, i.e. on runtime MIR, but actually it runs way before that.

So I decided to rename
- early-opt -> post-analysis
- elaborate-drops -> pre-optimizations

I am open to other suggestions.
This commit is contained in:
Matthias Krüger 2024-03-18 06:58:50 +01:00 committed by GitHub
commit 3fc3142df1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 43 additions and 40 deletions

View file

@ -507,7 +507,7 @@ fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let passes: &[&dyn MirPass<'tcx>] = &[
&cleanup_post_borrowck::CleanupPostBorrowck,
&remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::EarlyOpt,
&simplify::SimplifyCfg::PostAnalysis,
&deref_separator::Derefer,
];
@ -544,7 +544,7 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let passes: &[&dyn MirPass<'tcx>] = &[
&lower_intrinsics::LowerIntrinsics,
&remove_place_mention::RemovePlaceMention,
&simplify::SimplifyCfg::ElaborateDrops,
&simplify::SimplifyCfg::PreOptimizations,
];
pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup)));

View file

@ -37,8 +37,11 @@ pub enum SimplifyCfg {
Initial,
PromoteConsts,
RemoveFalseEdges,
EarlyOpt,
ElaborateDrops,
/// Runs at the beginning of "analysis to runtime" lowering, *before* drop elaboration.
PostAnalysis,
/// Runs at the end of "analysis to runtime" lowering, *after* drop elaboration.
/// This is before the main optimization passes on runtime MIR kick in.
PreOptimizations,
Final,
MakeShim,
AfterUninhabitedEnumBranching,
@ -50,8 +53,8 @@ pub fn name(&self) -> &'static str {
SimplifyCfg::Initial => "SimplifyCfg-initial",
SimplifyCfg::PromoteConsts => "SimplifyCfg-promote-consts",
SimplifyCfg::RemoveFalseEdges => "SimplifyCfg-remove-false-edges",
SimplifyCfg::EarlyOpt => "SimplifyCfg-early-opt",
SimplifyCfg::ElaborateDrops => "SimplifyCfg-elaborate-drops",
SimplifyCfg::PostAnalysis => "SimplifyCfg-post-analysis",
SimplifyCfg::PreOptimizations => "SimplifyCfg-pre-optimizations",
SimplifyCfg::Final => "SimplifyCfg-final",
SimplifyCfg::MakeShim => "SimplifyCfg-make_shim",
SimplifyCfg::AfterUninhabitedEnumBranching => {

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -1,4 +1,4 @@
//@ unit-test: SimplifyCfg-elaborate-drops
//@ unit-test: SimplifyCfg-pre-optimizations
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// Retagging (from Stacked Borrows) relies on the array index being a fresh
// temporary, so that side-effects cannot change it.
@ -10,7 +10,7 @@ unsafe fn foo(z: *mut usize) -> u32 {
}
// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
// CHECK-LABEL: fn main(
// CHECK: debug x => [[x:_.*]];

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -1,7 +1,7 @@
// skip-filecheck
//@ compile-flags: -Z mir-opt-level=0
// EMIT_MIR byte_slice.main.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR byte_slice.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
let x = b"foo";
let y = [5u8, b'x'];

View file

@ -1,4 +1,4 @@
// MIR for `BAR::promoted[0]` after SimplifyCfg-elaborate-drops
// MIR for `BAR::promoted[0]` after SimplifyCfg-pre-optimizations
const BAR::promoted[0]: &[&i32; 1] = {
let mut _0: &[&i32; 1];

View file

@ -1,4 +1,4 @@
// MIR for `FOO::promoted[0]` after SimplifyCfg-elaborate-drops
// MIR for `FOO::promoted[0]` after SimplifyCfg-pre-optimizations
const FOO::promoted[0]: &[&i32; 1] = {
let mut _0: &[&i32; 1];

View file

@ -6,11 +6,11 @@
static Y: i32 = 42;
// EMIT_MIR const_promotion_extern_static.BAR.PromoteTemps.diff
// EMIT_MIR const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir
static mut BAR: *const &i32 = [&Y].as_ptr();
// EMIT_MIR const_promotion_extern_static.FOO.PromoteTemps.diff
// EMIT_MIR const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir
static mut FOO: *const &i32 = [unsafe { &X }].as_ptr();
// EMIT_MIR const_promotion_extern_static.BOP.built.after.mir

View file

@ -4,7 +4,7 @@
// Ensure that there are no drop terminators in `unwrap<T>` (except the one along the cleanup
// path).
// EMIT_MIR no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.mir
fn unwrap<T>(opt: Option<T>) -> T {
match opt {
Some(x) => x,

View file

@ -1,4 +1,4 @@
// MIR for `unwrap` after SimplifyCfg-elaborate-drops
// MIR for `unwrap` after SimplifyCfg-pre-optimizations
fn unwrap(_1: Option<T>) -> T {
debug opt => _1;

View file

@ -1,4 +1,4 @@
// MIR for `unwrap` after SimplifyCfg-elaborate-drops
// MIR for `unwrap` after SimplifyCfg-pre-optimizations
fn unwrap(_1: Option<T>) -> T {
debug opt => _1;

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -2,7 +2,7 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
let mut x = Packed(Aligned(Droppy(0)));
x.0 = Aligned(Droppy(0));

View file

@ -1,4 +1,4 @@
// MIR for `array_casts` after SimplifyCfg-elaborate-drops
// MIR for `array_casts` after SimplifyCfg-pre-optimizations
fn array_casts() -> () {
let mut _0: ();

View file

@ -1,4 +1,4 @@
// MIR for `array_casts` after SimplifyCfg-elaborate-drops
// MIR for `array_casts` after SimplifyCfg-pre-optimizations
fn array_casts() -> () {
let mut _0: ();

View file

@ -1,4 +1,4 @@
// MIR for `main::{closure#0}` after SimplifyCfg-elaborate-drops
// MIR for `main::{closure#0}` after SimplifyCfg-pre-optimizations
fn main::{closure#0}(_1: &{closure@main::{closure#0}}, _2: &i32) -> &i32 {
debug x => _2;

View file

@ -1,4 +1,4 @@
// MIR for `main::{closure#0}` after SimplifyCfg-elaborate-drops
// MIR for `main::{closure#0}` after SimplifyCfg-pre-optimizations
fn main::{closure#0}(_1: &{closure@main::{closure#0}}, _2: &i32) -> &i32 {
debug x => _2;

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -1,4 +1,4 @@
// MIR for `main` after SimplifyCfg-elaborate-drops
// MIR for `main` after SimplifyCfg-pre-optimizations
fn main() -> () {
let mut _0: ();

View file

@ -8,8 +8,8 @@
struct Test(i32);
// EMIT_MIR retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.mir
// EMIT_MIR retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.mir
impl Test {
// Make sure we run the pass on a method, not just on bare functions.
fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 {
@ -26,8 +26,8 @@ impl Drop for Test {
fn drop(&mut self) {}
}
// EMIT_MIR retag.main.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR retag.main.SimplifyCfg-pre-optimizations.after.mir
// EMIT_MIR retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.mir
pub fn main() {
let mut x = 0;
{
@ -55,7 +55,7 @@ pub fn main() {
}
/// Casting directly to an array should also go through `&raw` and thus add appropriate retags.
// EMIT_MIR retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR retag.array_casts.SimplifyCfg-pre-optimizations.after.mir
fn array_casts() {
let mut x: [usize; 2] = [0, 0];
let p = &mut x as *mut usize;

View file

@ -1,4 +1,4 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-elaborate-drops
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-pre-optimizations
fn <impl at $DIR/retag.rs:13:1: 13:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 {
debug self => _1;

View file

@ -1,4 +1,4 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-elaborate-drops
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-pre-optimizations
fn <impl at $DIR/retag.rs:13:1: 13:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 {
debug self => _1;

View file

@ -1,4 +1,4 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-elaborate-drops
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-pre-optimizations
fn <impl at $DIR/retag.rs:13:1: 13:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
debug self => _1;

View file

@ -1,4 +1,4 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-elaborate-drops
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-pre-optimizations
fn <impl at $DIR/retag.rs:13:1: 13:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
debug self => _1;

View file

@ -1,5 +1,5 @@
- // MIR for `main` before SimplifyCfg-early-opt
+ // MIR for `main` after SimplifyCfg-early-opt
- // MIR for `main` before SimplifyCfg-post-analysis
+ // MIR for `main` after SimplifyCfg-post-analysis
fn main() -> () {
let mut _0: ();

View file

@ -4,7 +4,7 @@
//@ no-prefer-dynamic
// EMIT_MIR simplify_cfg.main.SimplifyCfg-initial.diff
// EMIT_MIR simplify_cfg.main.SimplifyCfg-early-opt.diff
// EMIT_MIR simplify_cfg.main.SimplifyCfg-post-analysis.diff
fn main() {
loop {
if bar() {