]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Add prettyprinter support for context selectors.
authorSandra Loosemore <sandra@codesourcery.com>
Fri, 22 Dec 2023 16:35:45 +0000 (16:35 +0000)
committerSandra Loosemore <sandra@codesourcery.com>
Fri, 22 Dec 2023 16:38:33 +0000 (16:38 +0000)
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 (print_omp_context_selector): Declare.

gcc/omp-general.cc
gcc/omp-general.h
gcc/tree-cfg.cc
gcc/tree-pretty-print.cc
gcc/tree-pretty-print.h

index 233f235d81ea1e6f9f0da93f8608c1fd2844fd6c..65990df1238598a63082d0627cd69ba7d45f3613 100644 (file)
@@ -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);
index 66ed4903513e0765c45b1ac700d3bffd5f57e507..3c2b221b226e1fe28999b21d331d0d073930a3b2 100644 (file)
@@ -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,
index d784b911532fa451f289fe38d8084f0d02e42c83..1ab18fa6b0fa7bd7396247a6db7511884f1d137d 100644 (file)
@@ -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, ")");
index 46e14398581dc37193ce7046a583265d3b310a2d..2848652915359bc38d2f1f20550098bf81b665c5 100644 (file)
@@ -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.  */
+static 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.  */
 
index 12bae053e5a1f731e174e092affa34e65dddfe64..3a02ebd87ec57cc123203e54239c272b2e473794 100644 (file)
@@ -45,6 +45,7 @@ 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 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);