OpenMP: Prepare omp-* for ancestor:1 handling gcc/ChangeLog: * omp-expand.cc (expand_omp_target): Set device to GOMP_DEVICE_HOST_FALLBACK for ancestor. * omp-low.cc (scan_omp_target): Add 'omp target device_ancestor' attribute to generated target-region function for ancestor:1. * omp-offload.cc (pass_omp_target_link::execute): Don't nullify function pointer for ancestor:1. gcc/omp-expand.cc | 6 +++++- gcc/omp-low.cc | 6 ++++++ gcc/omp-offload.cc | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index 1023c56fc3d..dc0a963e9e3 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -10005,7 +10005,11 @@ expand_omp_target (struct omp_region *region) need_device_adjustment = true; device_loc = OMP_CLAUSE_LOCATION (c); if (OMP_CLAUSE_DEVICE_ANCESTOR (c)) - sorry_at (device_loc, "% not yet supported"); + { + device = build_int_cst (integer_type_node, + GOMP_DEVICE_HOST_FALLBACK); + sorry_at (device_loc, "% not yet supported"); + } } else { diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index b9d5529f212..140ef229cc0 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -3094,6 +3094,12 @@ scan_omp_target (gomp_target *stmt, omp_context *outer_ctx) if (offloaded) { create_omp_child_function (ctx, false); + tree c = omp_find_clause (gimple_omp_target_clauses (ctx->stmt), + OMP_CLAUSE_DEVICE); + if (c && OMP_CLAUSE_DEVICE_ANCESTOR (c)) + DECL_ATTRIBUTES (ctx->cb.dst_fn) + = tree_cons (get_identifier ("omp target device_ancestor"), + NULL_TREE, DECL_ATTRIBUTES (ctx->cb.dst_fn)); gimple_omp_target_set_child_fn (stmt, ctx->cb.dst_fn); } diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc index 3a89119371c..a6c108aef30 100644 --- a/gcc/omp-offload.cc +++ b/gcc/omp-offload.cc @@ -2803,6 +2803,15 @@ pass_omp_target_link::execute (function *fun) { if (gimple_call_builtin_p (gsi_stmt (gsi), BUILT_IN_GOMP_TARGET)) { + tree dev = gimple_call_arg (gsi_stmt (gsi), 0); + tree fn = gimple_call_arg (gsi_stmt (gsi), 1); + if (POINTER_TYPE_P (TREE_TYPE (fn))) + fn = TREE_OPERAND (fn, 0); + if (TREE_CODE (dev) == INTEGER_CST + && wi::to_wide (dev) == GOMP_DEVICE_HOST_FALLBACK + && lookup_attribute ("omp target device_ancestor", + DECL_ATTRIBUTES (fn)) != NULL_TREE) + continue; /* ancestor:1 */ /* Nullify the second argument of __builtin_GOMP_target_ext. */ gimple_call_set_arg (gsi_stmt (gsi), 1, null_pointer_node); update_stmt (gsi_stmt (gsi));