+2020-05-14 Jakub Jelinek <jakub@redhat.com>
+
+ * function.h (struct function): Add has_omp_target bit.
+ * omp-offload.c (omp_discover_declare_target_fn_r): New function,
+ old renamed to ...
+ (omp_discover_declare_target_tgt_fn_r): ... this.
+ (omp_discover_declare_target_var_r): Call
+ omp_discover_declare_target_tgt_fn_r instead of
+ omp_discover_declare_target_fn_r.
+ (omp_discover_implicit_declare_target): Also queue functions with
+ has_omp_target bit set, for those walk with
+ omp_discover_declare_target_fn_r, for declare target to functions
+ walk with omp_discover_declare_target_tgt_fn_r.
+
2020-05-14 Uroš Bizjak <ubizjak@gmail.com>
PR target/95046
declare target to. */
static tree
-omp_discover_declare_target_fn_r (tree *tp, int *walk_subtrees, void *data)
+omp_discover_declare_target_tgt_fn_r (tree *tp, int *walk_subtrees, void *data)
{
if (TREE_CODE (*tp) == FUNCTION_DECL
&& !omp_declare_target_fn_p (*tp)
return NULL_TREE;
}
+/* Similarly, but ignore references outside of OMP_TARGET regions. */
+
+static tree
+omp_discover_declare_target_fn_r (tree *tp, int *walk_subtrees, void *data)
+{
+ if (TREE_CODE (*tp) == OMP_TARGET)
+ {
+ /* And not OMP_DEVICE_ANCESTOR. */
+ walk_tree_without_duplicates (&OMP_TARGET_BODY (*tp),
+ omp_discover_declare_target_tgt_fn_r,
+ data);
+ *walk_subtrees = 0;
+ }
+ else if (TYPE_P (*tp))
+ *walk_subtrees = 0;
+ return NULL_TREE;
+}
+
/* Helper function for omp_discover_implicit_declare_target, called through
walk_tree. Mark referenced FUNCTION_DECLs implicitly as
declare target to. */
omp_discover_declare_target_var_r (tree *tp, int *walk_subtrees, void *data)
{
if (TREE_CODE (*tp) == FUNCTION_DECL)
- return omp_discover_declare_target_fn_r (tp, walk_subtrees, data);
+ return omp_discover_declare_target_tgt_fn_r (tp, walk_subtrees, data);
else if (VAR_P (*tp)
&& is_global_var (*tp)
&& !omp_declare_target_var_p (*tp))
auto_vec<tree> worklist;
FOR_EACH_DEFINED_FUNCTION (node)
- if (omp_declare_target_fn_p (node->decl) && DECL_SAVED_TREE (node->decl))
- worklist.safe_push (node->decl);
+ if (DECL_SAVED_TREE (node->decl))
+ {
+ if (omp_declare_target_fn_p (node->decl))
+ worklist.safe_push (node->decl);
+ else if (DECL_STRUCT_FUNCTION (node->decl)
+ && DECL_STRUCT_FUNCTION (node->decl)->has_omp_target)
+ worklist.safe_push (node->decl);
+ }
FOR_EACH_STATIC_INITIALIZER (vnode)
if (omp_declare_target_var_p (vnode->decl))
worklist.safe_push (vnode->decl);
while (!worklist.is_empty ())
{
tree decl = worklist.pop ();
- if (TREE_CODE (decl) == FUNCTION_DECL)
+ if (VAR_P (decl))
+ walk_tree_without_duplicates (&DECL_INITIAL (decl),
+ omp_discover_declare_target_var_r,
+ &worklist);
+ else if (omp_declare_target_fn_p (decl))
walk_tree_without_duplicates (&DECL_SAVED_TREE (decl),
- omp_discover_declare_target_fn_r,
+ omp_discover_declare_target_tgt_fn_r,
&worklist);
else
- walk_tree_without_duplicates (&DECL_INITIAL (decl),
- omp_discover_declare_target_var_r,
+ walk_tree_without_duplicates (&DECL_SAVED_TREE (decl),
+ omp_discover_declare_target_fn_r,
&worklist);
}
}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0" } */
+
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+volatile int v;
+#pragma omp declare target to (v)
+typedef void (*fnp1) (void);
+typedef fnp1 (*fnp2) (void);
+void f1 (void) { v++; }
+void f2 (void) { v += 4; }
+void f3 (void) { v += 16; f1 (); }
+fnp1 f4 (void) { v += 64; return f2; }
+int a = 1;
+int *b = &a;
+int **c = &b;
+fnp2 f5 (void) { f3 (); return f4; }
+#pragma omp declare target to (c)
+
+int
+main ()
+{
+ int err = 0;
+ #pragma omp target map(from:err)
+ {
+ volatile int xa;
+ int *volatile xb;
+ int **volatile xc;
+ fnp2 xd;
+ fnp1 xe;
+ err = 0;
+ xa = a;
+ err |= xa != 1;
+ xb = b;
+ err |= xb != &a;
+ xc = c;
+ err |= xc != &b;
+ xd = f5 ();
+ err |= v != 17;
+ xe = xd ();
+ err |= v != 81;
+ xe ();
+ err |= v != 85;
+ }
+ if (err)
+ abort ();
+ return 0;
+}