diff mbox series

[committed,nvptx] Eliminate changed local var in nvptx_goacc_validate_dims

Message ID 20190103151634.GA22597@delia
State New
Headers show
Series [committed,nvptx] Eliminate changed local var in nvptx_goacc_validate_dims | expand

Commit Message

Tom de Vries Jan. 3, 2019, 3:16 p.m. UTC
Hi,

The TARGET_GOACC_VALIDATE_DIMS hook requires an implementation to return a bool
indicating whether the dims parameter has changed.

Factor nvptx_goacc_validate_dims_1 out of nvptx_goacc_validate_dims, and
calculate the return value in nvptx_goacc_validate_dims.

Committed to trunk.

Thanks,
- Tom

[nvptx] Eliminate changed local var in nvptx_goacc_validate_dims

2019-01-03  Tom de Vries  <tdevries@suse.de>

	* config/nvptx/nvptx.c (nvptx_goacc_validate_dims_1): New function,
	factored out of ...
	(nvptx_goacc_validate_dims): ... here.

---
 gcc/config/nvptx/nvptx.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index f4095ff5f55..39cf2c7b22a 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -5188,15 +5188,12 @@  nvptx_simt_vf ()
   return PTX_WARP_SIZE;
 }
 
-/* Validate compute dimensions of an OpenACC offload or routine, fill
-   in non-unity defaults.  FN_LEVEL indicates the level at which a
-   routine might spawn a loop.  It is negative for non-routines.  If
-   DECL is null, we are validating the default dimensions.  */
+/* As nvptx_goacc_validate_dims, but does not return bool to indicate whether
+   DIMS has changed.  */
 
-static bool
-nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
+static void
+nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level)
 {
-  bool changed = false;
   bool oacc_default_dims_p = false;
   bool oacc_min_dims_p = false;
   bool offload_region_p = false;
@@ -5255,7 +5252,6 @@  nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
       dims[GOMP_DIM_VECTOR] = fn_level > GOMP_DIM_VECTOR ? 1 : 0;
       dims[GOMP_DIM_WORKER] = fn_level > GOMP_DIM_WORKER ? 1 : 0;
       dims[GOMP_DIM_GANG] = fn_level > GOMP_DIM_GANG ? 1 : 0;
-      changed = true;
     }
 
   /* The vector size must be 32, unless this is a SEQ routine.  */
@@ -5272,7 +5268,6 @@  nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
 		    : G_("using vector_length (%d), ignoring runtime setting"),
 		    PTX_VECTOR_LENGTH, dims[GOMP_DIM_VECTOR]);
       dims[GOMP_DIM_VECTOR] = PTX_VECTOR_LENGTH;
-      changed = true;
     }
 
   /* Check the num workers is not too large.  */
@@ -5282,7 +5277,6 @@  nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
 		  "using num_workers (%d), ignoring %d",
 		  PTX_WORKER_LENGTH, dims[GOMP_DIM_WORKER]);
       dims[GOMP_DIM_WORKER] = PTX_WORKER_LENGTH;
-      changed = true;
     }
 
   if (oacc_default_dims_p || oacc_min_dims_p)
@@ -5292,10 +5286,30 @@  nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
 	dims[GOMP_DIM_WORKER] = PTX_DEFAULT_RUNTIME_DIM;
       if (dims[GOMP_DIM_GANG] < 0)
 	dims[GOMP_DIM_GANG] = PTX_DEFAULT_RUNTIME_DIM;
-      changed = true;
     }
+}
+
+/* Validate compute dimensions of an OpenACC offload or routine, fill
+   in non-unity defaults.  FN_LEVEL indicates the level at which a
+   routine might spawn a loop.  It is negative for non-routines.  If
+   DECL is null, we are validating the default dimensions.  */
+
+static bool
+nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
+{
+  int old_dims[GOMP_DIM_MAX];
+  unsigned int i;
 
-  return changed;
+  for (i = 0; i < GOMP_DIM_MAX; ++i)
+    old_dims[i] = dims[i];
+
+  nvptx_goacc_validate_dims_1 (decl, dims, fn_level);
+
+  for (i = 0; i < GOMP_DIM_MAX; ++i)
+    if (old_dims[i] != dims[i])
+      return true;
+
+  return false;
 }
 
 /* Return maximum dimension size, or zero for unbounded.  */