diff options
author | David Malcolm <dmalcolm@redhat.com> | 2022-04-28 13:46:15 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2022-04-28 13:48:41 -0400 |
commit | d8586b00dd00a1783862da5f0c8811a740400074 (patch) | |
tree | cc23674ed7415bb569e850bc0005b398c65cf225 | |
parent | 509fd16da8528444dccc98cef57a18a295c3f1b4 (diff) | |
download | gcc-d8586b00dd00a1783862da5f0c8811a740400074.zip gcc-d8586b00dd00a1783862da5f0c8811a740400074.tar.gz gcc-d8586b00dd00a1783862da5f0c8811a740400074.tar.bz2 |
analyzer: add .fpath.txt dumps to -fdump-analyzer-feasibility
I found this extension to -fdump-analyzer-feasibility very helpful when
debugging PR analyzer/105285.
gcc/analyzer/ChangeLog:
* diagnostic-manager.cc (epath_finder::process_worklist_item):
Call dump_feasible_path when a path that reaches the the target
enode is found.
(epath_finder::dump_feasible_path): New.
* engine.cc (feasibility_state::dump_to_pp): New.
* exploded-graph.h (feasibility_state::dump_to_pp): New decl.
* feasible-graph.cc (feasible_graph::dump_feasible_path): New.
* feasible-graph.h (feasible_graph::dump_feasible_path): New
decls.
* program-point.cc (function_point::print): Fix missing trailing
newlines.
* program-point.h (program_point::print_source_line): Remove
unimplemented decl.
gcc/ChangeLog:
* doc/invoke.texi (-fdump-analyzer-feasibility): Mention the
fpath.txt output.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
-rw-r--r-- | gcc/analyzer/diagnostic-manager.cc | 24 | ||||
-rw-r--r-- | gcc/analyzer/engine.cc | 9 | ||||
-rw-r--r-- | gcc/analyzer/exploded-graph.h | 2 | ||||
-rw-r--r-- | gcc/analyzer/feasible-graph.cc | 65 | ||||
-rw-r--r-- | gcc/analyzer/feasible-graph.h | 6 | ||||
-rw-r--r-- | gcc/analyzer/program-point.cc | 4 | ||||
-rw-r--r-- | gcc/analyzer/program-point.h | 1 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 4 |
8 files changed, 112 insertions, 3 deletions
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index bf7c8fc..5bd4cd4 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -112,6 +112,10 @@ private: void dump_feasible_graph (const exploded_node *target_enode, const char *desc, unsigned diag_idx, const feasible_graph &fg); + void dump_feasible_path (const exploded_node *target_enode, + unsigned diag_idx, + const feasible_graph &fg, + const feasible_node &fnode) const; const exploded_graph &m_eg; shortest_exploded_paths *m_sep; @@ -510,6 +514,9 @@ epath_finder::process_worklist_item (feasible_worklist *worklist, target_enode->m_index, diag_idx, succ_fnode->get_path_length ()); *out_best_path = fg->make_epath (succ_fnode); + if (flag_dump_analyzer_feasibility) + dump_feasible_path (target_enode, diag_idx, *fg, *succ_fnode); + /* Success: stop the worklist iteration. */ return false; } @@ -608,6 +615,23 @@ epath_finder::dump_feasible_graph (const exploded_node *target_enode, free (filename); } +/* Dump the path to FNODE to "BASE_NAME.DIAG_IDX.to-enN.fpath.txt". */ + +void +epath_finder::dump_feasible_path (const exploded_node *target_enode, + unsigned diag_idx, + const feasible_graph &fg, + const feasible_node &fnode) const +{ + auto_timevar tv (TV_ANALYZER_DUMP); + pretty_printer pp; + pp_printf (&pp, "%s.%i.to-en%i.fpath.txt", + dump_base_name, diag_idx, target_enode->m_index); + char *filename = xstrdup (pp_formatted_text (&pp)); + fg.dump_feasible_path (fnode, filename); + free (filename); +} + /* class saved_diagnostic. */ /* saved_diagnostic's ctor. diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index d8b6195..e43406e 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -4605,6 +4605,15 @@ feasibility_state::maybe_update_for_edge (logger *logger, return true; } +/* Dump this object to PP. */ + +void +feasibility_state::dump_to_pp (pretty_printer *pp, + bool simple, bool multiline) const +{ + m_model.dump_to_pp (pp, simple, multiline); +} + /* A family of cluster subclasses for use when generating .dot output for exploded graphs (-fdump-analyzer-exploded-graph), for grouping the enodes into hierarchical boxes. diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index af0ab8d..2dcdcc5 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -1001,6 +1001,8 @@ public: const region_model &get_model () const { return m_model; } const auto_sbitmap &get_snodes_visited () const { return m_snodes_visited; } + void dump_to_pp (pretty_printer *pp, bool simple, bool multiline) const; + private: region_model m_model; auto_sbitmap m_snodes_visited; diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc index 0ac8484..fe7e79f 100644 --- a/gcc/analyzer/feasible-graph.cc +++ b/gcc/analyzer/feasible-graph.cc @@ -218,6 +218,71 @@ feasible_graph::make_epath (feasible_node *fnode) const return epath; } +/* Dump the path to DST_FNODE in textual form to PP. */ + +void +feasible_graph::dump_feasible_path (const feasible_node &dst_fnode, + pretty_printer *pp) const +{ + const feasible_node *fnode = &dst_fnode; + + auto_vec<const feasible_edge *> fpath; + + /* FG is actually a tree. Built the path backwards, by walking + backwards from FNODE until we reach the origin. */ + while (fnode->get_inner_node ()->m_index != 0) + { + gcc_assert (fnode->m_preds.length () == 1); + feasible_edge *pred_fedge + = static_cast <feasible_edge *> (fnode->m_preds[0]); + fpath.safe_push (pred_fedge); + fnode = static_cast <const feasible_node *> (pred_fedge->m_src); + } + + /* Now reverse it. */ + fpath.reverse (); + + for (unsigned i = 0; i < fpath.length (); i++) + { + const feasible_edge *fedge = fpath[i]; + const feasible_node *src_fnode + = static_cast <const feasible_node *> (fedge->m_src); + const feasible_node *dest_fnode + = static_cast <const feasible_node *> (fedge->m_dest); + + pp_printf (pp, "fpath[%i]: FN %i (EN %i) -> FN %i (EN %i)", + i, + src_fnode->get_index (), + src_fnode->get_inner_node ()->m_index, + dest_fnode->get_index (), + dest_fnode->get_inner_node ()->m_index); + pp_newline (pp); + pp_printf (pp, " FN %i (EN %i):", + dest_fnode->get_index (), + dest_fnode->get_inner_node ()->m_index); + pp_newline (pp); + const program_point &point = dest_fnode->get_inner_node ()->get_point (); + point.print (pp, format (true)); + dest_fnode->get_state ().dump_to_pp (pp, true, true); + pp_newline (pp); + } +} + +/* Dump the path to DST_FNODE in textual form to FILENAME. */ + +void +feasible_graph::dump_feasible_path (const feasible_node &dst_fnode, + const char *filename) const +{ + FILE *fp = fopen (filename, "w"); + pretty_printer pp; + pp_format_decoder (&pp) = default_tree_printer; + pp.buffer->stream = fp; + dump_feasible_path (dst_fnode, &pp); + pp_flush (&pp); + fclose (fp); +} + /* Dump stats about this graph to LOGGER. */ void diff --git a/gcc/analyzer/feasible-graph.h b/gcc/analyzer/feasible-graph.h index d10a28d..f1868af 100644 --- a/gcc/analyzer/feasible-graph.h +++ b/gcc/analyzer/feasible-graph.h @@ -197,11 +197,17 @@ class feasible_graph : public digraph <fg_traits> exploded_path *make_epath (feasible_node *fnode) const; + void dump_feasible_path (const feasible_node &dst_fnode, + const char *filename) const; + unsigned get_num_infeasible () const { return m_num_infeasible; } void log_stats (logger *logger) const; private: + void dump_feasible_path (const feasible_node &dst_fnode, + pretty_printer *pp) const; + unsigned m_num_infeasible; }; diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index 61cea8a..8fa7066 100644 --- a/gcc/analyzer/program-point.cc +++ b/gcc/analyzer/program-point.cc @@ -114,6 +114,8 @@ function_point::print (pretty_printer *pp, const format &f) const case PK_ORIGIN: pp_printf (pp, "origin"); + if (f.m_newlines) + pp_newline (pp); break; case PK_BEFORE_SUPERNODE: @@ -156,6 +158,8 @@ function_point::print (pretty_printer *pp, const format &f) const case PK_AFTER_SUPERNODE: pp_printf (pp, "after SN: %i", m_supernode->m_index); + if (f.m_newlines) + pp_newline (pp); break; } } diff --git a/gcc/analyzer/program-point.h b/gcc/analyzer/program-point.h index 4b1c733..6084c9e 100644 --- a/gcc/analyzer/program-point.h +++ b/gcc/analyzer/program-point.h @@ -179,7 +179,6 @@ public: } void print (pretty_printer *pp, const format &f) const; - void print_source_line (pretty_printer *pp) const; void dump () const; json::object *to_json () const; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 07b4401..b2d2cea 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -10198,8 +10198,8 @@ diagnostic to @file{@var{file}.@var{idx}.@var{kind}.epath.txt}. @opindex dump-analyzer-feasibility Dump internal details about the analyzer's search for feasible paths. The details are written in a form suitable for viewing with GraphViz -to filenames of the form @file{@var{file}.*.fg.dot} and -@file{@var{file}.*.tg.dot}. +to filenames of the form @file{@var{file}.*.fg.dot}, +@file{@var{file}.*.tg.dot}, and @file{@var{file}.*.fpath.txt}. @item -fdump-analyzer-json @opindex fdump-analyzer-json |