Order functions using a post-order traversal, i.e. callees before callers. FIXME(eddyb) replace this with `rustc_data_structures::graph::iterate` (or similar).
(&self)
| 61 | // FIXME(eddyb) replace this with `rustc_data_structures::graph::iterate` |
| 62 | // (or similar). |
| 63 | pub fn post_order(&self) -> Vec<FuncIdx> { |
| 64 | let num_funcs = self.callees.len(); |
| 65 | |
| 66 | // FIXME(eddyb) use a proper bitset. |
| 67 | let mut visited = vec![false; num_funcs]; |
| 68 | let mut post_order = Vec::with_capacity(num_funcs); |
| 69 | |
| 70 | // Visit the call graph with entry points as roots. |
| 71 | for &entry in &self.entry_points { |
| 72 | self.post_order_step(entry, &mut visited, &mut post_order); |
| 73 | } |
| 74 | |
| 75 | // Also visit any functions that were not reached from entry points |
| 76 | // (they might be dead but they should be processed nonetheless). |
| 77 | for func in 0..num_funcs { |
| 78 | if !visited[func] { |
| 79 | self.post_order_step(func, &mut visited, &mut post_order); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | post_order |
| 84 | } |
| 85 | |
| 86 | fn post_order_step(&self, func: FuncIdx, visited: &mut [bool], post_order: &mut Vec<FuncIdx>) { |
| 87 | if visited[func] { |