rapx/analysis/core/alias_analysis/default/
block.rs

1use super::assign::*;
2use crate::analysis::graphs::scc::SccInfo;
3use rustc_data_structures::fx::FxHashSet;
4use rustc_middle::mir::Terminator;
5
6/// Each block is a strongly-connected component on the control-flow graph.
7#[derive(Debug, Clone)]
8pub struct Block<'tcx> {
9    pub index: usize,
10    pub is_cleanup: bool,
11    pub next: FxHashSet<usize>,
12    pub assignments: Vec<Assignment<'tcx>>,
13    pub const_value: Vec<ConstValue>,
14    // Used in scc handling: to clear the assignments of the enter node.
15    pub assigned_locals: FxHashSet<usize>,
16    pub terminator: Term<'tcx>,
17    /// All nodes belongs to a SCC.
18    /// This field could be a single node SCC.
19    /// The loops in the CFG are natural loops, so each SCC has only one enter.
20    pub scc: SccInfo,
21}
22
23#[derive(Debug, Clone)]
24pub enum Term<'tcx> {
25    Call(Terminator<'tcx>),
26    Drop(Terminator<'tcx>),
27    Switch(Terminator<'tcx>),
28    None,
29}
30
31#[derive(Debug, Clone)]
32pub struct ConstValue {
33    pub local: usize,
34    pub value: usize,
35}
36
37impl ConstValue {
38    pub fn new(local: usize, value: usize) -> Self {
39        ConstValue { local, value }
40    }
41}
42
43impl<'tcx> Block<'tcx> {
44    pub fn new(index: usize, is_cleanup: bool) -> Block<'tcx> {
45        Block {
46            index,
47            is_cleanup,
48            next: FxHashSet::<usize>::default(),
49            assignments: Vec::<Assignment<'tcx>>::new(),
50            const_value: Vec::<ConstValue>::new(),
51            assigned_locals: FxHashSet::<usize>::default(),
52            terminator: Term::None,
53            scc: SccInfo::new(index),
54        }
55    }
56
57    pub fn add_next(&mut self, index: usize) {
58        self.next.insert(index);
59    }
60}