public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ilya Verbin <iverbin@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Kirill Yukhin <kirill.yukhin@gmail.com>
Subject: Re: [gomp4.1] Handle new form of #pragma omp declare target
Date: Mon, 02 Nov 2015 16:54:00 -0000	[thread overview]
Message-ID: <20151102165417.GA30423@msticlxl57.ims.intel.com> (raw)
In-Reply-To: <20151030191225.GG478@tucnak.redhat.com>

On Fri, Oct 30, 2015 at 20:12:25 +0100, Jakub Jelinek wrote:
> On Fri, Oct 30, 2015 at 08:44:07PM +0300, Ilya Verbin wrote:
> > On Wed, Oct 28, 2015 at 00:11:03 +0300, Ilya Verbin wrote:
> > > On Fri, Jul 17, 2015 at 15:05:59 +0200, Jakub Jelinek wrote:
> > > > As the testcases show, #pragma omp declare target has now a new form (well,
> > > > two; with some issues on it pending), where it is used just as a single
> > > > declarative directive rather than a pair of them and allows marking
> > > > vars and functions by name as "omp declare target" vars/functions (which the
> > > > middle-end etc. already handles),
> > > 
> > > There is an issue - such variables are not added to the offloading tables,
> > > because when varpool_node::get_create is called for the first time, the variable
> > > doesn't yet have "omp declare target" attribute, and when it's called for the
> > > second time, it just returns existing node.  Functions also aren't marked as
> > > offloadable.  I tried to fix this by moving the code from
> > > varpool_node::get_create to varpool_node::finalize_decl, but it helped only C,
> > > but doesn't fix C++.  Therefore, I decided to iterate through all functions and
> > > variables, like in the patch bellow.  But it doesn't work for static vars,
> > > declared inside functions, because they do not appear in symtab :(
> > 
> > Ping?  Where should I set node->offloadable for "omp declare target to (list)"
> > functions, global and static vars?
> 
> Perhaps already somewhere in the FEs?  I mean, when the varpool node is
> created after the decl has that attribute, it already should set offsetable
> itself, so perhaps when adding the attribute check if corresponding varpool
> node exists already (but don't create it) and if yes, set offloadable?

Here is the patch.
make check RUNTESTFLAGS=gomp.exp and check-target-libgomp passed.
OK for gomp-4_5-branch?


gcc/c/
	* c-parser.c: Include context.h.
	(c_parser_omp_declare_target): If decl has "omp declare target" or
	"omp declare target link" attribute, and cgraph or varpool node already
	exists, then set corresponding flags.
gcc/cp/
	* parser.c: Include context.h.
	(cp_parser_omp_declare_target): If decl has "omp declare target" or
	"omp declare target link" attribute, and cgraph or varpool node already
	exists, then set corresponding flags.
libgomp/
	* testsuite/libgomp.c++/target-13.C: Add global variable with "omp
	declare target (<list>)" directive, use it in foo.
	* testsuite/libgomp.c/target-28.c: Likewise.


diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a169457..049417c 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -67,6 +67,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gomp-constants.h"
 #include "c-family/c-indentation.h"
 #include "gimple-expr.h"
+#include "context.h"
 
 \f
 /* Initialization routine for this file.  */
@@ -15600,7 +15601,22 @@ c_parser_omp_declare_target (c_parser *parser)
 	  continue;
 	}
       if (!at1)
-	DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+	{
+	  symtab_node *node = symtab_node::get (t);
+	  DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+	  if (node != NULL)
+	    {
+	      node->offloadable = 1;
+#ifdef ENABLE_OFFLOADING
+	      g->have_offload = true;
+	      if (is_a <varpool_node *> (node))
+		{
+		  vec_safe_push (offload_vars, t);
+		  node->force_output = 1;
+		}
+#endif
+	    }
+	}
     }
 }
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a374e6c..de77a4b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "omp-low.h"
 #include "gomp-constants.h"
 #include "c-family/c-indentation.h"
+#include "context.h"
 
 \f
 /* The lexer.  */
@@ -34773,7 +34774,22 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok)
 	  continue;
 	}
       if (!at1)
-	DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+	{
+	  symtab_node *node = symtab_node::get (t);
+	  DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+	  if (node != NULL)
+	    {
+	      node->offloadable = 1;
+#ifdef ENABLE_OFFLOADING
+	      g->have_offload = true;
+	      if (is_a <varpool_node *> (node))
+		{
+		  vec_safe_push (offload_vars, t);
+		  node->force_output = 1;
+		}
+#endif
+	    }
+	}
     }
 }
 
