diff options
author | Alex Coplan <alex.coplan@arm.com> | 2024-07-05 11:57:56 +0100 |
---|---|---|
committer | Alex Coplan <alex.coplan@arm.com> | 2024-07-05 11:57:56 +0100 |
commit | ae07f62a70ee2d0fdd7d8786122ae6360cfd4ca9 (patch) | |
tree | a55ed212e3fdd25ce560305b6a2f02594ba5db33 /gcc | |
parent | 319d3956b16b1270f27e9cbf749e881c4ff7dfb4 (diff) | |
download | gcc-ae07f62a70ee2d0fdd7d8786122ae6360cfd4ca9.zip gcc-ae07f62a70ee2d0fdd7d8786122ae6360cfd4ca9.tar.gz gcc-ae07f62a70ee2d0fdd7d8786122ae6360cfd4ca9.tar.bz2 |
middle-end: Add debug functions to dump dominator tree in dot format
This adds debug functions to dump the dominator tree in dot format.
There are two overloads: one which takes a FILE * and another which
takes a const char *fname and wraps the first with fopen/fclose for
convenience.
gcc/ChangeLog:
* dominance.cc (dot_dominance_tree): New.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/dominance.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/dominance.cc b/gcc/dominance.cc index 0357210..c14d997 100644 --- a/gcc/dominance.cc +++ b/gcc/dominance.cc @@ -1658,6 +1658,36 @@ debug_dominance_info (enum cdi_direction dir) fprintf (stderr, "%i %i\n", bb->index, bb2->index); } +/* Dump the dominance tree in direction DIR to the file F in dot form. + This allows easily visualizing the tree using graphviz. */ + +DEBUG_FUNCTION void +dot_dominance_tree (FILE *f, enum cdi_direction dir) +{ + fprintf (f, "digraph {\n"); + basic_block bb, idom; + FOR_EACH_BB_FN (bb, cfun) + if ((idom = get_immediate_dominator (dir, bb))) + fprintf (f, "%i -> %i;\n", idom->index, bb->index); + fprintf (f, "}\n"); +} + +/* Convenience wrapper around the above that dumps the dominance tree in + direction DIR to the file at path FNAME in dot form. */ + +DEBUG_FUNCTION void +dot_dominance_tree (const char *fname, enum cdi_direction dir) +{ + FILE *f = fopen (fname, "w"); + if (f) + { + dot_dominance_tree (f, dir); + fclose (f); + } + else + fprintf (stderr, "failed to open %s: %s\n", fname, xstrerror (errno)); +} + /* Prints to stderr representation of the dominance tree (for direction DIR) rooted in ROOT, indented by INDENT tabulators. If INDENT_FIRST is false, the first line of the output is not indented. */ |