Only create graphviz nodes for reachable MIR bb's
This commit is contained in:
parent
b9535c0b7d
commit
47ae42ee10
1 changed files with 10 additions and 2 deletions
|
@ -6,6 +6,7 @@ use std::{io, ops, str};
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rustc_graphviz as dot;
|
use rustc_graphviz as dot;
|
||||||
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_middle::mir::graphviz_safe_def_name;
|
use rustc_middle::mir::graphviz_safe_def_name;
|
||||||
use rustc_middle::mir::{self, BasicBlock, Body, Location};
|
use rustc_middle::mir::{self, BasicBlock, Body, Location};
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ where
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
results: &'a Results<'tcx, A>,
|
results: &'a Results<'tcx, A>,
|
||||||
style: OutputStyle,
|
style: OutputStyle,
|
||||||
|
reachable: BitSet<BasicBlock>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx, A> Formatter<'a, 'tcx, A>
|
impl<'a, 'tcx, A> Formatter<'a, 'tcx, A>
|
||||||
|
@ -41,7 +43,8 @@ where
|
||||||
A: Analysis<'tcx>,
|
A: Analysis<'tcx>,
|
||||||
{
|
{
|
||||||
pub fn new(body: &'a Body<'tcx>, results: &'a Results<'tcx, A>, style: OutputStyle) -> Self {
|
pub fn new(body: &'a Body<'tcx>, results: &'a Results<'tcx, A>, style: OutputStyle) -> Self {
|
||||||
Formatter { body, results, style }
|
let reachable = mir::traversal::reachable_as_bitset(body);
|
||||||
|
Formatter { body, results, style, reachable }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +111,12 @@ where
|
||||||
type Edge = CfgEdge;
|
type Edge = CfgEdge;
|
||||||
|
|
||||||
fn nodes(&self) -> dot::Nodes<'_, Self::Node> {
|
fn nodes(&self) -> dot::Nodes<'_, Self::Node> {
|
||||||
self.body.basic_blocks.indices().collect::<Vec<_>>().into()
|
self.body
|
||||||
|
.basic_blocks
|
||||||
|
.indices()
|
||||||
|
.filter(|&idx| self.reachable.contains(idx))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edges(&self) -> dot::Edges<'_, Self::Edge> {
|
fn edges(&self) -> dot::Edges<'_, Self::Edge> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue