On 14/12/15 09:47, Richard Biener wrote:
On Fri, Dec 11, 2015 at 6:05 PM, Tom de Vries <tom_devr...@mentor.com> wrote:
Hi,
atm, we dump ssa-name info for lhs-es of statements. That leaves out the ssa
names with default defs.
This proof-of-concept patch prints the ssa-name info for default defs, in
the following format:
...
__attribute__((noclone, noinline))
bar (intD.6 * cD.1755, intD.6 * dD.1756)
# PT = nonlocal
# DEFAULT_DEF c_2(D)
# PT = { D.1762 } (nonlocal)
# ALIGN = 4, MISALIGN = 0
# DEFAULT_DEF d_4(D)
{
;; basic block 2, loop depth 0, count 0, freq 10000, maybe hot
;; prev block 0, next block 1, flags: (NEW, REACHABLE)
;; pred: ENTRY [100.0%] (FALLTHRU,EXECUTABLE)
# .MEM_3 = VDEF <.MEM_1(D)>
*c_2(D) = 1;
# .MEM_5 = VDEF <.MEM_3>
*d_4(D) = 2;
# VUSE <.MEM_5>
return;
;; succ: EXIT [100.0%] (EXECUTABLE)
}
...
Good idea? Any further comments, f.i. on formatting?
I've had a similar patch in my dev tree for quite some while but never
pushed it because
of "formatting"...
That said,
+ if (gimple_in_ssa_p (fun))
Please add flags & TDF_ALIAS here to avoid issues with dump-file scanning.
Done.
+ {
+ arg = DECL_ARGUMENTS (fndecl);
+ while (arg)
+ {
+ tree def = ssa_default_def (fun, arg);
+ if (flags & TDF_ALIAS)
+ dump_ssaname_info_to_file (file, def);
+ fprintf (file, "# DEFAULT_DEF ");
+ print_generic_expr (file, def, dump_flags);
Rather than
# DEFAULT_DEF d_4(D)
I'd print
d_4(D) = GIMPLE_NOP;
(or how gimple-nop is printed - that is, just print the def-stmt).
My local patch simply adjusted the dumping of function
locals, thus I amended the existing
if (gimple_in_ssa_p (cfun))
for (ix = 1; ix < num_ssa_names; ++ix)
{
tree name = ssa_name (ix);
if (name && !SSA_NAME_VAR (name))
{
loop. Of course that intermixed default-defs with other anonymous
SSA vars which might be a little confusing.
But prepending the list of locals with
type d_4(D) = NOP();
together with SSA info might be the best.
Done.
In addition, I added printing of SSA_NAME_VAR(def) as argument to NOP.
I think that's even more clear: the var is printed in the same format as
in the arguments list, so it makes it easier to relate the two:
...
__attribute__((noclone, noinline))
bar (intD.6 * cD.1755, intD.6 * dD.1756)
{
# PT = nonlocal
intD.6 * c_2(D) = NOP(cD.1755);
# PT = { D.1762 } (nonlocal)
# ALIGN = 4, MISALIGN = 0
intD.6 * d_4(D) = NOP(dD.1756);
intD.6 _6;
intD.6 _7;
...
Note there is also the
static chain and the result decl (if DECL_BY_REFERENCE) to print.
Done, though I haven't tested that bit yet.
Thanks,
- Tom
Dump default defs for arguments, static chain and decl-by-reference
2015-12-14 Tom de Vries <t...@codesourcery.com>
* gimple-pretty-print.c (dump_ssaname_info_to_file): New function.
* gimple-pretty-print.h (dump_ssaname_info_to_file): Declare.
* tree-cfg.c (dump_default_def): New function.
(dump_function_to_file): Dump default defs for arguments, static chain,
and decl-by-reference.
---
gcc/gimple-pretty-print.c | 11 +++++++++++
gcc/gimple-pretty-print.h | 1 +
gcc/tree-cfg.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+)
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index f1abf5c..01e9b6b 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1887,6 +1887,17 @@ dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
}
}
+/* As dump_ssaname_info, but dump to FILE. */
+
+void
+dump_ssaname_info_to_file (FILE *file, tree node, int spc)
+{
+ pretty_printer buffer;
+ pp_needs_newline (&buffer) = true;
+ buffer.buffer->stream = file;
+ dump_ssaname_info (&buffer, node, spc);
+ pp_flush (&buffer);
+}
/* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
The caller is responsible for calling pp_flush on BUFFER to finalize
diff --git a/gcc/gimple-pretty-print.h b/gcc/gimple-pretty-print.h
index 1ab24b8..740965f 100644
--- a/gcc/gimple-pretty-print.h
+++ b/gcc/gimple-pretty-print.h
@@ -34,5 +34,6 @@ extern void print_gimple_expr (FILE *, gimple *, int, int);
extern void pp_gimple_stmt_1 (pretty_printer *, gimple *, int, int);
extern void gimple_dump_bb (FILE *, basic_block, int, int);
extern void gimple_dump_bb_for_graph (pretty_printer *, basic_block);
+extern void dump_ssaname_info_to_file (FILE *, tree, int);
#endif /* ! GCC_GIMPLE_PRETTY_PRINT_H */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 0c624aa..163fef6 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7312,6 +7312,23 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
return bb;
}
+/* Dump default default def DEF to file FILE using FLAGS and indentation
+ SPC. */
+
+static void
+dump_default_def (FILE *file, tree def, int spc, int flags)
+{
+ for (int i = 0; i < spc; ++i)
+ fprintf (file, " ");
+ dump_ssaname_info_to_file (file, def, spc);
+
+ print_generic_expr (file, TREE_TYPE (def), flags);
+ fprintf (file, " ");
+ print_generic_expr (file, def, flags);
+ fprintf (file, " = NOP(");
+ print_generic_expr (file, SSA_NAME_VAR (def), flags);
+ fprintf (file, ");\n");
+}
/* Dump FUNCTION_DECL FN to file FILE using FLAGS (see TDF_* in dumpfile.h)
*/
@@ -7391,6 +7408,35 @@ dump_function_to_file (tree fndecl, FILE *file, int flags)
ignore_topmost_bind = true;
fprintf (file, "{\n");
+ if (gimple_in_ssa_p (fun)
+ && (flags & TDF_ALIAS))
+ {
+ for (arg = DECL_ARGUMENTS (fndecl); arg != NULL;
+ arg = DECL_CHAIN (arg))
+ {
+ tree def = ssa_default_def (fun, arg);
+ if (def)
+ dump_default_def (file, def, 2, flags);
+ }
+
+ tree res = DECL_RESULT (fun->decl);
+ if (res != NULL_TREE
+ && DECL_BY_REFERENCE (res))
+ {
+ tree def = ssa_default_def (fun, res);
+ if (def)
+ dump_default_def (file, def, 2, flags);
+ }
+
+ tree static_chain = fun->static_chain_decl;
+ if (static_chain != NULL_TREE)
+ {
+ tree def = ssa_default_def (fun, static_chain);
+ if (def)
+ dump_default_def (file, def, 2, flags);
+ }
+ }
+
if (!vec_safe_is_empty (fun->local_decls))
FOR_EACH_LOCAL_DECL (fun, ix, var)
{