diff --git a/libgomp/testsuite/libgomp.c++/target-13.C b/libgomp/testsuite/libgomp.c++/target-13.C
index 376672d..5279ac0 100644
--- a/libgomp/testsuite/libgomp.c++/target-13.C
+++ b/libgomp/testsuite/libgomp.c++/target-13.C
@@ -1,11 +1,14 @@
 extern "C" void abort (void);
 
+int g;
+#pragma omp declare target (g)
+
 #pragma omp declare target
 int
 foo (void)
 {
   static int s;
-  return ++s;
+  return ++s + g;
 }
 #pragma omp end declare target
 
diff --git a/libgomp/testsuite/libgomp.c/target-28.c b/libgomp/testsuite/libgomp.c/target-28.c
index c9a2999..96e9e05 100644
--- a/libgomp/testsuite/libgomp.c/target-28.c
+++ b/libgomp/testsuite/libgomp.c/target-28.c
@@ -1,11 +1,14 @@
 extern void abort (void);
 
+int g;
+#pragma omp declare target (g)
+
 #pragma omp declare target
 int
 foo (void)
 {
   static int s;
-  return ++s;
+  return ++s + g;
 }
 #pragma omp end declare target
 

  -- Ilya

  reply	other threads:[~2015-11-02 16:54 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-17 13:43 Jakub Jelinek
2015-07-17 15:48 ` James Norris
2015-10-26 18:45 ` Ilya Verbin
2015-10-26 19:11   ` Jakub Jelinek
2015-10-26 19:49     ` Ilya Verbin
2015-10-26 19:55       ` Jakub Jelinek
2015-11-16 15:41         ` [gomp4.5] Handle #pragma omp declare target link Ilya Verbin
2015-11-19 15:31           ` Jakub Jelinek
2015-11-27 16:51             ` Ilya Verbin
2015-11-30 12:08               ` Jakub Jelinek
2015-11-30 20:42                 ` Ilya Verbin
2015-11-30 20:55                   ` Jakub Jelinek
2015-11-30 21:38                     ` Ilya Verbin
2015-12-01  8:18                       ` Jakub Jelinek
2015-12-01  8:48                         ` Ilya Verbin
2015-12-01 13:16                           ` Jakub Jelinek
2015-12-01 17:30                             ` Ilya Verbin
2015-12-01 19:05                               ` Jakub Jelinek
2015-12-08 14:46                                 ` Ilya Verbin
2015-12-11 17:27                                   ` Jakub Jelinek
2015-12-11 17:46                                     ` Ilya Verbin
2015-12-14 16:48                                     ` Ilya Verbin
2015-12-16 12:30                                       ` gomp_target_fini (was: [gomp4.5] Handle #pragma omp declare target link) Thomas Schwinge
2015-12-23 11:05                                         ` gomp_target_fini Thomas Schwinge
2016-01-11 10:40                                           ` gomp_target_fini Thomas Schwinge
2016-01-21  6:17                                             ` gomp_target_fini Thomas Schwinge
2016-01-21 15:24                                         ` gomp_target_fini Bernd Schmidt
2016-01-22 10:16                                           ` gomp_target_fini Jakub Jelinek
2016-01-25 18:23                                             ` gomp_target_fini Mike Stump
2016-04-19 14:01                                             ` gomp_target_fini Thomas Schwinge
2016-04-19 14:04                                               ` gomp_target_fini Jakub Jelinek
2016-04-21 13:43                                                 ` gomp_target_fini Alexander Monakov
2016-04-21 15:38                                                   ` gomp_target_fini Thomas Schwinge
2016-04-19 15:23                                               ` gomp_target_fini Alexander Monakov
2015-12-14 17:18                     ` [gomp4.5] Handle #pragma omp declare target link Ilya Verbin
2015-12-15  8:42                       ` Jakub Jelinek
2015-12-16 16:21                       ` Thomas Schwinge
2016-01-07 18:57                         ` [gomp4] Fix use of declare'd vars by routine procedures James Norris
2016-01-11 11:55                           ` Thomas Schwinge
2016-01-11 15:38                             ` James Norris
2019-06-26 16:23                       ` [gomp4.5] Handle #pragma omp declare target link Thomas Schwinge
2015-10-27 21:15 ` [gomp4.1] Handle new form of #pragma omp declare target Ilya Verbin
2015-10-30 17:48   ` Ilya Verbin
2015-10-30 19:23     ` Jakub Jelinek
2015-11-02 16:54       ` Ilya Verbin [this message]
2015-11-02 18:01         ` Jakub Jelinek
2015-11-23 11:33 ` Thomas Schwinge
2015-11-23 11:41   ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151102165417.GA30423@msticlxl57.ims.intel.com \
    --to=iverbin@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=kirill.yukhin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).