Skip to content

Commit 71e589a

Browse files
committed
implement move up propagation without post dominators
1 parent 42001ed commit 71e589a

File tree

8 files changed

+701
-3
lines changed

8 files changed

+701
-3
lines changed

src/librustc/mir/repr.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ impl<'tcx> Mir<'tcx> {
180180
Some(Local::new(idx))
181181
}
182182

183+
pub fn from_local_index_to_temp(&self, local: Local) -> Option<Temp> {
184+
let num_args_and_vars = self.arg_decls.len() + self.var_decls.len();
185+
if local.index() < num_args_and_vars {
186+
None
187+
} else if local.index() >= num_args_and_vars + self.temp_decls.len() {
188+
None
189+
} else {
190+
Some(Temp::new(local.index() - num_args_and_vars))
191+
}
192+
}
193+
pub fn from_local_index_to_var(&self, local: Local) -> Option<Var> {
194+
let num_args = self.arg_decls.len();
195+
if local.index() < num_args {
196+
None
197+
} else if local.index() >= num_args + self.var_decls.len() {
198+
None
199+
} else {
200+
Some(Var::new(local.index() - num_args))
201+
}
202+
}
203+
183204
/// Counts the number of locals, such that that local_index
184205
/// will always return an index smaller than this count.
185206
pub fn count_locals(&self) -> usize {
@@ -710,7 +731,7 @@ newtype_index!(Local, "local");
710731

711732
/// A path to a value; something that can be evaluated without
712733
/// changing or disturbing program state.
713-
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
734+
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Eq, Hash)]
714735
pub enum Lvalue<'tcx> {
715736
/// local variable declared by the user
716737
Var(Var),
@@ -868,7 +889,7 @@ pub struct VisibilityScopeData {
868889
/// These are values that can appear inside an rvalue (or an index
869890
/// lvalue). They are intentionally limited to prevent rvalues from
870891
/// being nested in one another.
871-
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
892+
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Eq, Hash)]
872893
pub enum Operand<'tcx> {
873894
Consume(Lvalue<'tcx>),
874895
Constant(Constant<'tcx>),

src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
998998
passes.push_pass(box mir::transform::deaggregator::Deaggregator);
999999

10001000
passes.push_pass(box mir::transform::add_call_guards::AddCallGuards);
1001+
passes.push_pass(box mir::transform::move_up_propagation::MoveUpPropagation);
10011002
passes.push_pass(box mir::transform::dump_mir::Marker("PreTrans"));
10021003

10031004
passes.run_passes(tcx, &mut mir_map);

src/librustc_mir/transform/dump_mir.rs

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ pub struct Disambiguator<'a> {
3434
is_after: bool
3535
}
3636

37+
impl<'a> Disambiguator<'a> {
38+
pub fn new(pass: &'a Pass, is_after: bool) -> Self {
39+
Disambiguator {
40+
pass: pass,
41+
is_after : is_after
42+
}
43+
}
44+
}
45+
3746
impl<'a> fmt::Display for Disambiguator<'a> {
3847
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
3948
let title = if self.is_after { "after" } else { "before" };

src/librustc_mir/transform/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ pub mod promote_consts;
1818
pub mod qualify_consts;
1919
pub mod dump_mir;
2020
pub mod deaggregator;
21+
pub mod move_up_propagation;
22+

0 commit comments

Comments
 (0)