diff mbox

internal fn pretty printing

Message ID 24f3b1f6-f094-34c9-cf8b-ff4caf0147fd@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Sept. 27, 2016, 10:58 a.m. UTC
In working on some new code I got sufficiently frustrated to implement pretty 
printing on internal function discriminators, as I think one of you suggested a 
while back.  With this patch we get:

  .data_dep.2 = UNIQUE (OACC_FORK, .data_dep.2, -1);

rather than an obscure raw integer for the first argument.

For the internal fns (I know of) that have a discriminator argument, I define 
the codes in appropriate macros, and then expand them to create the enum 
definitions.  In the pretty printer I examine the first argument and use that to 
index into a string array also built from the code macro.

Ok for trunk?  (I've just applied it to gomp4).

nathan

Comments

Bernd Schmidt Sept. 27, 2016, 1:30 p.m. UTC | #1
On 09/27/2016 12:58 PM, Nathan Sidwell wrote:
> In working on some new code I got sufficiently frustrated to implement
> pretty printing on internal function discriminators, as I think one of
> you suggested a while back.  With this patch we get:
>
>  .data_dep.2 = UNIQUE (OACC_FORK, .data_dep.2, -1);
>
> rather than an obscure raw integer for the first argument.
>
> For the internal fns (I know of) that have a discriminator argument, I
> define the codes in appropriate macros, and then expand them to create
> the enum definitions.  In the pretty printer I examine the first
> argument and use that to index into a string array also built from the
> code macro.
>
> Ok for trunk?  (I've just applied it to gomp4).

Ok.


Bernd
diff mbox

Patch

2016-09-27  Nathan Sidwell  <nathan@codesourcery.com>

	* internal-fn.h (IFN_UNIQUE_CODES, IFN_GOACC_LOOP_CODES,
	IFN_GOACC_REDUCTION_CODES): New.
	(enum ifn_unique_kind, enum ifn_goacc_loop_kind, enum
	ifn_goacc_reduction_kind): Use them.
	* gimple-pretty-print.c (dump_gimple_call_args): Decode first arg
	of internal functions, when applicable.

Index: gimple-pretty-print.c
===================================================================
--- gimple-pretty-print.c	(revision 240525)
+++ gimple-pretty-print.c	(working copy)
@@ -599,9 +599,63 @@  dump_gimple_return (pretty_printer *buff
 static void
 dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags)
 {
-  size_t i;
+  size_t i = 0;
 
-  for (i = 0; i < gimple_call_num_args (gs); i++)
+  /* Pretty print first arg to certain internal fns.  */
+  if (gimple_call_internal_p (gs))
+    {
+      const char *const *enums = NULL;
+      unsigned limit = 0;
+
+      switch (gimple_call_internal_fn (gs))
+	{
+	case IFN_UNIQUE:
+#define DEF(X) #X
+	  static const char *const unique_args[] = {IFN_UNIQUE_CODES};
+#undef DEF
+	  enums = unique_args;
+	  
+	  limit = ARRAY_SIZE (unique_args);
+	  break;
+	  
+	case IFN_GOACC_LOOP:
+#define DEF(X) #X
+	  static const char *const loop_args[] = {IFN_GOACC_LOOP_CODES};
+#undef DEF
+	  enums = loop_args;
+	  limit = ARRAY_SIZE (loop_args);
+	  break;
+
+	case IFN_GOACC_REDUCTION:
+#define DEF(X) #X
+	  static const char *const reduction_args[]
+	    = {IFN_GOACC_REDUCTION_CODES};
+#undef DEF
+	  enums = reduction_args;
+	  limit = ARRAY_SIZE (reduction_args);
+	  break;
+
+	default:
+	  break;
+	}
+      if (limit)
+	{
+	  tree arg0 = gimple_call_arg (gs, 0);
+	  HOST_WIDE_INT v;
+
+	  if (TREE_CODE (arg0) == INTEGER_CST
+	      && tree_fits_shwi_p (arg0)
+	      && (v = tree_to_shwi (arg0)) >= 0 && v < limit)
+	    {
+	      i++;
+	      pp_string (buffer, enums[v]);
+	      if (i < gimple_call_num_args (gs))
+		pp_string (buffer, ", ");
+	    }
+	}
+    }
+
+  for (; i < gimple_call_num_args (gs); i++)
     {
       dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
       if (i < gimple_call_num_args (gs) - 1)
Index: internal-fn.h
===================================================================
--- internal-fn.h	(revision 240525)
+++ internal-fn.h	(working copy)
@@ -20,26 +20,28 @@  along with GCC; see the file COPYING3.
 #ifndef GCC_INTERNAL_FN_H
 #define GCC_INTERNAL_FN_H
 
-/* INTEGER_CST values for IFN_UNIQUE function arg-0.  */
-enum ifn_unique_kind {
-  IFN_UNIQUE_UNSPEC,  /* Undifferentiated UNIQUE.  */
+/* INTEGER_CST values for IFN_UNIQUE function arg-0.
+
+   UNSPEC: Undifferentiated UNIQUE.
 
-  /* FORK and JOIN mark the points at which OpenACC partitioned
-     execution is entered or exited.
-     return: data dependency value
-     arg-1: data dependency var
-     arg-2: INTEGER_CST argument, indicating the axis.  */
-  IFN_UNIQUE_OACC_FORK,
-  IFN_UNIQUE_OACC_JOIN,
-
-  /* HEAD_MARK and TAIL_MARK are used to demark the sequence entering
-     or leaving partitioned execution.
-     return: data dependency value
-     arg-1: data dependency var
-     arg-2: INTEGER_CST argument, remaining markers in this sequence
-     arg-3...: varargs on primary header  */
-  IFN_UNIQUE_OACC_HEAD_MARK,
-  IFN_UNIQUE_OACC_TAIL_MARK
+   FORK and JOIN mark the points at which OpenACC partitioned
+   execution is entered or exited.
+      DEP_VAR = UNIQUE ({FORK,JOIN}, DEP_VAR, AXIS)
+
+   HEAD_MARK and TAIL_MARK are used to demark the sequence entering
+   or leaving partitioned execution.
+      DEP_VAR = UNIQUE ({HEAD,TAIL}_MARK, REMAINING_MARKS, ...PRIMARY_FLAGS)
+
+   The PRIMARY_FLAGS only occur on the first HEAD_MARK of a sequence.  */
+#define IFN_UNIQUE_CODES				  \
+  DEF(UNSPEC),	\
+    DEF(OACC_FORK), DEF(OACC_JOIN),		\
+    DEF(OACC_HEAD_MARK), DEF(OACC_TAIL_MARK)
+
+enum ifn_unique_kind {
+#define DEF(X) IFN_UNIQUE_##X
+  IFN_UNIQUE_CODES
+#undef DEF
 };
 
 /* INTEGER_CST values for IFN_GOACC_LOOP arg-0.  Allows the precise
@@ -59,11 +61,12 @@  enum ifn_unique_kind {
      CHUNK_NO - chunk number
      MASK - partitioning mask.  */
 
+#define IFN_GOACC_LOOP_CODES \
+  DEF(CHUNKS), DEF(STEP), DEF(OFFSET), DEF(BOUND)
 enum ifn_goacc_loop_kind {
-  IFN_GOACC_LOOP_CHUNKS,  /* Number of chunks.  */
-  IFN_GOACC_LOOP_STEP,    /* Size of each thread's step.  */
-  IFN_GOACC_LOOP_OFFSET,  /* Initial iteration value.  */
-  IFN_GOACC_LOOP_BOUND    /* Limit of iteration value.  */
+#define DEF(X) IFN_GOACC_LOOP_##X
+  IFN_GOACC_LOOP_CODES
+#undef DEF
 };
 
 /* The GOACC_REDUCTION function defines a generic interface to support
@@ -81,11 +84,12 @@  enum ifn_goacc_loop_kind {
    In general the return value is LOCAL_VAR, which creates a data
    dependency between calls operating on the same reduction.  */
 
+#define IFN_GOACC_REDUCTION_CODES \
+  DEF(SETUP), DEF(INIT), DEF(FINI), DEF(TEARDOWN)
 enum ifn_goacc_reduction_kind {
-  IFN_GOACC_REDUCTION_SETUP,
-  IFN_GOACC_REDUCTION_INIT,
-  IFN_GOACC_REDUCTION_FINI,
-  IFN_GOACC_REDUCTION_TEARDOWN
+#define DEF(X) IFN_GOACC_REDUCTION_##X
+  IFN_GOACC_REDUCTION_CODES
+#undef DEF
 };
 
 /* Initialize internal function tables.  */