ssa_reloop/lib.rs
1use arena_traits::Arena;
2use arena_traits::IndexIter;
3use relooper::{RelooperLabel, ShapedBlock};
4use ssa_impls::dom::dominates;
5use cfg_traits::Func;
6// use ssa_traits::Block;
7use cfg_traits::Block;
8// use ssa_traits::Term;
9use cfg_traits::Term;
10use cfg_traits::Target;
11// use waffle::{cfg::CFGInfo, Block, FunctionBody};
12
13pub fn go<F: Func<Block: RelooperLabel>>(b: &F, k: F::Block) -> Box<ShapedBlock<F::Block>> {
14 let cfg = ssa_impls::dom::domtree(b);
15 // let reloop = std::panic::catch_unwind(|| {
16 relooper::reloop(
17 b.blocks().iter()
18 .filter(|k| dominates::<F>(&cfg,Some(b.entry()), Some(*k)))
19 .map(|k| {
20 let l = &b.blocks()[k];
21 (
22 k,
23 l.term().targets()
24 .map(|a|a.block())
25 .chain(b.blocks().iter().filter(|x| dominates::<F>(&cfg,Some(*x), Some(k))))
26 .collect(),
27 )
28 })
29 // .chain(once((Block::invalid(), vec![b.entry])))
30 .collect(),
31 // Block::invalid(),
32 k,
33 )
34 // });
35 // let reloop = match reloop {
36 // Ok(a) => a,
37 // Err(e) => {
38 // panic!(
39 // "reloop failure ({}) in {}",
40 // e.downcast_ref::<&str>()
41 // .map(|a| *a)
42 // .unwrap_or("unknown panic"),
43 // b.display("", None)
44 // );
45 // }
46 // };
47 // reloop
48}