Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl optimization::Interprocedural for Inlining {
- fn optimize<'src, 'ast>(program: &FirmProgram<'src, 'ast>) -> Outcome {
- let g = CallGraph::new(program).construct();
- let mut g = condensation(g, false);
- g.reverse();
- g.retain_edges(|g, e| {
- let (n1, n2) = g.edge_endpoints(e).unwrap();
- n1 != n2
- });
- let topo_sort = toposort(&g, None).unwrap();
- let mut map = HashMap::new();
- for (idx, node_id) in topo_sort.iter().enumerate() {
- map.insert(RefEq(g.node_weight(*node_id).unwrap()), idx);
- }
- breakpoint!("inline graph", g, &|n: &Vec<FirmMethodP<'src, 'ast>>| {
- Label::from_text(format!(
- "{:?} {}",
- n.iter()
- .map(|n| n.borrow().def.name.as_str().to_owned())
- .collect::<Vec<_>>(),
- map.get(&RefEq(n)).unwrap()
- ))
- });
- for node in topo_sort {
- if g.node_weight(node).unwrap().len() != 1 {
- continue;
- }
- for edge in g.edges_directed(node, petgraph::Direction::Outgoing) {
- Inline::inline(*edge.weight());
- }
- }
- Outcome::Unchanged
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement