Skip to content

Commit bc0d0fa

Browse files
committed
Add MIR move elimination pass
1 parent 582e38e commit bc0d0fa

25 files changed

Lines changed: 2196 additions & 1 deletion

‎compiler/rustc_index/src/interval.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ impl<R: Idx, C: Step + Idx> SparseIntervalMatrix<R, C> {
374374
self.rows.iter_enumerated()
375375
}
376376

377+
pub fn clear_row(&mut self, row: R) {
378+
if let Some(row) = self.rows.get_mut(row) {
379+
row.clear();
380+
}
381+
}
382+
377383
fn ensure_row(&mut self, row: R) -> &mut IntervalSet<C> {
378384
self.rows.ensure_contains_elem(row, || IntervalSet::new(self.column_size))
379385
}
@@ -397,6 +403,16 @@ impl<R: Idx, C: Step + Idx> SparseIntervalMatrix<R, C> {
397403
write_row.union(read_row)
398404
}
399405

406+
pub fn disjoint_rows(&self, a: R, b: R) -> bool
407+
where
408+
C: Step,
409+
{
410+
let (Some(a), Some(b)) = (self.rows.get(a), self.rows.get(b)) else {
411+
return true;
412+
};
413+
a.disjoint(b)
414+
}
415+
400416
pub fn insert_all_into_row(&mut self, row: R) {
401417
self.ensure_row(row).insert_all();
402418
}

‎compiler/rustc_mir_transform/src/dest_prop.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ pub(super) struct DestinationPropagation;
155155

156156
impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
157157
fn policy(&self, ctx: &crate::PassCtx<'_>) -> PassPolicy {
158-
PassPolicy::optional(ctx.mir_opt_level() >= 2)
158+
PassPolicy::optional(
159+
ctx.mir_opt_level() >= 2 && !ctx.opts.unstable_opts.mir_move_elimination,
160+
)
159161
}
160162

161163
#[tracing::instrument(level = "trace", skip(self, tcx, body))]

‎compiler/rustc_mir_transform/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ declare_passes! {
164164
mod lower_slice_len : LowerSliceLenCalls;
165165
mod match_branches : MatchBranchSimplification;
166166
mod mentioned_items : MentionedItems;
167+
mod move_elimination : MoveElimination;
167168
mod multiple_return_terminators : MultipleReturnTerminators;
168169
mod post_drop_elaboration : CheckLiveDrops;
169170
mod prettify : ReorderBasicBlocks, ReorderLocals;
@@ -763,6 +764,7 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
763764
&dead_store_elimination::DeadStoreElimination::Final,
764765
&dest_prop::DestinationPropagation,
765766
&tail_copy_to_move::TailCopyToMove,
767+
&move_elimination::MoveElimination,
766768
&simplify::SimplifyLocals::Final,
767769
&multiple_return_terminators::MultipleReturnTerminators,
768770
// Some cleanup necessary at least for LLVM and potentially other codegen backends.

0 commit comments

Comments
 (0)