* [jit] New API entrypoint: gcc_jit_function_dump_to_dot
@ 2014-01-01 0:00 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2014-01-01 0:00 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
Committed to branch dmalcolm/jit:
gcc/jit/
* libgccjit.h (gcc_jit_function_dump_to_dot): New.
* libgccjit.map (gcc_jit_function_dump_to_dot): New.
* libgccjit++.h (gccjit::function::dump_to_dot): New.
* libgccjit.c (gcc_jit_function_dump_to_dot): New.
* internal-api.h (gcc::jit::recording::function::dump_to_dot): New.
(gcc::jit::recording::block::block): Add m_index member.
(gcc::jit::recording::block::dump_to_dot): New.
(gcc::jit::recording::block::dump_edges_to_dot): New.
* internal-api.c (gcc::jit::recording::function::new_block): Give
each block an index.
(gcc::jit::recording::function::dump_to_dot): New.
(gcc::jit::recording::block::dump_to_dot): New.
(gcc::jit::recording::block::dump_edges_to_dot): New.
---
gcc/jit/ChangeLog.jit | 16 ++++++++++
gcc/jit/internal-api.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-
gcc/jit/internal-api.h | 9 +++++-
gcc/jit/libgccjit++.h | 9 ++++++
gcc/jit/libgccjit.c | 11 +++++++
gcc/jit/libgccjit.h | 5 ++++
gcc/jit/libgccjit.map | 1 +
7 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index b9172a1..3e2799f 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,19 @@
+2014-03-05 David Malcolm <dmalcolm@redhat.com>
+
+ * libgccjit.h (gcc_jit_function_dump_to_dot): New.
+ * libgccjit.map (gcc_jit_function_dump_to_dot): New.
+ * libgccjit++.h (gccjit::function::dump_to_dot): New.
+ * libgccjit.c (gcc_jit_function_dump_to_dot): New.
+ * internal-api.h (gcc::jit::recording::function::dump_to_dot): New.
+ (gcc::jit::recording::block::block): Add m_index member.
+ (gcc::jit::recording::block::dump_to_dot): New.
+ (gcc::jit::recording::block::dump_edges_to_dot): New.
+ * internal-api.c (gcc::jit::recording::function::new_block): Give
+ each block an index.
+ (gcc::jit::recording::function::dump_to_dot): New.
+ (gcc::jit::recording::block::dump_to_dot): New.
+ (gcc::jit::recording::block::dump_edges_to_dot): New.
+
2014-03-04 David Malcolm <dmalcolm@redhat.com>
* internal-api.c (gcc::jit::recording::memento_of_get_pointer::
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index 835aa7f..62301b2 100644
--- a/gcc/jit/internal-api.c
+++ b/gcc/jit/internal-api.c
@@ -1294,7 +1294,7 @@ recording::function::new_block (const char *name)
gcc_assert (m_kind != GCC_JIT_FUNCTION_IMPORTED);
recording::block *result =
- new recording::block (this, new_string (name));
+ new recording::block (this, m_blocks.length (), new_string (name));
m_ctxt->record (result);
m_blocks.safe_push (result);
return result;
@@ -1430,6 +1430,42 @@ recording::function::validate ()
}
}
+void
+recording::function::dump_to_dot (const char *path)
+{
+ FILE *fp = fopen (path, "w");
+ if (!fp)
+ return;
+
+ pretty_printer the_pp;
+ the_pp.buffer->stream = fp;
+
+ pretty_printer *pp = &the_pp;
+
+ pp_printf (pp,
+ "digraph %s {\n", get_debug_string ());
+
+ /* Blocks: */
+ {
+ int i;
+ block *b;
+ FOR_EACH_VEC_ELT (m_blocks, i, b)
+ b->dump_to_dot (pp);
+ }
+
+ /* Edges: */
+ {
+ int i;
+ block *b;
+ FOR_EACH_VEC_ELT (m_blocks, i, b)
+ b->dump_edges_to_dot (pp);
+ }
+
+ pp_printf (pp, "}\n");
+ pp_flush (pp);
+ fclose (fp);
+}
+
recording::string *
recording::function::make_debug_string ()
{
@@ -1573,6 +1609,47 @@ recording::block::make_debug_string ()
(void *)this);
}
+void
+recording::block::dump_to_dot (pretty_printer *pp)
+{
+ pp_printf (pp,
+ ("\tblock_%d "
+ "[shape=record,style=filled,fillcolor=white,label=\"{"),
+ m_index);
+ pp_write_text_to_stream (pp);
+ if (m_name)
+ {
+ pp_string (pp, m_name->c_str ());
+ pp_string (pp, ":");
+ pp_newline (pp);
+ pp_write_text_as_dot_label_to_stream (pp, true /*for_record*/);
+ }
+
+ int i;
+ statement *s;
+ FOR_EACH_VEC_ELT (m_statements, i, s)
+ {
+ pp_string (pp, s->get_debug_string ());
+ pp_newline (pp);
+ pp_write_text_as_dot_label_to_stream (pp, true /*for_record*/);
+ }
+
+ pp_printf (pp,
+ "}\"];\n\n");
+ pp_flush (pp);
+}
+
+void
+recording::block::dump_edges_to_dot (pretty_printer *pp)
+{
+ block *next[2];
+ int num_succs = get_successor_blocks (&next[0], &next[1]);
+ for (int i = 0; i < num_succs; i++)
+ pp_printf (pp,
+ "\tblock_%d:s -> block_%d:n;\n",
+ m_index, next[i]->m_index);
+}
+
/* gcc::jit::recording::global:: */
void
recording::global::replay_into (replayer *r)
diff --git a/gcc/jit/internal-api.h b/gcc/jit/internal-api.h
index 5c11085..23352fc 100644
--- a/gcc/jit/internal-api.h
+++ b/gcc/jit/internal-api.h
@@ -889,6 +889,8 @@ public:
void validate ();
+ void dump_to_dot (const char *path);
+
private:
string * make_debug_string ();
@@ -907,9 +909,10 @@ private:
class block : public memento
{
public:
- block (function *func, string *name)
+ block (function *func, int index, string *name)
: memento (func->m_ctxt),
m_func (func),
+ m_index (index),
m_name (name),
m_statements (),
m_has_been_terminated (false),
@@ -974,8 +977,12 @@ private:
void replay_into (replayer *r);
+ void dump_to_dot (pretty_printer *pp);
+ void dump_edges_to_dot (pretty_printer *pp);
+
private:
function *m_func;
+ int m_index;
string *m_name;
vec<statement *> m_statements;
bool m_has_been_terminated;
diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
index b349ad9..da7471b 100644
--- a/gcc/jit/libgccjit++.h
+++ b/gcc/jit/libgccjit++.h
@@ -293,6 +293,8 @@ namespace gccjit
gcc_jit_function *get_inner_function () const;
+ void dump_to_dot (const std::string &path);
+
param get_param (int index);
block new_block ();
@@ -1113,6 +1115,13 @@ function::get_inner_function () const
return reinterpret_cast<gcc_jit_function *> (get_inner_object ());
}
+inline void
+function::dump_to_dot (const std::string &path)
+{
+ gcc_jit_function_dump_to_dot (get_inner_function (),
+ path.c_str ());
+}
+
inline param
function::get_param (int index)
{
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 75fdfeb..817d1b5 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -578,6 +578,17 @@ gcc_jit_function_get_param (gcc_jit_function *func, int index)
return static_cast <gcc_jit_param *> (func->get_param (index));
}
+void
+gcc_jit_function_dump_to_dot (gcc_jit_function *func,
+ const char *path)
+{
+ RETURN_IF_FAIL (func, NULL, "NULL function");
+ gcc::jit::recording::context *ctxt = func->m_ctxt;
+ RETURN_IF_FAIL (path, ctxt, "NULL path");
+
+ func->dump_to_dot (path);
+}
+
gcc_jit_block*
gcc_jit_function_new_block (gcc_jit_function *func,
const char *name)
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 83d4f85..e8f35b9 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -494,6 +494,11 @@ gcc_jit_function_as_object (gcc_jit_function *func);
extern gcc_jit_param *
gcc_jit_function_get_param (gcc_jit_function *func, int index);
+/* Emit the function in graphviz format. */
+extern void
+gcc_jit_function_dump_to_dot (gcc_jit_function *func,
+ const char *path);
+
/* Create a block.
The name can be NULL, or you can give it a meaningful name, which
diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
index ed51a62..0d9968c 100644
--- a/gcc/jit/libgccjit.map
+++ b/gcc/jit/libgccjit.map
@@ -47,6 +47,7 @@
gcc_jit_context_zero;
gcc_jit_field_as_object;
gcc_jit_function_as_object;
+ gcc_jit_function_dump_to_dot;
gcc_jit_function_get_param;
gcc_jit_function_new_block;
gcc_jit_function_new_local;
--
1.7.11.7
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-03-05 22:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01 0:00 [jit] New API entrypoint: gcc_jit_function_dump_to_dot David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).