Skip to content

Commit

Permalink
mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jun 3, 2024
1 parent 9a1a5a2 commit 42d586c
Show file tree
Hide file tree
Showing 5 changed files with 1,231 additions and 3 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ mod normalize_array_len;
mod nrvo;
mod prettify;
mod promote_consts;
mod promote_consts_local_arrays;
mod ref_prop;
mod remove_noop_landing_pads;
mod remove_storage_markers;
Expand Down Expand Up @@ -352,14 +353,22 @@ fn mir_promoted(

// What we need to run borrowck etc.
let promote_pass = promote_consts::PromoteTemps::default();
let promote_array = promote_consts_local_arrays::PromoteArraysOpt::default();
pm::run_passes(
tcx,
&mut body,
&[&promote_pass, &simplify::SimplifyCfg::PromoteConsts, &coverage::InstrumentCoverage],
&[
&promote_pass,
&promote_array,
&simplify::SimplifyCfg::PromoteConsts,
&coverage::InstrumentCoverage,
],
Some(MirPhase::Analysis(AnalysisPhase::Initial)),
);

let promoted = promote_pass.promoted_fragments.into_inner();
let mut promoted = promote_pass.promoted_fragments.into_inner();
let array_promoted = promote_array.promoted_fragments.into_inner();
promoted.extend(array_promoted);
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
}

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_mir_transform/src/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
// We're only interested in temporaries and the return place
match self.ccx.body.local_kind(index) {
LocalKind::Arg => return,
LocalKind::Temp if self.ccx.body.local_decls[index].is_user_variable() => return,
LocalKind::Temp
if {
let is_user_variable = self.ccx.body.local_decls[index].is_user_variable();
debug!(?is_user_variable);
is_user_variable
} =>
{
return;
}
LocalKind::ReturnPointer | LocalKind::Temp => {}
}

Expand Down
Loading

0 comments on commit 42d586c

Please sign in to comment.