Skip to content

Instantly share code, notes, and snippets.

@PramodBisht
Created June 27, 2018 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PramodBisht/3bf922125f8948f27bf053bcd496c208 to your computer and use it in GitHub Desktop.
Save PramodBisht/3bf922125f8948f27bf053bcd496c208 to your computer and use it in GitHub Desktop.
diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs
index 85458c7..eb5aace 100644
--- a/src/librustc_mir/dataflow/mod.rs
+++ b/src/librustc_mir/dataflow/mod.rs
@@ -11,7 +11,7 @@
use syntax::ast::{self, MetaItem};
use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf};
-use rustc_data_structures::indexed_vec::Idx;
+use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::bitslice::{bitwise, BitwiseOperator};
use rustc::ty::{self, TyCtxt};
@@ -177,6 +177,7 @@ struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O> where O: 'b + BitDenotation
{
builder: &'b mut DataflowAnalysis<'a, 'tcx, O>,
changed: bool,
+ first_iteration: bool,
}
impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
@@ -186,10 +187,13 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
let mut propcx = PropagationContext {
builder: self,
changed: true,
+ first_iteration: true
};
- while propcx.changed {
- propcx.changed = false;
- propcx.walk_cfg(&mut temp);
+ let mut dirty_list: IndexVec<BasicBlock, BasicBlockData<'tcx>> = IndexVec::new();
+
+ while propcx.first_iteration == true || !dirty_list.is_empty() {
+ propcx.walk_cfg(&mut temp, &mut dirty_list);
+ propcx.first_iteration = false;
}
}
@@ -235,9 +239,21 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: BitDenotation
{
- fn walk_cfg(&mut self, in_out: &mut IdxSet<BD::Idx>) {
+ fn walk_cfg(&mut self, in_out: &mut IdxSet<BD::Idx>,
+ dirty_list: &mut IndexVec<BasicBlock, BasicBlockData<'tcx>>) {
let mir = self.builder.mir;
- for (bb_idx, bb_data) in mir.basic_blocks().iter().enumerate() {
+ let dirty_list_clone = &dirty_list.clone();
+ let basic_blocks : &IndexVec<BasicBlock, BasicBlockData<>>;
+ if !self.first_iteration {
+ basic_blocks = dirty_list_clone;
+ } else {
+ basic_blocks = mir.basic_blocks();
+ }
+
+ let mut new_dirty_list: IndexVec<BasicBlock, BasicBlockData<'tcx>> = IndexVec::new();
+ for (bb_idx, bb_data) in basic_blocks.iter().enumerate() {
+ info!("bb_idx is {:?}", bb_idx);
+ self.changed = false;
let builder = &mut self.builder;
{
let sets = builder.flow_state.sets.for_block(bb_idx);
@@ -248,7 +264,14 @@ impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: Bi
}
builder.propagate_bits_into_graph_successors_of(
in_out, &mut self.changed, (mir::BasicBlock::new(bb_idx), bb_data));
+
+
+ if self.changed {
+ new_dirty_list.push(bb_data.clone());
+ }
+
}
+ *dirty_list = new_dirty_list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment