]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix up declare target handling for vars with DECL_LOCAL_DECL_ALIAS [PR102640]
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Oct 2021 11:30:26 +0000 (13:30 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 8 Oct 2021 11:30:26 +0000 (13:30 +0200)
The introduction of DECL_LOCAL_DECL_ALIAS and push_local_extern_decl_alias
in r11-3699-g4e62aca0e0520e4ed2532f2d8153581190621c1a broke the following
testcase.  The following patch fixes it by treating similarly not just
the variable to or link clause is put on, but also its DECL_LOCAL_DECL_ALIAS
if any.  If it hasn't been created yet, when it is created it will copy
attributes and therefore should get it for free, and as it is an extern,
nothing more than attributes is needed for it.

2021-10-08  Jakub Jelinek  <jakub@redhat.com>

PR c++/102640
gcc/cp/
* parser.c (handle_omp_declare_target_clause): New function.
(cp_parser_omp_declare_target): Use it.
gcc/testsuite/
* c-c++-common/gomp/pr102640.c: New test.

(cherry picked from commit db3d7270b42fe27fb05664c4fdf524ab7ad13a75)

gcc/c-family/ChangeLog.omp
gcc/cp/ChangeLog.omp
gcc/cp/parser.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/pr102640.c [new file with mode: 0644]

index afb871f6d82a13f365aa2c78160c15282de3707f..4d19a6e56c7c0ae53c7dadc873b511eda01a05d5 100644 (file)
@@ -1,3 +1,14 @@
+2021-10-06  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-10-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/102571
+       * c-omp.c (c_finish_omp_atomic): Optimize the case where type has
+       padding, but the non-padding bits are contiguous set of bytes
+       by adjusting the memcmp call arguments instead of emitting
+       __builtin_clear_padding and then comparing all the type's bytes.
+
 2021-10-01  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index 06b5dc933026b0443918cfc07253cd165e54c3be..b5b92bc6a1cca5502f9fbb8497449c4f309494d8 100644 (file)
@@ -1,3 +1,12 @@
+2021-10-08  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-10-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/102640
+       * parser.c (handle_omp_declare_target_clause): New function.
+       (cp_parser_omp_declare_target): Use it.
+
 2021-10-01  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index 954f85d4b2d5227a28ca70407bc6ed65a3166f84..6694349adb77213884bf4b71f417fb9b401975d0 100644 (file)
@@ -45241,6 +45241,71 @@ cp_parser_late_parsing_omp_declare_simd (cp_parser *parser, tree attrs)
   return attrs;
 }
 
