[v3,2/2,RFC] Add debugging for move history.
Checks
Commit Message
gcc/ChangeLog:
* diagnostic-move-history.cc (dump_move_history): New routine.
(dump_move_history_for): Likewise.
(debug_mv_h): Likewise.
* diagnostic-move-history.h (dump_move_history): New prototype.
(dump_move_history_for): Likewise.
* gimple-ssa-isolate-paths.cc (isolate_path): Add debugging message
when setting move history for statements.
* tree-ssa-sink.cc (sink_code_in_bb): Likewise.
* tree-ssa-threadupdate.cc (ssa_redirect_edges): Likewise.
(back_jt_path_registry::duplicate_thread_path): Likewise.
---
gcc/diagnostic-move-history.cc | 67 +++++++++++++++++++++++++++++++++
gcc/diagnostic-move-history.h | 2 +
gcc/gimple-ssa-isolate-paths.cc | 10 +++++
gcc/tree-ssa-sink.cc | 3 ++
gcc/tree-ssa-threadupdate.cc | 18 +++++++++
5 files changed, 100 insertions(+)
Comments
Qing Zhao <qing.zhao@oracle.com> writes:
> gcc/ChangeLog:
>
> * diagnostic-move-history.cc (dump_move_history): New routine.
> (dump_move_history_for): Likewise.
> (debug_mv_h): Likewise.
> * diagnostic-move-history.h (dump_move_history): New prototype.
> (dump_move_history_for): Likewise.
> * gimple-ssa-isolate-paths.cc (isolate_path): Add debugging message
> when setting move history for statements.
> * tree-ssa-sink.cc (sink_code_in_bb): Likewise.
> * tree-ssa-threadupdate.cc (ssa_redirect_edges): Likewise.
> (back_jt_path_registry::duplicate_thread_path): Likewise.
> ---
> gcc/diagnostic-move-history.cc | 67 +++++++++++++++++++++++++++++++++
> gcc/diagnostic-move-history.h | 2 +
> gcc/gimple-ssa-isolate-paths.cc | 10 +++++
> gcc/tree-ssa-sink.cc | 3 ++
> gcc/tree-ssa-threadupdate.cc | 18 +++++++++
> 5 files changed, 100 insertions(+)
>
> diff --git a/gcc/diagnostic-move-history.cc b/gcc/diagnostic-move-history.cc
> index b0e8308dbf6b..e4c471ab50f3 100644
> --- a/gcc/diagnostic-move-history.cc
> +++ b/gcc/diagnostic-move-history.cc
> @@ -24,6 +24,7 @@
> #include "backend.h"
> #include "tree.h"
> #include "gimple.h"
> +#include "tree-pretty-print.h"
> #include "gimple-iterator.h"
> #include "cfganal.h"
> #include "diagnostic-move-history.h"
> @@ -262,3 +263,69 @@ set_move_history_to_stmts_in_bb (basic_block bb, edge entry,
>
> return true;
> }
> +
> +/* Dump the move_history data structure MV_HISTORY. */
> +
> +void
> +dump_move_history (FILE *file, move_history_t mv_history)
> +{
> + fprintf (file, "The move history is: \n");
"is:\n"
> + if (!mv_history)
> + {
> + fprintf (file, "No move history.\n");
> + return;
> + }
> +
> + for (move_history_t cur_ch = mv_history; cur_ch;
> + cur_ch = cur_ch->prev_move)
> + {
> + expanded_location exploc_cond = expand_location (cur_ch->condition);
> +
> + if (exploc_cond.file)
> + fprintf (file, "[%s:", exploc_cond.file);
> + fprintf (file, "%d, ", exploc_cond.line);
> + fprintf (file, "%d] ", exploc_cond.column);
> +
> + fprintf (file, "%s ", cur_ch->is_true_path ? "true" : "false");
> + const char *reason = NULL;
> + switch (cur_ch->reason)
> + {
> + case COPY_BY_THREAD_JUMP:
> + reason = "copy_by_thread_jump";
> + break;
> + case COPY_BY_ISOLATE_PATH:
> + reason = "copy_by_isolate_path";
> + break;
> + case MOVE_BY_SINK:
> + reason = "move_by_sink";
> + break;
> + default:
> + reason = "UNKNOWN";
> + break;
> + }
> + fprintf (file, "%s \n", reason);
"s\n"
> + }
> +}
> +
> +/* Dump the move_history date structure attached to the gimple STMT. */
date -> data
> +void
> +dump_move_history_for (FILE *file, const gimple *stmt)
> +{
> + move_history_t mv_history = get_move_history (stmt);
> + if (!mv_history)
> + fprintf (file, "No move history.\n");
> + else
> + dump_move_history (file, mv_history);
> +}
> +
> +DEBUG_FUNCTION void
> +debug_mv_h (const move_history_t mv_history)
> +{
> + dump_move_history (stderr, mv_history);
> +}
> +
> +DEBUG_FUNCTION void
> +debug_mv_h (const gimple * stmt)
> +{
> + dump_move_history_for (stderr, stmt);
> +}
> [...]
Thanks.
Will fix them in the next version.
Qing
> On Oct 30, 2024, at 13:52, Sam James <sam@gentoo.org> wrote:
>
> Qing Zhao <qing.zhao@oracle.com> writes:
>
>> gcc/ChangeLog:
>>
>> * diagnostic-move-history.cc (dump_move_history): New routine.
>> (dump_move_history_for): Likewise.
>> (debug_mv_h): Likewise.
>> * diagnostic-move-history.h (dump_move_history): New prototype.
>> (dump_move_history_for): Likewise.
>> * gimple-ssa-isolate-paths.cc (isolate_path): Add debugging message
>> when setting move history for statements.
>> * tree-ssa-sink.cc (sink_code_in_bb): Likewise.
>> * tree-ssa-threadupdate.cc (ssa_redirect_edges): Likewise.
>> (back_jt_path_registry::duplicate_thread_path): Likewise.
>> ---
>> gcc/diagnostic-move-history.cc | 67 +++++++++++++++++++++++++++++++++
>> gcc/diagnostic-move-history.h | 2 +
>> gcc/gimple-ssa-isolate-paths.cc | 10 +++++
>> gcc/tree-ssa-sink.cc | 3 ++
>> gcc/tree-ssa-threadupdate.cc | 18 +++++++++
>> 5 files changed, 100 insertions(+)
>>
>> diff --git a/gcc/diagnostic-move-history.cc b/gcc/diagnostic-move-history.cc
>> index b0e8308dbf6b..e4c471ab50f3 100644
>> --- a/gcc/diagnostic-move-history.cc
>> +++ b/gcc/diagnostic-move-history.cc
>> @@ -24,6 +24,7 @@
>> #include "backend.h"
>> #include "tree.h"
>> #include "gimple.h"
>> +#include "tree-pretty-print.h"
>> #include "gimple-iterator.h"
>> #include "cfganal.h"
>> #include "diagnostic-move-history.h"
>> @@ -262,3 +263,69 @@ set_move_history_to_stmts_in_bb (basic_block bb, edge entry,
>>
>> return true;
>> }
>> +
>> +/* Dump the move_history data structure MV_HISTORY. */
>> +
>> +void
>> +dump_move_history (FILE *file, move_history_t mv_history)
>> +{
>> + fprintf (file, "The move history is: \n");
>
> "is:\n"
>
>> + if (!mv_history)
>> + {
>> + fprintf (file, "No move history.\n");
>> + return;
>> + }
>> +
>> + for (move_history_t cur_ch = mv_history; cur_ch;
>> + cur_ch = cur_ch->prev_move)
>> + {
>> + expanded_location exploc_cond = expand_location (cur_ch->condition);
>> +
>> + if (exploc_cond.file)
>> + fprintf (file, "[%s:", exploc_cond.file);
>> + fprintf (file, "%d, ", exploc_cond.line);
>> + fprintf (file, "%d] ", exploc_cond.column);
>> +
>> + fprintf (file, "%s ", cur_ch->is_true_path ? "true" : "false");
>> + const char *reason = NULL;
>> + switch (cur_ch->reason)
>> + {
>> + case COPY_BY_THREAD_JUMP:
>> + reason = "copy_by_thread_jump";
>> + break;
>> + case COPY_BY_ISOLATE_PATH:
>> + reason = "copy_by_isolate_path";
>> + break;
>> + case MOVE_BY_SINK:
>> + reason = "move_by_sink";
>> + break;
>> + default:
>> + reason = "UNKNOWN";
>> + break;
>> + }
>> + fprintf (file, "%s \n", reason);
>
> "s\n"
>
>> + }
>> +}
>> +
>> +/* Dump the move_history date structure attached to the gimple STMT. */
>
> date -> data
>
>> +void
>> +dump_move_history_for (FILE *file, const gimple *stmt)
>> +{
>> + move_history_t mv_history = get_move_history (stmt);
>> + if (!mv_history)
>> + fprintf (file, "No move history.\n");
>> + else
>> + dump_move_history (file, mv_history);
>> +}
>> +
>> +DEBUG_FUNCTION void
>> +debug_mv_h (const move_history_t mv_history)
>> +{
>> + dump_move_history (stderr, mv_history);
>> +}
>> +
>> +DEBUG_FUNCTION void
>> +debug_mv_h (const gimple * stmt)
>> +{
>> + dump_move_history_for (stderr, stmt);
>> +}
>> [...]
@@ -24,6 +24,7 @@
#include "backend.h"
#include "tree.h"
#include "gimple.h"
+#include "tree-pretty-print.h"
#include "gimple-iterator.h"
#include "cfganal.h"
#include "diagnostic-move-history.h"
@@ -262,3 +263,69 @@ set_move_history_to_stmts_in_bb (basic_block bb, edge entry,
return true;
}
+
+/* Dump the move_history data structure MV_HISTORY. */
+
+void
+dump_move_history (FILE *file, move_history_t mv_history)
+{
+ fprintf (file, "The move history is: \n");
+ if (!mv_history)
+ {
+ fprintf (file, "No move history.\n");
+ return;
+ }
+
+ for (move_history_t cur_ch = mv_history; cur_ch;
+ cur_ch = cur_ch->prev_move)
+ {
+ expanded_location exploc_cond = expand_location (cur_ch->condition);
+
+ if (exploc_cond.file)
+ fprintf (file, "[%s:", exploc_cond.file);
+ fprintf (file, "%d, ", exploc_cond.line);
+ fprintf (file, "%d] ", exploc_cond.column);
+
+ fprintf (file, "%s ", cur_ch->is_true_path ? "true" : "false");
+ const char *reason = NULL;
+ switch (cur_ch->reason)
+ {
+ case COPY_BY_THREAD_JUMP:
+ reason = "copy_by_thread_jump";
+ break;
+ case COPY_BY_ISOLATE_PATH:
+ reason = "copy_by_isolate_path";
+ break;
+ case MOVE_BY_SINK:
+ reason = "move_by_sink";
+ break;
+ default:
+ reason = "UNKNOWN";
+ break;
+ }
+ fprintf (file, "%s \n", reason);
+ }
+}
+
+/* Dump the move_history date structure attached to the gimple STMT. */
+void
+dump_move_history_for (FILE *file, const gimple *stmt)
+{
+ move_history_t mv_history = get_move_history (stmt);
+ if (!mv_history)
+ fprintf (file, "No move history.\n");
+ else
+ dump_move_history (file, mv_history);
+}
+
+DEBUG_FUNCTION void
+debug_mv_h (const move_history_t mv_history)
+{
+ dump_move_history (stderr, mv_history);
+}
+
+DEBUG_FUNCTION void
+debug_mv_h (const gimple * stmt)
+{
+ dump_move_history_for (stderr, stmt);
+}
@@ -88,5 +88,7 @@ extern bool set_move_history_to_stmt (gimple *, edge,
of the entry edge. */
extern bool set_move_history_to_stmts_in_bb (basic_block, edge,
bool, enum move_reason);
+extern void dump_move_history (FILE *, move_history_t);
+extern void dump_move_history_for (FILE *, const gimple *);
#endif // DIAGNOSTIC_MOVE_HISTORY_H_INCLUDED
@@ -176,6 +176,16 @@ isolate_path (basic_block bb, basic_block duplicate,
incoming edge. */
if (flag_diagnostics_details)
{
+ if (dump_file)
+ {
+ fprintf (dump_file, "Set move history for stmts of B[%d]"
+ " as not on the destination of the edge\n",
+ bb->index);
+ fprintf (dump_file, "Set move history for stmts of B[%d]"
+ " as on the destination of the edge\n",
+ duplicate->index);
+ }
+
set_move_history_to_stmts_in_bb (bb, e, false, COPY_BY_ISOLATE_PATH);
set_move_history_to_stmts_in_bb (duplicate, e,
true, COPY_BY_ISOLATE_PATH);
@@ -718,6 +718,9 @@ sink_code_in_bb (basic_block bb, virtual_operand_live &vop_live)
{
edge entry = find_edge (bb, gsi_bb (togsi));
set_move_history_to_stmt (stmt, entry, true, MOVE_BY_SINK);
+ if (dump_file)
+ fprintf (dump_file, " Set move history for the stmt"
+ " as on the destination of the edge\n");
}
/* Update virtual operands of statements in the path we
@@ -1348,6 +1348,15 @@ ssa_redirect_edges (struct redirection_data **slot,
incoming edge. */
if (flag_diagnostics_details)
{
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Set move history for stmts of B[%d]"
+ " as not on the destination of the edge\n",
+ e->dest->index);
+ fprintf (dump_file, "Set move history for stmts of B[%d]"
+ " as on the destination of the edge\n",
+ rd->dup_blocks[0]->index);
+ }
set_move_history_to_stmts_in_bb (e->dest, e, false,
COPY_BY_THREAD_JUMP);
set_move_history_to_stmts_in_bb (rd->dup_blocks[0], e,
@@ -2438,6 +2447,15 @@ back_jt_path_registry::duplicate_thread_path (edge entry,
for (i = 0; i < n_region; i++)
if (flag_diagnostics_details)
{
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Set move history for stmts of B[%d]"
+ " as not on the destination of the edge\n",
+ region[i]->index);
+ fprintf (dump_file, "Set move history for stmts of B[%d]"
+ " as on the destination of the edge\n",
+ region_copy[i]->index);
+ }
set_move_history_to_stmts_in_bb (region[i], entry, false,
COPY_BY_THREAD_JUMP);
set_move_history_to_stmts_in_bb (region_copy[i], entry,