Move predecessors
from Body to BasicBlocks
This commit is contained in:
parent
2446b17745
commit
39d9c1cb1f
9 changed files with 10 additions and 16 deletions
|
@ -1628,7 +1628,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
location: Location,
|
location: Location,
|
||||||
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
|
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
|
||||||
if location.statement_index == 0 {
|
if location.statement_index == 0 {
|
||||||
let predecessors = body.predecessors()[location.block].to_vec();
|
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
|
||||||
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))
|
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))
|
||||||
} else {
|
} else {
|
||||||
Either::Right(std::iter::once(Location {
|
Either::Right(std::iter::once(Location {
|
||||||
|
|
|
@ -258,7 +258,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
|
|
||||||
let block = self.cx.elements.to_location(block_start).block;
|
let block = self.cx.elements.to_location(block_start).block;
|
||||||
self.stack.extend(
|
self.stack.extend(
|
||||||
self.cx.body.predecessors()[block]
|
self.cx.body.basic_blocks.predecessors()[block]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&pred_bb| self.cx.body.terminator_loc(pred_bb))
|
.map(|&pred_bb| self.cx.body.terminator_loc(pred_bb))
|
||||||
.map(|pred_loc| self.cx.elements.point_from_location(pred_loc)),
|
.map(|pred_loc| self.cx.elements.point_from_location(pred_loc)),
|
||||||
|
@ -354,7 +354,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = self.cx.body;
|
let body = self.cx.body;
|
||||||
for &pred_block in body.predecessors()[block].iter() {
|
for &pred_block in body.basic_blocks.predecessors()[block].iter() {
|
||||||
debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,);
|
debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,);
|
||||||
|
|
||||||
// Check whether the variable is (at least partially)
|
// Check whether the variable is (at least partially)
|
||||||
|
|
|
@ -41,7 +41,6 @@ use std::fmt::{self, Debug, Display, Formatter, Write};
|
||||||
use std::ops::{ControlFlow, Index, IndexMut};
|
use std::ops::{ControlFlow, Index, IndexMut};
|
||||||
use std::{iter, mem};
|
use std::{iter, mem};
|
||||||
|
|
||||||
use self::predecessors::Predecessors;
|
|
||||||
pub use self::query::*;
|
pub use self::query::*;
|
||||||
use self::switch_sources::SwitchSources;
|
use self::switch_sources::SwitchSources;
|
||||||
pub use basic_blocks::BasicBlocks;
|
pub use basic_blocks::BasicBlocks;
|
||||||
|
@ -449,11 +448,6 @@ impl<'tcx> Body<'tcx> {
|
||||||
.unwrap_or_else(|| Either::Right(block_data.terminator()))
|
.unwrap_or_else(|| Either::Right(block_data.terminator()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn predecessors(&self) -> &Predecessors {
|
|
||||||
self.basic_blocks.predecessors()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `body.switch_sources()[&(target, switch)]` returns a list of switch
|
/// `body.switch_sources()[&(target, switch)]` returns a list of switch
|
||||||
/// values that lead to a `target` block from a `switch` block.
|
/// values that lead to a `target` block from a `switch` block.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2837,7 +2831,7 @@ impl Location {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let predecessors = body.predecessors();
|
let predecessors = body.basic_blocks.predecessors();
|
||||||
|
|
||||||
// If we're in another block, then we want to check that block is a predecessor of `other`.
|
// If we're in another block, then we want to check that block is a predecessor of `other`.
|
||||||
let mut queue: Vec<BasicBlock> = predecessors[other.block].to_vec();
|
let mut queue: Vec<BasicBlock> = predecessors[other.block].to_vec();
|
||||||
|
|
|
@ -228,7 +228,7 @@ impl Direction for Backward {
|
||||||
) where
|
) where
|
||||||
A: Analysis<'tcx>,
|
A: Analysis<'tcx>,
|
||||||
{
|
{
|
||||||
for pred in body.predecessors()[bb].iter().copied() {
|
for pred in body.basic_blocks.predecessors()[bb].iter().copied() {
|
||||||
match body[pred].terminator().kind {
|
match body[pred].terminator().kind {
|
||||||
// Apply terminator-specific edge effects.
|
// Apply terminator-specific edge effects.
|
||||||
//
|
//
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards {
|
||||||
impl AddCallGuards {
|
impl AddCallGuards {
|
||||||
pub fn add_call_guards(&self, body: &mut Body<'_>) {
|
pub fn add_call_guards(&self, body: &mut Body<'_>) {
|
||||||
let mut pred_count: IndexVec<_, _> =
|
let mut pred_count: IndexVec<_, _> =
|
||||||
body.predecessors().iter().map(|ps| ps.len()).collect();
|
body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect();
|
||||||
pred_count[START_BLOCK] += 1;
|
pred_count[START_BLOCK] += 1;
|
||||||
|
|
||||||
// We need a place to store the new blocks generated
|
// We need a place to store the new blocks generated
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl CoverageGraph {
|
||||||
let mut basic_blocks = Vec::new();
|
let mut basic_blocks = Vec::new();
|
||||||
for (bb, data) in mir_cfg_without_unwind {
|
for (bb, data) in mir_cfg_without_unwind {
|
||||||
if let Some(last) = basic_blocks.last() {
|
if let Some(last) = basic_blocks.last() {
|
||||||
let predecessors = &mir_body.predecessors()[bb];
|
let predecessors = &mir_body.basic_blocks.predecessors()[bb];
|
||||||
if predecessors.len() > 1 || !predecessors.contains(last) {
|
if predecessors.len() > 1 || !predecessors.contains(last) {
|
||||||
// The `bb` has more than one _incoming_ edge, and should start its own
|
// The `bb` has more than one _incoming_ edge, and should start its own
|
||||||
// `BasicCoverageBlockData`. (Note, the `basic_blocks` vector does not yet
|
// `BasicCoverageBlockData`. (Note, the `basic_blocks` vector does not yet
|
||||||
|
|
|
@ -133,7 +133,7 @@ fn find_local_assigned_to_return_place(
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
match body.predecessors()[block].as_slice() {
|
match body.basic_blocks.predecessors()[block].as_slice() {
|
||||||
&[pred] => block = pred,
|
&[pred] => block = pred,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl<'tcx> MirPass<'tcx> for SeparateConstSwitch {
|
||||||
/// Returns the amount of blocks that were duplicated
|
/// Returns the amount of blocks that were duplicated
|
||||||
pub fn separate_const_switch(body: &mut Body<'_>) -> usize {
|
pub fn separate_const_switch(body: &mut Body<'_>) -> usize {
|
||||||
let mut new_blocks: SmallVec<[(BasicBlock, BasicBlock); 6]> = SmallVec::new();
|
let mut new_blocks: SmallVec<[(BasicBlock, BasicBlock); 6]> = SmallVec::new();
|
||||||
let predecessors = body.predecessors();
|
let predecessors = body.basic_blocks.predecessors();
|
||||||
'block_iter: for (block_id, block) in body.basic_blocks().iter_enumerated() {
|
'block_iter: for (block_id, block) in body.basic_blocks().iter_enumerated() {
|
||||||
if let TerminatorKind::SwitchInt {
|
if let TerminatorKind::SwitchInt {
|
||||||
discr: Operand::Copy(switch_place) | Operand::Move(switch_place),
|
discr: Operand::Copy(switch_place) | Operand::Move(switch_place),
|
||||||
|
|
|
@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
|
||||||
// `arg` is a reference as it is `.deref()`ed in the previous block.
|
// `arg` is a reference as it is `.deref()`ed in the previous block.
|
||||||
// Look into the predecessor block and find out the source of deref.
|
// Look into the predecessor block and find out the source of deref.
|
||||||
|
|
||||||
let ps = &mir.predecessors()[bb];
|
let ps = &mir.basic_blocks.predecessors()[bb];
|
||||||
if ps.len() != 1 {
|
if ps.len() != 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue