Skip to content

Commit e123117

Browse files
committed
Refactoring: Allow BlockSets.on_entry to denote locally accumulated intrablock state.
(Still musing about whether it could make sense to revise the design here to make these constraints on usage explicit.)
1 parent d4add5d commit e123117

File tree

1 file changed

+30
-0
lines changed
  • src/librustc_mir/dataflow

1 file changed

+30
-0
lines changed

src/librustc_mir/dataflow/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
195195
for (bb, data) in self.mir.basic_blocks().iter_enumerated() {
196196
let &mir::BasicBlockData { ref statements, ref terminator, is_cleanup: _ } = data;
197197

198+
let mut interim_state;
198199
let sets = &mut self.flow_state.sets.for_block(bb.index());
200+
if BD::accumulates_intrablock_state() {
201+
interim_state = sets.on_entry.to_owned();
202+
sets.on_entry = &mut interim_state;
203+
}
199204
for j_stmt in 0..statements.len() {
200205
let location = Location { block: bb, statement_index: j_stmt };
201206
self.flow_state.operator.statement_effect(sets, location);
@@ -560,6 +565,31 @@ pub trait BitDenotation: BitwiseOperator {
560565
/// Specifies what index type is used to access the bitvector.
561566
type Idx: Idx;
562567

568+
/// Some analyses want to accumulate knowledge within a block when
569+
/// analyzing its statements for building the gen/kill sets. Override
570+
/// this method to return true in such cases.
571+
///
572+
/// When this returns true, the statement-effect (re)construction
573+
/// will clone the `on_entry` state and pass along a reference via
574+
/// `sets.on_entry` to that local clone into `statement_effect` and
575+
/// `terminator_effect`).
576+
///
577+
/// When its false, no local clone is constucted; instead a
578+
/// reference directly into `on_entry` is passed along via
579+
/// `sets.on_entry` instead, which represents the flow state at
580+
/// the block's start, not necessarily the state immediately prior
581+
/// to the statement/terminator under analysis.
582+
///
583+
/// In either case, the passed reference is mutable; but this is a
584+
/// wart from using the `BlockSets` type in the API; the intention
585+
/// is that the `statement_effect` and `terminator_effect` methods
586+
/// mutate only the gen/kill sets.
587+
///
588+
/// FIXME: We should consider enforcing the intention described in
589+
/// the previous paragraph by passing the three sets in separate
590+
/// parameters to encode their distinct mutabilities.
591+
fn accumulates_intrablock_state() -> bool { false }
592+
563593
/// A name describing the dataflow analysis that this
564594
/// BitDenotation is supporting. The name should be something
565595
/// suitable for plugging in as part of a filename e.g. avoid

0 commit comments

Comments
 (0)