On Wed, Nov 18, 2015 at 12:47:47PM +0000, Julian Brown wrote:

The FE/gimplifier part is okay, but I really don't like the
omp-low.c changes, mostly the *lookup_decl_in_outer_ctx* changes.
If I count well, we have right now 27 maybe_lookup_decl_in_outer_ctx
callers and 7 lookup_decl_in_outer_ctx callers, you want to change
behavior of 1 maybe_lookup_decl_in_outer_ctx and 1
lookup_decl_in_outer_ctx.  Why exactly those 2 and not the others?
What are the exact rules (what does the standard say about it)?
I'd expect that all phases (scan_sharing_clauses, lower_omp* and
expand_omp*) should agree on the same behavior, otherwise I can't see how it
can work properly.  And, if you want to change just a couple of spots,
I'd strongly prefer to add new functions with this weirdo behavior, rather
than tweaking the original function.

> --- a/gcc/omp-low.c
> +++ b/gcc/omp-low.c
> @@ -390,8 +390,8 @@ scan_omp_op (tree *tp, omp_context *ctx)
>  }
>  
>  static void lower_omp (gimple_seq *, omp_context *);
> -static tree lookup_decl_in_outer_ctx (tree, omp_context *);
> -static tree maybe_lookup_decl_in_outer_ctx (tree, omp_context *);
> +static tree lookup_decl_in_outer_ctx (tree, omp_context *, bool = false);
> +static tree maybe_lookup_decl_in_outer_ctx (tree, omp_context *, bool = 
> false);
>  
>  /* Find an OMP clause of type KIND within CLAUSES.  */
>  
> @@ -1935,6 +1935,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
>         install_var_local (decl, ctx);
>         break;
>  
> +     case OMP_CLAUSE_USE_DEVICE:
>       case OMP_CLAUSE_USE_DEVICE_PTR:
>         decl = OMP_CLAUSE_DECL (c);
>         if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
> @@ -2137,7 +2138,6 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
>         break;
>  
>       case OMP_CLAUSE_DEVICE_RESIDENT:
> -     case OMP_CLAUSE_USE_DEVICE:
>       case OMP_CLAUSE__CACHE_:
>         sorry ("Clause not supported yet");
>         break;
> @@ -2288,6 +2288,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
>       case OMP_CLAUSE_SIMD:
>       case OMP_CLAUSE_NOGROUP:
>       case OMP_CLAUSE_DEFAULTMAP:
> +     case OMP_CLAUSE_USE_DEVICE:
>       case OMP_CLAUSE_USE_DEVICE_PTR:
>       case OMP_CLAUSE__CILK_FOR_COUNT_:
>       case OMP_CLAUSE_ASYNC:
> @@ -2305,7 +2306,6 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
>         break;
>  
>       case OMP_CLAUSE_DEVICE_RESIDENT:
> -     case OMP_CLAUSE_USE_DEVICE:
>       case OMP_CLAUSE__CACHE_:
>         sorry ("Clause not supported yet");
>         break;
> @@ -3608,6 +3608,8 @@ check_omp_nesting_restrictions (gimple *stmt, 
> omp_context *ctx)
>           case GF_OMP_TARGET_KIND_OACC_UPDATE: stmt_name = "update"; break;
>           case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
>             stmt_name = "enter/exit data"; break;
> +         case GF_OMP_TARGET_KIND_OACC_HOST_DATA: stmt_name = "host_data";
> +           break;
>           default: gcc_unreachable ();
>           }
>         switch (gimple_omp_target_kind (ctx->stmt))
> @@ -3619,6 +3621,8 @@ check_omp_nesting_restrictions (gimple *stmt, 
> omp_context *ctx)
>           case GF_OMP_TARGET_KIND_OACC_KERNELS:
>             ctx_stmt_name = "kernels"; break;
>           case GF_OMP_TARGET_KIND_OACC_DATA: ctx_stmt_name = "data"; break;
> +         case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
> +           ctx_stmt_name = "host_data"; break;
>           default: gcc_unreachable ();
>           }
>  
> @@ -3941,13 +3945,22 @@ maybe_lookup_ctx (gimple *stmt)
>      parallelism happens only rarely.  */
>  
>  static tree
> -lookup_decl_in_outer_ctx (tree decl, omp_context *ctx)
> +lookup_decl_in_outer_ctx (tree decl, omp_context *ctx,
> +                       bool skip_hostdata)
>  {
>    tree t;
>    omp_context *up;
>  
>    for (up = ctx->outer, t = NULL; up && t == NULL; up = up->outer)
> -    t = maybe_lookup_decl (decl, up);
> +    {
> +      if (skip_hostdata
> +       && gimple_code (up->stmt) == GIMPLE_OMP_TARGET
> +       && gimple_omp_target_kind (up->stmt)
> +          == GF_OMP_TARGET_KIND_OACC_HOST_DATA)
> +     continue;
> +
> +      t = maybe_lookup_decl (decl, up);
> +    }
>  
>    gcc_assert (!ctx->is_nested || t || is_global_var (decl));
>  
> @@ -3959,13 +3972,22 @@ lookup_decl_in_outer_ctx (tree decl, omp_context *ctx)
>     in outer contexts.  */
>  
>  static tree
> -maybe_lookup_decl_in_outer_ctx (tree decl, omp_context *ctx)
> +maybe_lookup_decl_in_outer_ctx (tree decl, omp_context *ctx,
> +                             bool skip_hostdata)
>  {
>    tree t = NULL;
>    omp_context *up;
>  
>    for (up = ctx->outer, t = NULL; up && t == NULL; up = up->outer)
> -    t = maybe_lookup_decl (decl, up);
> +    {
> +      if (skip_hostdata
> +       && gimple_code (up->stmt) == GIMPLE_OMP_TARGET
> +       && gimple_omp_target_kind (up->stmt)
> +          == GF_OMP_TARGET_KIND_OACC_HOST_DATA)
> +     continue;
> +
> +      t = maybe_lookup_decl (decl, up);
> +    }
>  
>    return t ? t : decl;
>  }
> @@ -12499,6 +12521,7 @@ expand_omp_target (struct omp_region *region)
>        break;
>      case GF_OMP_TARGET_KIND_DATA:
>      case GF_OMP_TARGET_KIND_OACC_DATA:
> +    case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
>        data_region = true;
>        break;
>      default:
> @@ -12742,6 +12765,9 @@ expand_omp_target (struct omp_region *region)
>      case GF_OMP_TARGET_KIND_OACC_DECLARE:
>        start_ix = BUILT_IN_GOACC_DECLARE;
>        break;
> +    case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
> +      start_ix = BUILT_IN_GOACC_HOST_DATA;
> +      break;
>      default:
>        gcc_unreachable ();
>      }
> @@ -12866,6 +12892,7 @@ expand_omp_target (struct omp_region *region)
>      case BUILT_IN_GOACC_DATA_START:
>      case BUILT_IN_GOACC_DECLARE:
>      case BUILT_IN_GOMP_TARGET_DATA:
> +    case BUILT_IN_GOACC_HOST_DATA:
>        break;
>      case BUILT_IN_GOMP_TARGET:
>      case BUILT_IN_GOMP_TARGET_UPDATE:
> @@ -13173,6 +13200,7 @@ build_omp_regions_1 (basic_block bb, struct 
> omp_region *parent,
>               case GF_OMP_TARGET_KIND_OACC_PARALLEL:
>               case GF_OMP_TARGET_KIND_OACC_KERNELS:
>               case GF_OMP_TARGET_KIND_OACC_DATA:
> +             case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
>                 break;
>               case GF_OMP_TARGET_KIND_UPDATE:
>               case GF_OMP_TARGET_KIND_ENTER_DATA:
> @@ -14972,6 +15000,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
> omp_context *ctx)
>        break;
>      case GF_OMP_TARGET_KIND_DATA:
>      case GF_OMP_TARGET_KIND_OACC_DATA:
> +    case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
>        data_region = true;
>        break;
>      default:
> @@ -15079,7 +15108,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
> omp_context *ctx)
>         {
>           if (TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
>             {
> -             if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx))
> +             if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx,
> +                                                                true))
>                   && varpool_node::get_create (var)->offloadable)
>                 continue;
>  
> @@ -15178,6 +15208,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
> omp_context *ctx)
>         }
>       break;
>  
> +      case OMP_CLAUSE_USE_DEVICE:
>        case OMP_CLAUSE_USE_DEVICE_PTR:
>        case OMP_CLAUSE_IS_DEVICE_PTR:
>       var = OMP_CLAUSE_DECL (c);
> @@ -15316,7 +15347,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
> omp_context *ctx)
>             talign = DECL_ALIGN_UNIT (ovar);
>           if (nc)
>             {
> -             var = lookup_decl_in_outer_ctx (ovar, ctx);
> +             var = lookup_decl_in_outer_ctx (ovar, ctx, true);
>               x = build_sender_ref (ovar, ctx);
>  
>               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
> @@ -15563,12 +15594,14 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
> omp_context *ctx)
>                                   build_int_cstu (tkind_type, tkind));
>           break;
>  
> +       case OMP_CLAUSE_USE_DEVICE:
>         case OMP_CLAUSE_USE_DEVICE_PTR:
>         case OMP_CLAUSE_IS_DEVICE_PTR:
>           ovar = OMP_CLAUSE_DECL (c);
>           var = lookup_decl_in_outer_ctx (ovar, ctx);
>           x = build_sender_ref (ovar, ctx);
> -         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR)
> +         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
> +             || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE)
>             tkind = GOMP_MAP_USE_DEVICE_PTR;
>           else
>             tkind = GOMP_MAP_FIRSTPRIVATE_INT;
> @@ -15771,10 +15804,12 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
> omp_context *ctx)
>                                    gimple_build_assign (new_var, x));
>             }
>           break;
> +       case OMP_CLAUSE_USE_DEVICE:
>         case OMP_CLAUSE_USE_DEVICE_PTR:
>         case OMP_CLAUSE_IS_DEVICE_PTR:
>           var = OMP_CLAUSE_DECL (c);
> -         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR)
> +         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
> +             || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE)
>             x = build_sender_ref (var, ctx);
>           else
>             x = build_receiver_ref (var, false, ctx);
> @@ -16761,6 +16796,7 @@ make_gimple_omp_edges (basic_block bb, struct 
> omp_region **region,
>       case GF_OMP_TARGET_KIND_OACC_PARALLEL:
>       case GF_OMP_TARGET_KIND_OACC_KERNELS:
>       case GF_OMP_TARGET_KIND_OACC_DATA:
> +     case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
>         break;
>       case GF_OMP_TARGET_KIND_UPDATE:
>       case GF_OMP_TARGET_KIND_ENTER_DATA:

        Jakub

Reply via email to