On Wed, Jul 15, 2015 at 07:47:12AM -0700, Aldy Hernandez wrote:
> This fixes the problem with C++ iterators not working as sink() iterator
> variables.
> 
> OK for branch?

I wonder (though not 100% sure about) if, because we really need the
OMP_FOR_ORIG_DECLS on OMP_FOR only, no other construct can be ordered,
it wouldn't make more sense to make
#define OMP_FOR_ORIG_DECLS(NODE)   TREE_OPERAND (OMP_FOR_CHECK (NODE), 6)
(note, FOR rather than LOOP) and only use 7 arguments on OMP_FOR and
not all the other loop constructs.  That would of course mean
guarding all setters and users of OMP_FOR_ORIG_DECLS (x) with
if (TREE_CODE (x) == OMP_FOR), but that is just 2 locations.

> --- a/gcc/gimplify.c
> +++ b/gcc/gimplify.c
> @@ -7311,7 +7311,11 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
>        gcc_assert (DECL_P (decl));
>        gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl))
>                 || POINTER_TYPE_P (TREE_TYPE (decl)));
> -      gimplify_omp_ctxp->iter_vars.quick_push (decl);
> +      if (OMP_FOR_ORIG_DECLS (for_stmt))
> +     gimplify_omp_ctxp->iter_vars.quick_push
> +       (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i));
> +      else
> +     gimplify_omp_ctxp->iter_vars.quick_push (decl);

No matter the decision about above, I think you want to quick_push
here twice for each decl (or have two vectors, but a single one is probably
better), and rewrite all uses of the orig decl to the new decl.
Note, gimplify_omp_for can also do similar replacement of an orig decl
with a new decl (even for OMP_FOR_ORIG_DECLS == NULL case aka C),
when the iterator var is addressable.

> +#pragma omp parallel for ordered(1)
> +  for (it = v.begin(); it < v.end(); ++it)
> +    {
> +#pragma omp ordered depend(sink:it)
> +    std::cout << *it << '\n';
> +    }
> +}

I'd try to avoid adding such blatanly wrong testcases, even just
for parsing, perhaps one day we'll want to diagnose it.
Depending on the current iteration is just wrong (like on a future one).
And with no depend(source) it will just hang.
So, can you make it depend(sink:it-1) and add
#pragma omp ordered depend(source) after it?

        Jakub

Reply via email to