Skip to content

[MIR] Implement move up propagation without post dominators #34693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 23 additions & 2 deletions src/librustc/mir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ impl<'tcx> Mir<'tcx> {
Some(Local::new(idx))
}

pub fn from_local_index_to_temp(&self, local: Local) -> Option<Temp> {
let num_args_and_vars = self.arg_decls.len() + self.var_decls.len();
if local.index() < num_args_and_vars {
None
} else if local.index() >= num_args_and_vars + self.temp_decls.len() {
None
} else {
Some(Temp::new(local.index() - num_args_and_vars))
}
}
pub fn from_local_index_to_var(&self, local: Local) -> Option<Var> {
let num_args = self.arg_decls.len();
if local.index() < num_args {
None
} else if local.index() >= num_args + self.var_decls.len() {
None
} else {
Some(Var::new(local.index() - num_args))
}
}

/// Counts the number of locals, such that that local_index
/// will always return an index smaller than this count.
pub fn count_locals(&self) -> usize {
Expand Down Expand Up @@ -710,7 +731,7 @@ newtype_index!(Local, "local");

/// A path to a value; something that can be evaluated without
/// changing or disturbing program state.
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Eq, Hash)]
pub enum Lvalue<'tcx> {
/// local variable declared by the user
Var(Var),
Expand Down Expand Up @@ -868,7 +889,7 @@ pub struct VisibilityScopeData {
/// These are values that can appear inside an rvalue (or an index
/// lvalue). They are intentionally limited to prevent rvalues from
/// being nested in one another.
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Eq, Hash)]
pub enum Operand<'tcx> {
Consume(Lvalue<'tcx>),
Constant(Constant<'tcx>),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
passes.push_pass(box mir::transform::deaggregator::Deaggregator);

passes.push_pass(box mir::transform::add_call_guards::AddCallGuards);
passes.push_pass(box mir::transform::move_up_propagation::MoveUpPropagation);
passes.push_pass(box mir::transform::dump_mir::Marker("PreTrans"));

passes.run_passes(tcx, &mut mir_map);
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_mir/transform/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ pub struct Disambiguator<'a> {
is_after: bool
}

impl<'a> Disambiguator<'a> {
pub fn new(pass: &'a Pass, is_after: bool) -> Self {
Disambiguator {
pass: pass,
is_after : is_after
}
}
}

impl<'a> fmt::Display for Disambiguator<'a> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let title = if self.is_after { "after" } else { "before" };
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ pub mod promote_consts;
pub mod qualify_consts;
pub mod dump_mir;
pub mod deaggregator;
pub mod move_up_propagation;

Loading