diff options
| author | kadmin <julianknodt@gmail.com> | 2023-02-05 22:14:40 +0000 |
|---|---|---|
| committer | kadmin <julianknodt@gmail.com> | 2023-02-08 02:04:07 +0000 |
| commit | 15d4728cda673e90b4db1ea2c60d18a6fae306d0 (patch) | |
| tree | 6fc14e55485198c4b29ea73f9c7619e1bda9644e /compiler/rustc_mir_transform/src | |
| parent | 15f4eec7a986e6c9125ff3e0115d70aef6d5c711 (diff) | |
| download | rust-15d4728cda673e90b4db1ea2c60d18a6fae306d0.tar.gz rust-15d4728cda673e90b4db1ea2c60d18a6fae306d0.zip | |
Add de-init to destination place
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/large_enums.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/lib.rs | 2 |
2 files changed, 11 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index 3f8662ad697..89f8de23583 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::interpret::AllocId; use rustc_middle::mir::*; use rustc_middle::ty::{self, AdtDef, Const, ParamEnv, Ty, TyCtxt}; +use rustc_session::Session; use rustc_target::abi::{HasDataLayout, Size, TagEncoding, Variants}; /// A pass that seeks to optimize unnecessary moves of large enum types, if there is a large @@ -28,14 +29,12 @@ pub struct EnumSizeOpt { } impl<'tcx> MirPass<'tcx> for EnumSizeOpt { + fn is_enabled(&self, sess: &Session) -> bool { + sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3 + } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let sess = tcx.sess; - // FIXME(julianknodt): one thing noticed while testing this mir-opt is that there is a - // different layout of large enums on wasm. It's not clear what is causing this layout - // difference, as it should be identical to i686 (32 bit). - if (!sess.opts.unstable_opts.unsound_mir_opts) || sess.mir_opt_level() < 3 { - return; - } + // NOTE: This pass may produce different MIR based on the alignment of the target + // platform, but it will still be valid. self.optim(tcx, body); } } @@ -254,6 +253,9 @@ impl EnumSizeOpt { )), }; + let deinit_old = + Statement { source_info, kind: StatementKind::Deinit(box dst) }; + let copy_bytes = Statement { source_info, kind: StatementKind::Intrinsic( @@ -279,6 +281,7 @@ impl EnumSizeOpt { dst_cast, src_ptr, src_cast, + deinit_old, copy_bytes, store_dead, ] diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index be3652dd3e7..45cd4024c9f 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -547,7 +547,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { tcx, body, &[ - &large_enums::EnumSizeOpt { discrepancy: 128 }, &reveal_all::RevealAll, // has to be done before inlining, since inlined code is in RevealAll mode. &lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first &unreachable_prop::UnreachablePropagation, @@ -586,6 +585,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &simplify::SimplifyLocals::new("final"), &multiple_return_terminators::MultipleReturnTerminators, &deduplicate_blocks::DeduplicateBlocks, + &large_enums::EnumSizeOpt { discrepancy: 128 }, // Some cleanup necessary at least for LLVM and potentially other codegen backends. &add_call_guards::CriticalCallEdges, // Dump the end result for testing and debugging purposes. |
