With the change to use enumerators instead of strings to represent
context selector and selector-set names, the default tree-list output
for dumping selectors is less helpful for debugging and harder to use
in test cases.  This patch adds support for dumping context selectors
using syntax similar to that used for input to the compiler.

gcc/ChangeLog
        * omp-general.cc (omp_context_name_list_prop): Remove static qualifer.
        * omp-general.h (omp_context_name_list_prop): Declare.
        * tree-cfg.cc (dump_function_to_file): Intercept
        "omp declare variant base" attribute for special handling.
        * tree-pretty-print.cc: Include omp-general.h.
        (dump_omp_context_selector): New.
        (print_omp_context_selector): New.
        * tree-pretty-print.h (dump_omp_context_selector): Declare.
        (print_omp_context_selector): Declare.
---
 gcc/omp-general.cc       |  2 +-
 gcc/omp-general.h        |  1 +
 gcc/tree-cfg.cc          |  9 +++++
 gcc/tree-pretty-print.cc | 75 ++++++++++++++++++++++++++++++++++++++++
 gcc/tree-pretty-print.h  |  3 ++
 5 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 233f235d81e..65990df1238 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1234,7 +1234,7 @@ struct omp_ts_info omp_ts_map[] =
 /* Return a name from PROP, a property in selectors accepting
    name lists.  */
 
-static const char *
+const char *
 omp_context_name_list_prop (tree prop)
 {
   gcc_assert (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE);
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 66ed4903513..3c2b221b226 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -164,6 +164,7 @@ extern gimple *omp_build_barrier (tree lhs);
 extern tree find_combined_omp_for (tree *, int *, void *);
 extern poly_uint64 omp_max_vf (void);
 extern int omp_max_simt_vf (void);
+extern const char *omp_context_name_list_prop (tree);
 extern void omp_construct_traits_to_codes (tree, int, enum tree_code *);
 extern tree omp_check_context_selector (location_t loc, tree ctx);
 extern void omp_mark_declare_variant (location_t loc, tree variant,
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index d784b911532..1ab18fa6b0f 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -8291,6 +8291,15 @@ dump_function_to_file (tree fndecl, FILE *file, 
dump_flags_t flags)
 
              if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
                print_no_sanitize_attr_value (file, TREE_VALUE (chain));
+             else if (!strcmp (IDENTIFIER_POINTER (name),
+                               "omp declare variant base"))
+               {
+                 tree a = TREE_VALUE (chain);
+                 print_generic_expr (file, TREE_PURPOSE (a), dump_flags);
+                 fprintf (file, " match ");
+                 print_omp_context_selector (file, TREE_VALUE (a),
+                                             dump_flags);
+               }
              else
                print_generic_expr (file, TREE_VALUE (chain), dump_flags);
              fprintf (file, ")");
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 68857ae1cdf..fd61d28faff 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gomp-constants.h"
 #include "gimple.h"
 #include "fold-const.h"
+#include "omp-general.h"
 
 /* Routines in this file get invoked via the default tree printer
    used by diagnostics and thus they are called from pp_printf which
@@ -1497,6 +1498,80 @@ dump_omp_clauses (pretty_printer *pp, tree clause, int 
spc, dump_flags_t flags,
     }
 }
 
+/* Dump an OpenMP context selector CTX to PP.  */
+void
+dump_omp_context_selector (pretty_printer *pp, tree ctx, int spc,
+                          dump_flags_t flags)
+{
+  for (tree set = ctx; set && set != error_mark_node; set = TREE_CHAIN (set))
+    {
+      pp_string (pp, OMP_TSS_NAME (set));
+      pp_string (pp, " = {");
+      for (tree sel = OMP_TSS_TRAIT_SELECTORS (set);
+          sel && sel != error_mark_node; sel = TREE_CHAIN (sel))
+       {
+         if (OMP_TS_CODE (sel) == OMP_TRAIT_INVALID)
+           pp_string (pp, "<unknown selector>");
+         else
+           pp_string (pp, OMP_TS_NAME (sel));
+         tree score = OMP_TS_SCORE (sel);
+         tree props = OMP_TS_PROPERTIES (sel);
+         if (props)
+           {
+             pp_string (pp, " (");
+             if (score)
+               {
+                 pp_string (pp, "score(");
+                 dump_generic_node (pp, score, spc + 4, flags, false);
+                 pp_string (pp, "): ");
+               }
+             for (tree prop = props; prop; prop = TREE_CHAIN (prop))
+               {
+                 if (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE)
+                   {
+                     const char *str = omp_context_name_list_prop (prop);
+                     pp_string (pp, "\"");
+                     pretty_print_string (pp, str, strlen (str) + 1);
+                     pp_string (pp, "\"");
+                   }
+                 else if (OMP_TP_NAME (prop))
+                   dump_generic_node (pp, OMP_TP_NAME (prop), spc + 4,
+                                      flags, false);
+                 else if (OMP_TP_VALUE (prop))
+                   dump_generic_node (pp, OMP_TP_VALUE (prop), spc + 4,
+                                      flags, false);
+                 if (TREE_CHAIN (prop))
+                   {
+                     pp_comma (pp);
+                     pp_space (pp);
+                   }
+               }
+             pp_string (pp, ")");
+           }
+         if (TREE_CHAIN (sel))
+           {
+             pp_comma (pp);
+             pp_space (pp);
+           }
+       }
+      pp_string (pp, "}");
+      if (TREE_CHAIN (set))
+       {
+         pp_comma (pp);
+         newline_and_indent (pp, spc);
+       }
+    }
+}
+
+/* Wrapper for above, used for "declare variant".  Compare to
+   print_generic_expr.  */
+void
+print_omp_context_selector (FILE *file, tree t, dump_flags_t flags)
+{
+  maybe_init_pretty_print (file);
+  dump_omp_context_selector (tree_pp, t, 0, flags);
+  pp_flush (tree_pp);
+}
 
 /* Dump location LOC to PP.  */
 
diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h
index 12bae053e5a..32e4b0ef2e8 100644
--- a/gcc/tree-pretty-print.h
+++ b/gcc/tree-pretty-print.h
@@ -45,6 +45,9 @@ extern void dump_omp_atomic_memory_order (pretty_printer *,
                                          enum omp_memory_order);
 extern void dump_omp_loop_non_rect_expr (pretty_printer *, tree, int,
                                         dump_flags_t);
+extern void dump_omp_context_selector (pretty_printer *, tree, int,
+                                      dump_flags_t);
+extern void print_omp_context_selector (FILE *, tree, dump_flags_t);
 extern int dump_generic_node (pretty_printer *, tree, int, dump_flags_t, bool);
 extern void print_declaration (pretty_printer *, tree, int, dump_flags_t);
 extern int op_code_prio (enum tree_code);
-- 
2.31.1

Reply via email to