From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51208 invoked by alias); 27 Oct 2015 21:11:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 51198 invoked by uid 89); 27 Oct 2015 21:11:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f174.google.com Received: from mail-wi0-f174.google.com (HELO mail-wi0-f174.google.com) (209.85.212.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 27 Oct 2015 21:11:35 +0000 Received: by wicfx6 with SMTP id fx6so177285818wic.1 for ; Tue, 27 Oct 2015 14:11:32 -0700 (PDT) X-Received: by 10.194.189.49 with SMTP id gf17mr34211777wjc.158.1445980292083; Tue, 27 Oct 2015 14:11:32 -0700 (PDT) Received: from msticlxl57.ims.intel.com (jfdmzpr01-ext.jf.intel.com. [134.134.139.70]) by smtp.gmail.com with ESMTPSA id gl9sm46810069wjb.10.2015.10.27.14.11.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Oct 2015 14:11:31 -0700 (PDT) Date: Tue, 27 Oct 2015 21:15:00 -0000 From: Ilya Verbin To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, Kirill Yukhin Subject: Re: [gomp4.1] Handle new form of #pragma omp declare target Message-ID: <20151027211103.GA9097@msticlxl57.ims.intel.com> References: <20150717130559.GI1780@tucnak.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150717130559.GI1780@tucnak.redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg02977.txt.bz2 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 :( diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 1a64d789..0ba04ef 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -511,16 +511,6 @@ cgraph_node::create (tree decl) gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); node->decl = decl; - - if ((flag_openacc || flag_openmp) - && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))) - { - node->offloadable = 1; -#ifdef ENABLE_OFFLOADING - g->have_offload = true; -#endif - } - node->register_symbol (); if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL) diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 04a4d3f..9ac7b36 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1016,6 +1016,25 @@ analyze_functions (bool first_time) symtab->state = CONSTRUCTION; input_location = UNKNOWN_LOCATION; + /* Process offloadable functions and variables. */ + if (first_time && (flag_openacc || flag_openmp)) + FOR_EACH_SYMBOL (node) + if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (node->decl))) + { + node->offloadable = 1; + +#ifdef ENABLE_OFFLOADING + g->have_offload = true; + + if (TREE_CODE (node->decl) == VAR_DECL && !DECL_EXTERNAL (node->decl)) + { + if (!in_lto_p) + vec_safe_push (offload_vars, node->decl); + node->force_output = 1; + } +#endif + } + /* Ugly, but the fixup can not happen at a time same body alias is created; C++ FE is confused about the COMDAT groups being right. */ if (symtab->cpp_implicit_aliases_done) diff --git a/gcc/varpool.c b/gcc/varpool.c index 7d11e20..077dd40 100644 --- a/gcc/varpool.c +++ b/gcc/varpool.c @@ -154,19 +154,6 @@ varpool_node::get_create (tree decl) node = varpool_node::create_empty (); node->decl = decl; - - if ((flag_openacc || flag_openmp) && !DECL_EXTERNAL (decl) - && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))) - { - node->offloadable = 1; -#ifdef ENABLE_OFFLOADING - g->have_offload = true; - if (!in_lto_p) - vec_safe_push (offload_vars, decl); - node->force_output = 1; -#endif - } - node->register_symbol (); return node; } 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