On Tue, Apr 05, 2016 at 06:53:47PM -0700, Cesar Philippidis wrote: > --- a/gcc/omp-low.c > +++ b/gcc/omp-low.c > @@ -309,6 +309,25 @@ is_oacc_kernels (omp_context *ctx) > == GF_OMP_TARGET_KIND_OACC_KERNELS)); > } > > +/* Return true if CTX corresponds to an oacc parallel region and if > + VAR is used in a reduction. */ > + > +static bool > +is_oacc_parallel_reduction (tree var, omp_context *ctx) > +{ > + if (!is_oacc_parallel (ctx)) > + return false; > + > + tree clauses = gimple_omp_target_clauses (ctx->stmt); > + > + for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) > + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION > + && OMP_CLAUSE_DECL (c) == var) > + return true; > + > + return false; > +} > + > /* If DECL is the artificial dummy VAR_DECL created for non-static > data member privatization, return the underlying "this" parameter, > otherwise return NULL. */ > @@ -2122,7 +2141,8 @@ scan_sharing_clauses (tree clauses, omp_context *ctx, > else > install_var_field (decl, true, 3, ctx, > base_pointers_restrict); > - if (is_gimple_omp_offloaded (ctx->stmt)) > + if (is_gimple_omp_offloaded (ctx->stmt) > + && !is_oacc_parallel_reduction (decl, ctx)) > install_var_local (decl, ctx); > } > }
The above is O(n^2) in number of clauses on the construct. Perhaps better define some OMP_CLAUSE_MAP_IN_REDUCTION macro (e.g. TREE_PRIVATE bit is unused on OMP_CLAUSE_MAP right now), make sure to set it e.g. during gimplification where you can see all GOVD_* flags for a particular decl), and then use this flag here? Jakub