On Mon, May 23, 2016 at 07:15:48PM +0300, Alexander Monakov wrote: > (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?)
Sure. > 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?) I'll ask on the lang committee. That said, for external declarations of variables, all we care is that if any external declaration is specified in to/link clause on declare target directive, then the definition (for common vars all the definitions I guess) are also specified in the same kind of clause. Having the externs specified in omp declare target to is important for code generation, we need to know that whether the vars should be mapped implicitly on target constructs and remapped in the target construct bodies, or whether the actual vars should be used in the regions. Thus, > So from that perspective it's undesirable to have 'omp declare target' on > declarations that don't define anything. is just wrong, we at least need the symbol_table::offloadable bit set. About g->head_offload and offload_vars, I guess it is fine not to set those for externs but we need to arrange that to be set when we actually define it when it has been previously extern, and we need some sensible handling of the case where the var is only declared extern and omp declare target, used in some target region, but not actually defined anywhere in the same shared library or executable. Jakub