+/* Helper for cp_parser_omp_declare_target, handle one to or link clause
+   on #pragma omp declare target.  Return false if errors were reported.  */
+
+static bool
+handle_omp_declare_target_clause (tree c, tree t, int device_type)
+{
+  tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
+  tree at2 = lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (t));
+  tree id;
+  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
+    {
+      id = get_identifier ("omp declare target link");
+      std::swap (at1, at2);
+    }
+  else
+    id = get_identifier ("omp declare target");
+  if (at2)
+    {
+      error_at (OMP_CLAUSE_LOCATION (c),
+               "%qD specified both in declare target %<link%> and %<to%>"
+               " clauses", t);
+      return false;
+    }
+  if (!at1)
+    {
+      DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+      if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
+       return true;
+
+      symtab_node *node = symtab_node::get (t);
+      if (node != NULL)
+       {
+         node->offloadable = 1;
+         if (ENABLE_OFFLOADING)
+           {
+             g->have_offload = true;
+             if (is_a <varpool_node *> (node))
+               vec_safe_push (offload_vars, t);
+           }
+       }
+    }
+  if (TREE_CODE (t) != FUNCTION_DECL)
+    return true;
+  if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0)
+    {
+      tree at3 = lookup_attribute ("omp declare target host",
+                                  DECL_ATTRIBUTES (t));
+      if (at3 == NULL_TREE)
+       {
+         id = get_identifier ("omp declare target host");
+         DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+       }
+    }
+  if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0)
+    {
+      tree at3 = lookup_attribute ("omp declare target nohost",
+                                  DECL_ATTRIBUTES (t));
+      if (at3 == NULL_TREE)
+       {
+         id = get_identifier ("omp declare target nohost");
+         DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+       }
+    }
+  return true;
+}
 
 /* OpenMP 4.0:
    # pragma omp declare target new-line
@@ -45293,67 +45358,16 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok)
     {
       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE)
        continue;
-      tree t = OMP_CLAUSE_DECL (c), id;
-      tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
-      tree at2 = lookup_attribute ("omp declare target link",
-                                  DECL_ATTRIBUTES (t));
+      tree t = OMP_CLAUSE_DECL (c);
       only_device_type = false;
-      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
-       {
-         id = get_identifier ("omp declare target link");
-         std::swap (at1, at2);
-       }
-      else
-       id = get_identifier ("omp declare target");
-      if (at2)
-       {
-         error_at (OMP_CLAUSE_LOCATION (c),
-                   "%qD specified both in declare target %<link%> and %<to%>"
-                   " clauses", t);
-         continue;
-       }
-      if (!at1)
-       {
-         DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
-         if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
-           continue;
-
-         symtab_node *node = symtab_node::get (t);
-         if (node != NULL)
-           {
-             node->offloadable = 1;
-             if (ENABLE_OFFLOADING)
-               {
-                 g->have_offload = true;
-                 if (is_a <varpool_node *> (node))
-                   vec_safe_push (offload_vars, t);
-               }
-           }
-       }
-      if (TREE_CODE (t) != FUNCTION_DECL)
+      if (!handle_omp_declare_target_clause (c, t, device_type))
        continue;
-      if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0)
-       {
-         tree at3 = lookup_attribute ("omp declare target host",
-                                      DECL_ATTRIBUTES (t));
-         if (at3 == NULL_TREE)
-           {
-             id = get_identifier ("omp declare target host");
-             DECL_ATTRIBUTES (t)
-               = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
-           }
-       }
-      if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0)
-       {
-         tree at3 = lookup_attribute ("omp declare target nohost",
-                                      DECL_ATTRIBUTES (t));
-         if (at3 == NULL_TREE)
-           {
-             id = get_identifier ("omp declare target nohost");
-             DECL_ATTRIBUTES (t)
-               = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
-           }
-       }
+      if (VAR_OR_FUNCTION_DECL_P (t)
+         && DECL_LOCAL_DECL_P (t)
+         && DECL_LANG_SPECIFIC (t)
+         && DECL_LOCAL_DECL_ALIAS (t))
+       handle_omp_declare_target_clause (c, DECL_LOCAL_DECL_ALIAS (t),
+                                         device_type);
     }
   if (device_type && only_device_type)
     warning_at (OMP_CLAUSE_LOCATION (clauses), 0,
index 1027065ddf75fd9813e313c74d9ec85ec2631155..e806233da0a0c0cdc1db1c4e2a03ee56f7e117a6 100644 (file)
@@ -1,3 +1,11 @@
+2021-10-08  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-10-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/102640
+       * c-c++-common/gomp/pr102640.c: New test.
+
 2021-10-06  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
diff --git a/gcc/testsuite/c-c++-common/gomp/pr102640.c b/gcc/testsuite/c-c++-common/gomp/pr102640.c
new file mode 100644 (file)
index 0000000..00ebab9
--- /dev/null
@@ -0,0 +1,44 @@
+/* PR c++/102640 */
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple -fdump-tree-omplower" } */
+/* Verify var[123] are mapped without any copying, because they are
+   mentioned in declare target directive to clauses.  */
+/* { dg-final { scan-tree-dump-not "firstprivate\\\(var\[123]\\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump-not ".omp_data_arr.\[0-9]*.var" "omplower" } } */
+/* { dg-final { scan-tree-dump-not ".omp_data_i->var" "omplower" } } */
+
+void
+foo (void)
+{
+  extern int var1;
+  #pragma omp declare target to (var1)
+
+  #pragma omp target
+  var1++;
+}
+
+int
+bar (int x)
+{
+  extern int var2;
+  #pragma omp declare target to (var2)
+  if (x)
+    return var2;
+  #pragma omp target
+  var2++;
+  return -1;
+}
+#pragma omp declare target to (bar)
+
+#pragma omp declare target
+int
+baz (int x)
+{
+  extern int var3;
+  if (x)
+    return var3;
+  #pragma omp target
+  var3++;
+  return -1;
+}
+#pragma omp end declare target