| 161 | |
| 162 | impl core::fmt::Debug for DominatorTree { |
| 163 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 164 | if !self.is_valid() { |
| 165 | return f.write_str("DominatorTree { <invalid> }"); |
| 166 | } |
| 167 | |
| 168 | let mut s = f.debug_tuple("DominatorTree"); |
| 169 | |
| 170 | if let Some((mut root, _)) = self.nodes.iter().find(|n| n.1.pre_number != NOT_VISITED) { |
| 171 | loop { |
| 172 | if let Some(b) = self.idom(root) |
| 173 | && b != root |
| 174 | { |
| 175 | root = b; |
| 176 | } else { |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | fn fmt_block(domtree: &DominatorTree, block: Block) -> impl core::fmt::Debug { |
| 182 | core::fmt::from_fn(move |f| { |
| 183 | let children = domtree |
| 184 | .children(block) |
| 185 | .map(|c| fmt_block(domtree, c)) |
| 186 | .collect::<Vec<_>>(); |
| 187 | let mut s = f.debug_tuple(&format!("{block}")); |
| 188 | if !children.is_empty() { |
| 189 | s.field(&children); |
| 190 | } |
| 191 | s.finish() |
| 192 | }) |
| 193 | } |
| 194 | |
| 195 | s.field(&fmt_block(self, root)); |
| 196 | } |
| 197 | |
| 198 | s.finish() |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /// Methods for querying the dominator tree. |