On Wed, Jan 13, 2021 at 11:07:44PM +0800, Chung-Lin Tang wrote:
> 2021-01-13  Chung-Lin Tang  <clt...@codesourcery.com>

...
Looks mostly ok, with some nits.

>       * parse.c ("tree.h"): Add include.
>       ("omp-general.h"): Likewise.

I think the usual way is to write:
        * parse.c: Include "tree.h" and "omp-general.h".
        (gfc_parse_file): Add code to merge omp_requires to omp_requires_mask.

Something I miss in the patch is that for the device API calls (I'd bother
only with direct calls) we should probably set OMP_REQUIRES_TARGET_USED
too, so perhaps do that during gimplification if flag_openmp and
in gimplify_call_expr there is fndecl and DECL_NAME of it is non-NULL and
starts with "omp_" it looks at DECL_ASSEMBLER_NAME and compares that to a
selected list of device APIs.

Also, would it be possible to diagnose .gnu.gomp_requires mismatches also
at link time through the linker plugin/mkoffload?
At least if we have LTO offloading bytecode in and the plugin is doing
something...

> +      if (flag_openmp && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0)
> +     {
> +       const char *requires_section = ".gnu.gomp_requires";
> +       tree maskvar = build_decl (UNKNOWN_LOCATION, VAR_DECL,
> +                                  get_identifier (".gomp_requires_mask"),
> +                                  unsigned_type_node);
> +       SET_DECL_ALIGN (maskvar, TYPE_ALIGN (unsigned_type_node));
> +       TREE_STATIC (maskvar) = 1;
> +       DECL_INITIAL (maskvar)
> +         = build_int_cst (unsigned_type_node,
> +                          ((unsigned int) omp_requires_mask
> +                           & (OMP_REQUIRES_UNIFIED_ADDRESS
> +                              | OMP_REQUIRES_UNIFIED_SHARED_MEMORY
> +                              | OMP_REQUIRES_REVERSE_OFFLOAD)));
> +       set_decl_section_name (maskvar, requires_section);

This probably needs to sorry if the target doesn't support named sections.
We probably don't support LTO in that case either though.

Also, the diagnostic of the mismatches on the library side should print
details, say that libfoobar is #pragma omp requires unified_shared_memory
while libbar is not.

        Jakub

Reply via email to