1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#![allow(missing_docs)]
use cfg::ControlFlowGraph;
use petgraph::graph::NodeIndex;
#[derive(Debug, Default)]
pub struct SimpleLoop<'lsg> {
pub basic_blocks: Vec<NodeIndex>,
pub children: Vec<&'lsg SimpleLoop<'lsg>>,
pub counter: usize,
pub header: Option<NodeIndex>,
pub is_root: bool,
pub is_reducible: bool,
pub nesting_level: usize,
pub depth_level: usize,
}
impl<'lsg> SimpleLoop<'lsg> {
pub fn new(counter: usize) -> Self {
SimpleLoop {
counter: counter,
..Default::default()
}
}
}
#[allow(dead_code)]
enum BasicBlockType {
Top,
NonHeader,
Reducible,
Single,
Irreducible,
Dead,
}
pub struct LoopStructureGraph<'lsg> {
pub loop_counter: usize,
pub loops: Vec<SimpleLoop<'lsg>>,
pub root: SimpleLoop<'lsg>,
}
impl<'lsg> Default for LoopStructureGraph<'lsg> {
fn default() -> Self {
LoopStructureGraph {
loop_counter: 1,
loops: vec![],
root: SimpleLoop::new(0),
}
}
}
pub fn find_loops<'havlak>(
cfg: &'havlak ControlFlowGraph,
_lsg: &'havlak mut LoopStructureGraph<'havlak>,
) -> usize {
if cfg.entry_block.is_none() {
return 0;
}
unimplemented!();
}