aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-10-25 00:29:09 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2019-10-25 00:29:09 +0200
commit135df52cc3f1ef90092ab02a01c4dabc7fd0ed18 (patch)
tree788a3c845a393f73563f1c4dba757939c85265ff /gcc/gimplify.c
parentf8cb8bcde13df2f2b1a996567c849ec512eec210 (diff)
downloadgcc-135df52cc3f1ef90092ab02a01c4dabc7fd0ed18.zip
gcc-135df52cc3f1ef90092ab02a01c4dabc7fd0ed18.tar.gz
gcc-135df52cc3f1ef90092ab02a01c4dabc7fd0ed18.tar.bz2
gimplify.h (omp_construct_selector_matches): Declare.
* gimplify.h (omp_construct_selector_matches): Declare. * gimplify.c (struct gimplify_omp_ctx): Add code member. (gimplify_call_expr): Call omp_resolve_declare_variant and remap called function if needed for flag_openmp. (gimplify_scan_omp_clauses): Set ctx->code. (omp_construct_selector_matches): New function. * omp-general.h (omp_constructor_traits_to_codes, omp_context_selector_matches, omp_resolve_declare_variant): Declare. * omp-general.c (omp_constructor_traits_to_codes, omp_context_selector_matches, omp_resolve_declare_variant): New functions. c-family/ * c-common.h (c_omp_context_selector_matches): Remove. * c-omp.c (c_omp_context_selector_matches): Remove. * c-attribs.c (c_common_attribute_table): Add "omp declare target {host,nohost,block}" attributes. c/ * c-parser.c (c_finish_omp_declare_variant): Use omp_context_selector_matches instead of c_omp_context_selector_matches. * c-decl.c (c_decl_attributes): Add "omp declare target block" attribute in between declare target and end declare target pragmas. cp/ * decl2.c (cplus_decl_attributes): Add "omp declare target block" attribute in between declare target and end declare target pragmas. testsuite/ * c-c++-common/gomp/declare-variant-8.c: New test. From-SVN: r277427
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r--gcc/gimplify.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 914bb8e..05ae2f1 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -219,6 +219,7 @@ struct gimplify_omp_ctx
location_t location;
enum omp_clause_default_kind default_kind;
enum omp_region_type region_type;
+ enum tree_code code;
bool combined_loop;
bool distribute;
bool target_firstprivatize_array_bases;
@@ -3385,6 +3386,13 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
/* Remember the original function pointer type. */
fnptrtype = TREE_TYPE (CALL_EXPR_FN (*expr_p));
+ if (flag_openmp && fndecl)
+ {
+ tree variant = omp_resolve_declare_variant (fndecl);
+ if (variant != fndecl)
+ CALL_EXPR_FN (*expr_p) = build1 (ADDR_EXPR, fnptrtype, variant);
+ }
+
/* There is a sequence point before the call, so any side effects in
the calling expression must occur before the actual call. Force
gimplify_expr to use an internal post queue. */
@@ -8137,6 +8145,7 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
int nowait = -1;
ctx = new_omp_context (region_type);
+ ctx->code = code;
outer_ctx = ctx->outer_context;
if (code == OMP_TARGET)
{
@@ -10324,6 +10333,99 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
delete_omp_context (ctx);
}
+/* Return 0 if CONSTRUCTS selectors don't match the OpenMP context,
+ -1 if unknown yet (simd is involved, won't be known until vectorization)
+ and positive number if they do, the number is then the number of constructs
+ in the OpenMP context. */
+
+HOST_WIDE_INT
+omp_construct_selector_matches (enum tree_code *constructs, int nconstructs)
+{
+ int matched = 0, cnt = 0;
+ bool simd_seen = false;
+ for (struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; ctx;)
+ {
+ if (((ctx->region_type & ORT_PARALLEL) && ctx->code == OMP_PARALLEL)
+ || ((ctx->region_type & (ORT_TARGET | ORT_IMPLICIT_TARGET | ORT_ACC))
+ == ORT_TARGET && ctx->code == OMP_TARGET)
+ || ((ctx->region_type & ORT_TEAMS) && ctx->code == OMP_TEAMS)
+ || (ctx->region_type == ORT_WORKSHARE && ctx->code == OMP_FOR)
+ || (ctx->region_type == ORT_SIMD
+ && ctx->code == OMP_SIMD
+ && !omp_find_clause (ctx->clauses, OMP_CLAUSE_BIND)))
+ {
+ ++cnt;
+ if (matched < nconstructs && ctx->code == constructs[matched])
+ {
+ if (ctx->code == OMP_SIMD)
+ {
+ if (matched)
+ return 0;
+ simd_seen = true;
+ }
+ ++matched;
+ }
+ if (ctx->code == OMP_TARGET)
+ return matched < nconstructs ? 0 : simd_seen ? -1 : cnt;
+ }
+ else if (ctx->region_type == ORT_WORKSHARE
+ && ctx->code == OMP_LOOP
+ && ctx->outer_context
+ && ctx->outer_context->region_type == ORT_COMBINED_PARALLEL
+ && ctx->outer_context->outer_context
+ && ctx->outer_context->outer_context->code == OMP_LOOP
+ && ctx->outer_context->outer_context->distribute)
+ ctx = ctx->outer_context->outer_context;
+ ctx = ctx->outer_context;
+ }
+ if (cnt == 0
+ && constructs[0] == OMP_SIMD
+ && lookup_attribute ("omp declare simd",
+ DECL_ATTRIBUTES (current_function_decl)))
+ {
+ /* Declare simd is a maybe case, it is supposed to be added only to the
+ omp-simd-clone.c added clones and not to the base function. */
+ gcc_assert (matched == 0);
+ ++cnt;
+ simd_seen = true;
+ if (++matched == nconstructs)
+ return -1;
+ }
+ if (tree attr = lookup_attribute ("omp declare variant variant",
+ DECL_ATTRIBUTES (current_function_decl)))
+ {
+ enum tree_code variant_constructs[5];
+ int variant_nconstructs
+ = omp_constructor_traits_to_codes (TREE_VALUE (attr),
+ variant_constructs);
+ for (int i = 0; i < variant_nconstructs; i++)
+ {
+ ++cnt;
+ if (matched < nconstructs
+ && variant_constructs[i] == constructs[matched])
+ {
+ if (variant_constructs[i] == OMP_SIMD)
+ {
+ if (matched)
+ return 0;
+ simd_seen = true;
+ }
+ ++matched;
+ }
+ }
+ }
+ if (lookup_attribute ("omp declare target block",
+ DECL_ATTRIBUTES (current_function_decl)))
+ {
+ ++cnt;
+ if (matched < nconstructs && constructs[matched] == OMP_TARGET)
+ ++matched;
+ }
+ if (matched == nconstructs)
+ return simd_seen ? -1 : cnt;
+ return 0;
+}
+
/* Gimplify OACC_CACHE. */
static void