Skip to content

Commit 2c2d05c

Browse files
committed
implement move up propagation without post dominators
1 parent 9316ae5 commit 2c2d05c

File tree

7 files changed

+653
-7
lines changed

7 files changed

+653
-7
lines changed

src/librustc/mir/repr.rs

+27-6
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 {
@@ -680,13 +701,13 @@ pub enum AssertMessage<'tcx> {
680701
///////////////////////////////////////////////////////////////////////////
681702
// Statements
682703

683-
#[derive(Clone, RustcEncodable, RustcDecodable)]
704+
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, PartialEq)]
684705
pub struct Statement<'tcx> {
685706
pub source_info: SourceInfo,
686707
pub kind: StatementKind<'tcx>,
687708
}
688709

689-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
710+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, Eq, PartialEq)]
690711
pub enum StatementKind<'tcx> {
691712
Assign(Lvalue<'tcx>, Rvalue<'tcx>),
692713
}
@@ -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>),
@@ -887,7 +908,7 @@ impl<'tcx> Debug for Operand<'tcx> {
887908
///////////////////////////////////////////////////////////////////////////
888909
/// Rvalues
889910
890-
#[derive(Clone, RustcEncodable, RustcDecodable)]
911+
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, PartialEq)]
891912
pub enum Rvalue<'tcx> {
892913
/// x (either a move or copy, depending on type of x)
893914
Use(Operand<'tcx>),
@@ -1113,7 +1134,7 @@ pub struct Constant<'tcx> {
11131134
pub literal: Literal<'tcx>,
11141135
}
11151136

1116-
#[derive(Clone, RustcEncodable, RustcDecodable)]
1137+
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, PartialEq)]
11171138
pub struct TypedConstVal<'tcx> {
11181139
pub ty: Ty<'tcx>,
11191140
pub span: Span,

src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
999999
passes.push_pass(box mir::transform::simplify_cfg::SimplifyCfg::new("elaborate-drops"));
10001000

10011001
passes.push_pass(box mir::transform::add_call_guards::AddCallGuards);
1002+
passes.push_pass(box mir::transform::move_up_propagation::MoveUpPropagation);
10021003
passes.push_pass(box mir::transform::dump_mir::Marker("PreTrans"));
10031004

10041005
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

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ pub mod add_call_guards;
1717
pub mod promote_consts;
1818
pub mod qualify_consts;
1919
pub mod dump_mir;
20+
pub mod move_up_propagation;

0 commit comments

Comments
 (0)