[Patch][OpenMP][Fortran] Support absent optional args with use_device_{ptr,addr} (+ OpenACC's use_device clause)
Jakub Jelinek
jakub@redhat.com
Fri Nov 8 14:39:00 GMT 2019
On Thu, Nov 07, 2019 at 11:42:22AM +0100, Tobias Burnus wrote:
> + /* For VALUE, the scalar variable is passed as is but a hidden argument
> + denotes the value. Cf. trans-expr.c. */
> + if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE)
> + {
> + char name[GFC_MAX_SYMBOL_LEN + 2];
> + tree tree_name;
> +
> + name[0] = '_';
> + strcpy (&name[1], IDENTIFIER_POINTER (DECL_NAME (decl)));
> + tree_name = get_identifier (name);
> +
> + /* Walk function argument list to find the hidden arg. */
> + decl = DECL_ARGUMENTS (DECL_CONTEXT (decl));
> + for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
> + if (DECL_NAME (decl) == tree_name)
> + break;
> +
> + gcc_assert (decl);
> + return decl;
> + }
Is this reliable? I mean, consider -fallow-leading-underscore with:
subroutine foo (a, _a)
integer, optional, value :: a
logical(kind=1), value :: _a
...
end subroutine foo
and whatever OpenMP clause is affected in ...
In GIMPLE dump I certainly see:
foo (integer(kind=4) a, logical(kind=1) _a, logical(kind=1) _a)
and I bet the above would pick the wrong one.
Not really sure if additional DECL_ARTIFICIAL (decl) test would be enough.
> --- a/gcc/omp-general.c
> +++ b/gcc/omp-general.c
> @@ -63,12 +63,18 @@ omp_is_allocatable_or_ptr (tree decl)
> return lang_hooks.decls.omp_is_allocatable_or_ptr (decl);
> }
>
> -/* Return true if DECL is a Fortran optional argument. */
> +/* Check whether this DECL belongs to a Fortran optional argument.
> + With 'for_present_check' set to false, decls which are optional parameters
> + themselve are returned as tree - or a NULL_TREE otherwise. Those decls are
> + always pointers. With 'for_present_check' set to true, the decl for checking
> + whether an argument is present is returned; for arguments with value
> + attribute this is the hidden argument and of BOOLEAN_TYPE. If the decl is
> + unrelated to optional arguments, NULL_TREE is returned. */
>
> -bool
> -omp_is_optional_argument (tree decl)
> +tree
> +omp_check_optional_argument (tree decl, bool also_value)
Why is the argument called for_present_check in the langhook and
also_value here? Looks inconsistent.
> --- a/gcc/omp-general.h
> +++ b/gcc/omp-general.h
> @@ -74,7 +74,7 @@ struct omp_for_data
>
> extern tree omp_find_clause (tree clauses, enum omp_clause_code kind);
> extern bool omp_is_allocatable_or_ptr (tree decl);
> -extern bool omp_is_optional_argument (tree decl);
> +extern tree omp_check_optional_argument (tree decl, bool also_value);
> extern bool omp_is_reference (tree decl);
> extern void omp_adjust_for_condition (location_t loc, enum tree_code *cond_code,
> tree *n2, tree v, tree step);
Here too.
Jakub
More information about the Gcc-patches
mailing list