On Wed, 21 Oct 2015, Jakub Jelinek wrote: > > At the moment the attribute setting logic in omp-low.c is such that if a > > function that should be present in target code does not already have 'omp > > declare target' attribute, it receives 'omp target entrypoint'. That is > > wasteful: clearly not all user-declared target functions will be target > > region > > entry points in OpenMP. > > > > The motivating example for this change is OpenMP parallel target regions. > > The > > 'parallel' part is outlined into its own function. We don't want that > > function be an 'entrypoint' on PTX (but only as a matter of optimality > > rather > > than correctness). > > > > * omp-low.c (create_omp_child_function): Set "omp target entrypoint" > > or "omp declare target" attribute based on is_gimple_omp_offloaded. > > This is principally ok, but you want to change it for 01/14. > After that I think it is ready for trunk.
As you suggested in patch 01/14, I'll want to use different attributes to distinguish between OpenACC and OpenMP entrypoints. I've tried your suggestion "acc target entrypoint", and unfortunately it doesn't work because ipa-icf does: sem_function::parse (cgraph_node *node, bitmap_obstack *stack) { ... if (lookup_attribute_by_prefix ("omp ", DECL_ATTRIBUTES (node->decl)) != NULL) return NULL; ... } so changing the prefix affects code generation. I don't see why IPA-ICF needs that (it's there from when the file was added to trunk, and there's no comment). I went with "omp acc target entrypoint" instead, as below. OK? (for trunk?) Thanks. Alexander omp-low: set more precise attributes on offloaded functions At the moment the attribute setting logic in omp-low.c is such that if a function that should be present in target code does not already have 'omp declare target' attribute, it receives 'omp target entrypoint'. However, that is inaccurate for OpenMP: functions outlined for e.g. omp-parallel regions do not have 'omp declare target' attribute, but they cannot be entrypoints either. Detect entrypoints using 'is_gimple_omp_offloaded'. Additionally, distinguish between OpenACC and OpenMP entrypoints, and use 'omp acc target entrypoint' for the former. * omp-low.c (create_omp_child_function): Set "omp target entrypoint", "omp acc target entrypoint" or "omp declare target" attribute based on is_gimple_omp_offloaded and is_gimple_omp_oacc. * config/nvptx/nvptx.c (write_as_kernel): Test OpenACC-specific attribute "omp acc target entrypoint". Add a comment about the OpenMP attribute handling. diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index 21c59ef..ac021fc 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -402,7 +402,10 @@ static bool write_as_kernel (tree attrs) { return (lookup_attribute ("kernel", attrs) != NULL_TREE - || lookup_attribute ("omp target entrypoint", attrs) != NULL_TREE); + || lookup_attribute ("omp acc target entrypoint", attrs) != NULL_TREE); + /* Ignore "omp target entrypoint" here: OpenMP target region functions are + called from gomp_nvptx_main. The corresponding kernel entry is emitted + from write_omp_entry. */ } /* Write a function decl for DECL to S, where NAME is the name to be used. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 06b4a5e..696889d 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -2245,9 +2245,16 @@ create_omp_child_function (omp_context *ctx, bool task_copy) if (cgraph_node::get_create (decl)->offloadable && !lookup_attribute ("omp declare target", DECL_ATTRIBUTES (current_function_decl))) - DECL_ATTRIBUTES (decl) - = tree_cons (get_identifier ("omp target entrypoint"), - NULL_TREE, DECL_ATTRIBUTES (decl)); + { + const char *target_attr = (is_gimple_omp_offloaded (ctx->stmt) + ? (is_gimple_omp_oacc (ctx->stmt) + ? "omp acc target entrypoint" + : "omp target entrypoint") + : "omp declare target"); + DECL_ATTRIBUTES (decl) + = tree_cons (get_identifier (target_attr), + NULL_TREE, DECL_ATTRIBUTES (decl)); + } t = build_decl (DECL_SOURCE_LOCATION (decl), RESULT_DECL, NULL_TREE, void_type_node);