Skip to content

Commit

Permalink
Use builder method to set dead_unwinds
Browse files Browse the repository at this point in the history
`dead_unwinds` is an empty bitset in most places. This saves us from
having to construct that empty bitset for every dataflow analysis.
  • Loading branch information
ecstatic-morse committed Nov 14, 2019
1 parent abb068e commit 75775ba
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
9 changes: 4 additions & 5 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ fn do_mir_borrowck<'a, 'tcx>(
param_env,
};

let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe);
let mut flow_inits =
dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, &dead_unwinds, flow_inits)
.iterate_to_fixpoint()
.into_cursor(body);
let mut flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, flow_inits)
.iterate_to_fixpoint()
.into_cursor(body);

let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure();
let borrow_set = Rc::new(BorrowSet::build(
Expand Down Expand Up @@ -201,6 +199,7 @@ fn do_mir_borrowck<'a, 'tcx>(

let regioncx = Rc::new(regioncx);

let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
let flow_borrows = FlowAtLocation::new(do_dataflow(
tcx,
body,
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_mir/dataflow/generic/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
dead_unwinds: &'a BitSet<BasicBlock>,
dead_unwinds: Option<&'a BitSet<BasicBlock>>,
entry_sets: IndexVec<BasicBlock, BitSet<A::Idx>>,
analysis: A,

Expand All @@ -42,7 +42,6 @@ where
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
dead_unwinds: &'a BitSet<BasicBlock>,
analysis: A,
) -> Self {
let bits_per_block = analysis.bits_per_block(body);
Expand Down Expand Up @@ -70,7 +69,7 @@ where
}
}

Self::new(tcx, body, def_id, dead_unwinds, analysis, Some(trans_for_block))
Self::new(tcx, body, def_id, analysis, Some(trans_for_block))
}
}

Expand All @@ -87,17 +86,15 @@ where
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
dead_unwinds: &'a BitSet<BasicBlock>,
analysis: A,
) -> Self {
Self::new(tcx, body, def_id, dead_unwinds, analysis, None)
Self::new(tcx, body, def_id, analysis, None)
}

fn new(
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
dead_unwinds: &'a BitSet<BasicBlock>,
analysis: A,
trans_for_block: Option<IndexVec<BasicBlock, GenKillSet<A::Idx>>>,
) -> Self {
Expand All @@ -118,12 +115,17 @@ where
tcx,
body,
def_id,
dead_unwinds,
dead_unwinds: None,
entry_sets,
trans_for_block,
}
}

pub fn dead_unwinds(mut self, dead_unwinds: &'a BitSet<BasicBlock>) -> Self {
self.dead_unwinds = Some(dead_unwinds);
self
}

pub fn iterate_to_fixpoint(mut self) -> Results<'tcx, A> {
let mut temp_state = BitSet::new_empty(self.bits_per_block);

Expand Down Expand Up @@ -229,7 +231,7 @@ where
| DropAndReplace { target, value: _, location: _, unwind: Some(unwind) }
=> {
self.propagate_bits_into_entry_set_for(in_out, target, dirty_list);
if !self.dead_unwinds.contains(bb) {
if self.dead_unwinds.map_or(true, |bbs| !bbs.contains(bb)) {
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);
}
}
Expand All @@ -242,7 +244,7 @@ where

Call { cleanup, ref destination, ref func, ref args, .. } => {
if let Some(unwind) = cleanup {
if !self.dead_unwinds.contains(bb) {
if self.dead_unwinds.map_or(true, |bbs| !bbs.contains(bb)) {
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);
}
}
Expand All @@ -263,7 +265,7 @@ where
FalseUnwind { real_target, unwind } => {
self.propagate_bits_into_entry_set_for(in_out, real_target, dirty_list);
if let Some(unwind) = unwind {
if !self.dead_unwinds.contains(bb) {
if self.dead_unwinds.map_or(true, |bbs| !bbs.contains(bb)) {
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ impl<Q: Qualif> QualifCursor<'a, 'mir, 'tcx, Q> {
pub fn new(
q: Q,
item: &'a Item<'mir, 'tcx>,
dead_unwinds: &BitSet<BasicBlock>,
) -> Self {
let analysis = FlowSensitiveAnalysis::new(q, item);
let results =
dataflow::Engine::new_generic(item.tcx, item.body, item.def_id, dead_unwinds, analysis)
dataflow::Engine::new_generic(item.tcx, item.body, item.def_id, analysis)
.iterate_to_fixpoint();
let cursor = dataflow::ResultsCursor::new(item.body, results);

Expand Down Expand Up @@ -133,20 +132,17 @@ impl Validator<'a, 'mir, 'tcx> {
pub fn new(
item: &'a Item<'mir, 'tcx>,
) -> Self {
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());

let needs_drop = QualifCursor::new(
NeedsDrop,
item,
&dead_unwinds,
);

let has_mut_interior = QualifCursor::new(
HasMutInterior,
item,
&dead_unwinds,
);

let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
let indirectly_mutable = old_dataflow::do_dataflow(
item.tcx,
item.body,
Expand Down
15 changes: 8 additions & 7 deletions src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
param_env,
};
let dead_unwinds = find_dead_unwinds(tcx, body, def_id, &env);
let flow_inits = dataflow::generic::Engine::new_gen_kill(
tcx, body, def_id, &dead_unwinds,
MaybeInitializedPlaces::new(tcx, body, &env),
).iterate_to_fixpoint();
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &env);
let flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, flow_inits)
.dead_unwinds(&dead_unwinds)
.iterate_to_fixpoint();
let flow_uninits =
do_dataflow(tcx, body, def_id, &[], &dead_unwinds,
MaybeUninitializedPlaces::new(tcx, body, &env),
Expand Down Expand Up @@ -74,10 +74,11 @@ fn find_dead_unwinds<'tcx>(
// We only need to do this pass once, because unwind edges can only
// reach cleanup blocks, which can't have unwind edges themselves.
let mut dead_unwinds = BitSet::new_empty(body.basic_blocks().len());

let flow_inits = MaybeInitializedPlaces::new(tcx, body, &env);
let flow_inits =
dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, &dead_unwinds, flow_inits)
.iterate_to_fixpoint();
let flow_inits = dataflow::generic::Engine::new_gen_kill(tcx, body, def_id, flow_inits)
.iterate_to_fixpoint();

for (bb, bb_data) in body.basic_blocks().iter_enumerated() {
let location = match bb_data.terminator().kind {
TerminatorKind::Drop { ref location, unwind: Some(_), .. } |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/rustc_peek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());

let flow_inits = Engine::new_gen_kill(
tcx, body, def_id, &dead_unwinds,
tcx, body, def_id,
MaybeInitializedPlaces::new(tcx, body, &mdpe),
).iterate_to_fixpoint();
let flow_uninits =
Expand Down

0 comments on commit 75775ba

Please sign in to comment.