On Fri, 20 May 2016, Jakub Jelinek wrote: > but that made me think on what handling do we want for the > "omp declare target" DECL_EXTERNAL vars. [snip] > In the C/C++ FEs, we set not just node->offloadable, but also for > ENABLE_OFFLOADING g->have_offload and offload_vars too. Wonder if that > means we register even non-local vars, that would be IMHO a bug.
(it's unclear to me what you mean by 'non-local vars' here, from the context it looks like it's 'variables with an external declaration and no definition in the current TU'; correct?) Looking at the OpenMP 4.5 spec, there's a requirement that [2.10.6 declare target directive, Restrictions, C/C++] * All declarations and definitions for a function must have a declare target directive if one is specified for any of them. Otherwise, the result is unspecified. (why are variables exempted?) A natural way to conform to that requirement is to have a '#pragma omp declare target' in the header file declaring the offloaded function. But that means every TU that includes that header will have g->have_offload set, even if otherwise it doesn't touch OpenMP at all. So from that perspective it's undesirable to have 'omp declare target' on declarations that don't define anything. > On the other side, we need to watch for an extern declaration > of a VAR_DECL marked for offloading and only later on locally defined, > in that case if we haven't set g->have_offload and added entry to > offload_vars, we'd need to do it when merging the extern decl with the > definition. Yes, but I wonder if setting g->have_offload etc. in the front-ends is the right thing to do at all. Shouldn't frontends simply set 'omp declare target' and leave the rest to omp-low? Hope that's constructive. Alexander