return 0;
}
-/* Store the construct selectors as tree codes from last to first.
- CTX is a list of trait selectors, nconstructs must be equal to its
- length, and the array CONSTRUCTS holds the output. */
-
-void
-omp_construct_traits_to_codes (tree ctx, int nconstructs,
- enum tree_code *constructs)
-{
- int i = nconstructs - 1;
-
- /* Order must match the OMP_TRAIT_CONSTRUCT_* enumerators in
- enum omp_ts_code. */
- static enum tree_code code_map[]
- = { OMP_TARGET, OMP_TEAMS, OMP_PARALLEL, OMP_FOR, OMP_SIMD, OMP_DISPATCH };
-
- for (tree ts = ctx; ts; ts = TREE_CHAIN (ts), i--)
- {
- enum omp_ts_code sel = OMP_TS_CODE (ts);
- int j = (int)sel - (int)OMP_TRAIT_CONSTRUCT_TARGET;
- gcc_assert (j >= 0 && (unsigned int) j < ARRAY_SIZE (code_map));
- constructs[i] = code_map[j];
- }
- gcc_assert (i == -1);
-}
-
/* Return true if PROP is possibly present in one of the offloading target's
OpenMP contexts. The format of PROPS string is always offloading target's
name terminated by '\0', followed by properties for that offloading
return true;
}
-#if 0
-/* Return 1 if context selector matches the current OpenMP context, 0
- if it does not and -1 if it is unknown and need to be determined later.
- Some properties can be checked right away during parsing (this routine),
- others need to wait until the whole TU is parsed, others need to wait until
- IPA, others until vectorization. */
-
-int
-omp_context_selector_matches (tree ctx)
-{
- int ret = 1;
- for (tree tss = ctx; tss; tss = TREE_CHAIN (tss))
- {
- enum omp_tss_code set = OMP_TSS_CODE (tss);
- tree selectors = OMP_TSS_TRAIT_SELECTORS (tss);
-
- /* Immediately reject the match if there are any ignored
- selectors present. */
- for (tree ts = selectors; ts; ts = TREE_CHAIN (ts))
- if (OMP_TS_CODE (ts) == OMP_TRAIT_INVALID)
- return 0;
-
- if (set == OMP_TRAIT_SET_CONSTRUCT)
- {
- /* For now, ignore the construct set. While something can be
- determined already during parsing, we don't know until end of TU
- whether additional constructs aren't added through declare variant
- unless "omp declare variant variant" attribute exists already
- (so in most of the cases), and we'd need to maintain set of
- surrounding OpenMP constructs, which is better handled during
- gimplification. */
- if (symtab->state == PARSING)
- {
- ret = -1;
- continue;
- }
-
- int nconstructs = list_length (selectors);
- enum tree_code *constructs = NULL;
- if (nconstructs)
- {
- /* Even though this alloca appears in a loop over selector
- sets, it does not repeatedly grow the stack, because
- there can be only one construct selector set specified.
- This is enforced by omp_check_context_selector. */
- constructs
- = (enum tree_code *) alloca (nconstructs
- * sizeof (enum tree_code));
- omp_construct_traits_to_codes (selectors, nconstructs,
- constructs);
- }
-
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- {
- if (!cfun->after_inlining)
- {
- ret = -1;
- continue;
- }
- int i;
- for (i = 0; i < nconstructs; ++i)
- if (constructs[i] == OMP_SIMD)
- break;
- if (i < nconstructs)
- {
- ret = -1;
- continue;
- }
- /* If there is no simd, assume it is ok after IPA,
- constructs should have been checked before. */
- continue;
- }
-
- int r = omp_construct_selector_matches (constructs, nconstructs,
- NULL);
- if (r == 0)
- return 0;
- if (r == -1)
- ret = -1;
- continue;
- }
- for (tree ts = selectors; ts; ts = TREE_CHAIN (ts))
- {
- enum omp_ts_code sel = OMP_TS_CODE (ts);
- switch (sel)
- {
- case OMP_TRAIT_IMPLEMENTATION_VENDOR:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
- {
- const char *prop = omp_context_name_list_prop (p);
- if (prop == NULL)
- return 0;
- if (!strcmp (prop, "gnu"))
- continue;
- return 0;
- }
- break;
- case OMP_TRAIT_IMPLEMENTATION_EXTENSION:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- /* We don't support any extensions right now. */
- return 0;
- break;
- case OMP_TRAIT_IMPLEMENTATION_ADMO:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- {
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- break;
-
- enum omp_memory_order omo
- = ((enum omp_memory_order)
- (omp_requires_mask
- & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER));
- if (omo == OMP_MEMORY_ORDER_UNSPECIFIED)
- {
- /* We don't know yet, until end of TU. */
- if (symtab->state == PARSING)
- {
- ret = -1;
- break;
- }
- else
- omo = OMP_MEMORY_ORDER_RELAXED;
- }
- tree p = OMP_TS_PROPERTIES (ts);
- const char *prop = IDENTIFIER_POINTER (OMP_TP_NAME (p));
- if (!strcmp (prop, "relaxed")
- && omo != OMP_MEMORY_ORDER_RELAXED)
- return 0;
- else if (!strcmp (prop, "seq_cst")
- && omo != OMP_MEMORY_ORDER_SEQ_CST)
- return 0;
- else if (!strcmp (prop, "acq_rel")
- && omo != OMP_MEMORY_ORDER_ACQ_REL)
- return 0;
- else if (!strcmp (prop, "acquire")
- && omo != OMP_MEMORY_ORDER_ACQUIRE)
- return 0;
- else if (!strcmp (prop, "release")
- && omo != OMP_MEMORY_ORDER_RELEASE)
- return 0;
- }
- break;
- case OMP_TRAIT_DEVICE_ARCH:
- if (set == OMP_TRAIT_SET_DEVICE)
- for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
- {
- const char *arch = omp_context_name_list_prop (p);
- if (arch == NULL)
- return 0;
- int r = 0;
- if (targetm.omp.device_kind_arch_isa != NULL)
- r = targetm.omp.device_kind_arch_isa (omp_device_arch,
- arch);
- if (r == 0 || (r == -1 && symtab->state != PARSING))
- {
- /* If we are or might be in a target region or
- declare target function, need to take into account
- also offloading values. */
- if (!omp_maybe_offloaded ())
- return 0;
- if (ENABLE_OFFLOADING)
- {
- const char *arches = omp_offload_device_arch;
- if (omp_offload_device_kind_arch_isa (arches,
- arch))
- {
- ret = -1;
- continue;
- }
- }
- return 0;
- }
- else if (r == -1)
- ret = -1;
- /* If arch matches on the host, it still might not match
- in the offloading region. */
- else if (omp_maybe_offloaded ())
- ret = -1;
- }
- break;
- case OMP_TRAIT_IMPLEMENTATION_UNIFIED_ADDRESS:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- {
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- break;
-
- if ((omp_requires_mask & OMP_REQUIRES_UNIFIED_ADDRESS) == 0)
- {
- if (symtab->state == PARSING)
- ret = -1;
- else
- return 0;
- }
- }
- break;
- case OMP_TRAIT_IMPLEMENTATION_UNIFIED_SHARED_MEMORY:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- {
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- break;
-
- if ((omp_requires_mask
- & OMP_REQUIRES_UNIFIED_SHARED_MEMORY) == 0)
- {
- if (symtab->state == PARSING)
- ret = -1;
- else
- return 0;
- }
- }
- break;
- case OMP_TRAIT_IMPLEMENTATION_SELF_MAPS:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- {
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- break;
-
- if ((omp_requires_mask
- & OMP_REQUIRES_SELF_MAPS) == 0)
- {
- if (symtab->state == PARSING)
- ret = -1;
- else
- return 0;
- }
- }
- break;
- case OMP_TRAIT_IMPLEMENTATION_DYNAMIC_ALLOCATORS:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- {
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- break;
-
- if ((omp_requires_mask
- & OMP_REQUIRES_DYNAMIC_ALLOCATORS) == 0)
- {
- if (symtab->state == PARSING)
- ret = -1;
- else
- return 0;
- }
- }
- break;
- case OMP_TRAIT_IMPLEMENTATION_REVERSE_OFFLOAD:
- if (set == OMP_TRAIT_SET_IMPLEMENTATION)
- {
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- break;
-
- if ((omp_requires_mask & OMP_REQUIRES_REVERSE_OFFLOAD) == 0)
- {
- if (symtab->state == PARSING)
- ret = -1;
- else
- return 0;
- }
- }
- break;
- case OMP_TRAIT_DEVICE_KIND:
- if (set == OMP_TRAIT_SET_DEVICE)
- for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
- {
- const char *prop = omp_context_name_list_prop (p);
- if (prop == NULL)
- return 0;
- if (!strcmp (prop, "any"))
- continue;
- if (!strcmp (prop, "host"))
- {
-#ifdef ACCEL_COMPILER
- return 0;
-#else
- if (omp_maybe_offloaded ())
- ret = -1;
- continue;
-#endif
- }
- if (!strcmp (prop, "nohost"))
- {
-#ifndef ACCEL_COMPILER
- if (omp_maybe_offloaded ())
- ret = -1;
- else
- return 0;
-#endif
- continue;
- }
- int r = 0;
- if (targetm.omp.device_kind_arch_isa != NULL)
- r = targetm.omp.device_kind_arch_isa (omp_device_kind,
- prop);
- else
- r = strcmp (prop, "cpu") == 0;
- if (r == 0 || (r == -1 && symtab->state != PARSING))
- {
- /* If we are or might be in a target region or
- declare target function, need to take into account
- also offloading values. */
- if (!omp_maybe_offloaded ())
- return 0;
- if (ENABLE_OFFLOADING)
- {
- const char *kinds = omp_offload_device_kind;
- if (omp_offload_device_kind_arch_isa (kinds, prop))
- {
- ret = -1;
- continue;
- }
- }
- return 0;
- }
- else if (r == -1)
- ret = -1;
- /* If kind matches on the host, it still might not match
- in the offloading region. */
- else if (omp_maybe_offloaded ())
- ret = -1;
- }
- break;
- case OMP_TRAIT_DEVICE_ISA:
- if (set == OMP_TRAIT_SET_DEVICE)
- for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
- {
- const char *isa = omp_context_name_list_prop (p);
- if (isa == NULL)
- return 0;
- int r = 0;
- if (targetm.omp.device_kind_arch_isa != NULL)
- r = targetm.omp.device_kind_arch_isa (omp_device_isa,
- isa);
- if (r == 0 || (r == -1 && symtab->state != PARSING))
- {
- /* If isa is valid on the target, but not in the
- current function and current function has
- #pragma omp declare simd on it, some simd clones
- might have the isa added later on. */
- if (r == -1
- && targetm.simd_clone.compute_vecsize_and_simdlen
- && (cfun == NULL || !cfun->after_inlining))
- {
- tree attrs
- = DECL_ATTRIBUTES (current_function_decl);
- if (lookup_attribute ("omp declare simd", attrs))
- {
- ret = -1;
- continue;
- }
- }
- /* If we are or might be in a target region or
- declare target function, need to take into account
- also offloading values. */
- if (!omp_maybe_offloaded ())
- return 0;
- if (ENABLE_OFFLOADING)
- {
- const char *isas = omp_offload_device_isa;
- if (omp_offload_device_kind_arch_isa (isas, isa))
- {
- ret = -1;
- continue;
- }
- }
- return 0;
- }
- else if (r == -1)
- ret = -1;
- /* If isa matches on the host, it still might not match
- in the offloading region. */
- else if (omp_maybe_offloaded ())
- ret = -1;
- }
- break;
- case OMP_TRAIT_USER_CONDITION:
- if (set == OMP_TRAIT_SET_USER)
- for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
- if (OMP_TP_NAME (p) == NULL_TREE)
- {
- if (integer_zerop (OMP_TP_VALUE (p)))
- return 0;
- if (integer_nonzerop (OMP_TP_VALUE (p)))
- break;
- ret = -1;
- }
- break;
- default:
- break;
- }
- }
- }
- return ret;
-}
-#endif
-
/* Return 1 if context selector CTX matches the current OpenMP context, 0
if it does not and -1 if it is unknown and need to be determined later.
Some properties can be checked right away during parsing, others need
return NULL_TREE;
}
-#if 0
-/* Compute *SCORE for context selector CTX. Return true if the score
- would be different depending on whether it is a declare simd clone or
- not. DECLARE_SIMD should be true for the case when it would be
- a declare simd clone. */
-
-static bool
-omp_context_compute_score (tree ctx, score_wide_int *score, bool declare_simd)
-{
- tree selectors
- = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
- bool has_kind = omp_get_context_selector (ctx, OMP_TRAIT_SET_DEVICE,
- OMP_TRAIT_DEVICE_KIND);
- bool has_arch = omp_get_context_selector (ctx, OMP_TRAIT_SET_DEVICE,
- OMP_TRAIT_DEVICE_ARCH);
- bool has_isa = omp_get_context_selector (ctx, OMP_TRAIT_SET_DEVICE,
- OMP_TRAIT_DEVICE_ISA);
- bool ret = false;
- *score = 1;
- for (tree tss = ctx; tss; tss = TREE_CHAIN (tss))
- if (OMP_TSS_TRAIT_SELECTORS (tss) != selectors)
- for (tree ts = OMP_TSS_TRAIT_SELECTORS (tss); ts; ts = TREE_CHAIN (ts))
- {
- tree s = OMP_TS_SCORE (ts);
- if (s && TREE_CODE (s) == INTEGER_CST)
- *score += score_wide_int::from (wi::to_wide (s),
- TYPE_SIGN (TREE_TYPE (s)));
- }
-
- if (selectors || has_kind || has_arch || has_isa)
- {
- int nconstructs = list_length (selectors);
- enum tree_code *constructs = NULL;
- if (nconstructs)
- {
- constructs
- = (enum tree_code *) alloca (nconstructs
- * sizeof (enum tree_code));
- omp_construct_traits_to_codes (selectors, nconstructs, constructs);
- }
- int *scores
- = (int *) alloca ((2 * nconstructs + 2) * sizeof (int));
- if (omp_construct_selector_matches (constructs, nconstructs, scores)
- == 2)
- ret = true;
- int b = declare_simd ? nconstructs + 1 : 0;
- if (scores[b + nconstructs] + 4U < score->get_precision ())
- {
- for (int n = 0; n < nconstructs; ++n)
- {
- if (scores[b + n] < 0)
- {
- *score = -1;
- return ret;
- }
- *score += wi::shifted_mask <score_wide_int> (scores[b + n], 1, false);
- }
- if (has_kind)
- *score += wi::shifted_mask <score_wide_int> (scores[b + nconstructs],
- 1, false);
- if (has_arch)
- *score += wi::shifted_mask <score_wide_int> (scores[b + nconstructs] + 1,
- 1, false);
- if (has_isa)
- *score += wi::shifted_mask <score_wide_int> (scores[b + nconstructs] + 2,
- 1, false);
- }
- else /* FIXME: Implement this. */
- gcc_unreachable ();
- }
- return ret;
-}
-#endif
/* Given an omp_variant VARIANT, compute VARIANT->score and
VARIANT->scorable.
return construct_context;
}
-/* Class describing a single variant. */
-struct GTY(()) omp_declare_variant_entry {
- /* NODE of the variant. */
- cgraph_node *variant;
- /* Score if not in declare simd clone. */
- score_wide_int score;
- /* Score if in declare simd clone. */
- score_wide_int score_in_declare_simd_clone;
- /* Context selector for the variant. */
- tree ctx;
- /* True if the context selector is known to match already. */
- bool matches;
-};
-
-/* Class describing a function with variants. */
-struct GTY((for_user)) omp_declare_variant_base_entry {
- /* NODE of the base function. */
- cgraph_node *base;
- /* NODE of the artificial function created for the deferred variant
- resolution. */
- cgraph_node *node;
- /* Vector of the variants. */
- vec<omp_declare_variant_entry, va_gc> *variants;
-};
-
-struct omp_declare_variant_hasher
- : ggc_ptr_hash<omp_declare_variant_base_entry> {
- static hashval_t hash (omp_declare_variant_base_entry *);
- static bool equal (omp_declare_variant_base_entry *,
- omp_declare_variant_base_entry *);
-};
-
-hashval_t
-omp_declare_variant_hasher::hash (omp_declare_variant_base_entry *x)
-{
- inchash::hash hstate;
- hstate.add_int (DECL_UID (x->base->decl));
- hstate.add_int (x->variants->length ());
- omp_declare_variant_entry *variant;
- unsigned int i;
- FOR_EACH_VEC_SAFE_ELT (x->variants, i, variant)
- {
- hstate.add_int (DECL_UID (variant->variant->decl));
- hstate.add_wide_int (variant->score);
- hstate.add_wide_int (variant->score_in_declare_simd_clone);
- hstate.add_ptr (variant->ctx);
- hstate.add_int (variant->matches);
- }
- return hstate.end ();
-}
-
-bool
-omp_declare_variant_hasher::equal (omp_declare_variant_base_entry *x,
- omp_declare_variant_base_entry *y)
-{
- if (x->base != y->base
- || x->variants->length () != y->variants->length ())
- return false;
- omp_declare_variant_entry *variant;
- unsigned int i;
- FOR_EACH_VEC_SAFE_ELT (x->variants, i, variant)
- if (variant->variant != (*y->variants)[i].variant
- || variant->score != (*y->variants)[i].score
- || (variant->score_in_declare_simd_clone
- != (*y->variants)[i].score_in_declare_simd_clone)
- || variant->ctx != (*y->variants)[i].ctx
- || variant->matches != (*y->variants)[i].matches)
- return false;
- return true;
-}
-
-static GTY(()) hash_table<omp_declare_variant_hasher> *omp_declare_variants;
-
-struct omp_declare_variant_alt_hasher
- : ggc_ptr_hash<omp_declare_variant_base_entry> {
- static hashval_t hash (omp_declare_variant_base_entry *);
- static bool equal (omp_declare_variant_base_entry *,
- omp_declare_variant_base_entry *);
-};
-
-hashval_t
-omp_declare_variant_alt_hasher::hash (omp_declare_variant_base_entry *x)
-{
- return DECL_UID (x->node->decl);
-}
-
-bool
-omp_declare_variant_alt_hasher::equal (omp_declare_variant_base_entry *x,
- omp_declare_variant_base_entry *y)
-{
- return x->node == y->node;
-}
-
-static GTY(()) hash_table<omp_declare_variant_alt_hasher>
- *omp_declare_variant_alt;
-
-#if 0
-/* Try to resolve declare variant after gimplification. */
-
-static tree
-omp_resolve_late_declare_variant (tree alt)
-{
- cgraph_node *node = cgraph_node::get (alt);
- cgraph_node *cur_node = cgraph_node::get (cfun->decl);
- if (node == NULL
- || !node->declare_variant_alt
- || !cfun->after_inlining)
- return alt;
-
- omp_declare_variant_base_entry entry;
- entry.base = NULL;
- entry.node = node;
- entry.variants = NULL;
- omp_declare_variant_base_entry *entryp
- = omp_declare_variant_alt->find_with_hash (&entry, DECL_UID (alt));
-
- unsigned int i, j;
- omp_declare_variant_entry *varentry1, *varentry2;
- auto_vec <bool, 16> matches;
- unsigned int nmatches = 0;
- FOR_EACH_VEC_SAFE_ELT (entryp->variants, i, varentry1)
- {
- if (varentry1->matches)
- {
- /* This has been checked to be ok already. */
- matches.safe_push (true);
- nmatches++;
- continue;
- }
- switch (omp_context_selector_matches (varentry1->ctx))
- {
- case 0:
- matches.safe_push (false);
- break;
- case -1:
- return alt;
- default:
- matches.safe_push (true);
- nmatches++;
- break;
- }
- }
-
- if (nmatches == 0)
- return entryp->base->decl;
-
- /* A context selector that is a strict subset of another context selector
- has a score of zero. */
- FOR_EACH_VEC_SAFE_ELT (entryp->variants, i, varentry1)
- if (matches[i])
- {
- for (j = i + 1;
- vec_safe_iterate (entryp->variants, j, &varentry2); ++j)
- if (matches[j])
- {
- int r = omp_context_selector_compare (varentry1->ctx,
- varentry2->ctx);
- if (r == -1)
- {
- /* ctx1 is a strict subset of ctx2, ignore ctx1. */
- matches[i] = false;
- break;
- }
- else if (r == 1)
- /* ctx2 is a strict subset of ctx1, remove ctx2. */
- matches[j] = false;
- }
- }
-
- score_wide_int max_score = -1;
- varentry2 = NULL;
- FOR_EACH_VEC_SAFE_ELT (entryp->variants, i, varentry1)
- if (matches[i])
- {
- score_wide_int score
- = (cur_node->simdclone ? varentry1->score_in_declare_simd_clone
- : varentry1->score);
- if (score > max_score)
- {
- max_score = score;
- varentry2 = varentry1;
- }
- }
- return varentry2->variant->decl;
-}
-
-/* Hook to adjust hash tables on cgraph_node removal. */
-
-static void
-omp_declare_variant_remove_hook (struct cgraph_node *node, void *)
-{
- if (!node->declare_variant_alt)
- return;
-
- /* Drop this hash table completely. */
- omp_declare_variants = NULL;
- /* And remove node from the other hash table. */
- if (omp_declare_variant_alt)
- {
- omp_declare_variant_base_entry entry;
- entry.base = NULL;
- entry.node = node;
- entry.variants = NULL;
- omp_declare_variant_alt->remove_elt_with_hash (&entry,
- DECL_UID (node->decl));
- }
-}
-
-/* Try to resolve declare variant, return the variant decl if it should
- be used instead of base, or base otherwise. */
-
-tree
-omp_resolve_declare_variant (tree base)
-{
- tree variant1 = NULL_TREE, variant2 = NULL_TREE;
- if (cfun && (cfun->curr_properties & PROP_gimple_any) != 0)
- return omp_resolve_late_declare_variant (base);
-
- if (omp_has_novariants () == 1)
- return base;
-
- auto_vec <tree, 16> variants;
- auto_vec <bool, 16> defer;
- bool any_deferred = false;
- for (tree attr = DECL_ATTRIBUTES (base); attr; attr = TREE_CHAIN (attr))
- {
- attr = lookup_attribute ("omp declare variant base", attr);
- if (attr == NULL_TREE)
- break;
- if (TREE_CODE (TREE_PURPOSE (TREE_VALUE (attr))) != FUNCTION_DECL)
- continue;
- cgraph_node *node = cgraph_node::get (base);
- /* If this is already a magic decl created by this function,
- don't process it again. */
- if (node && node->declare_variant_alt)
- return base;
- switch (omp_context_selector_matches (TREE_VALUE (TREE_VALUE (attr))))
- {
- case 0:
- /* No match, ignore. */
- break;
- case -1:
- /* Needs to be deferred. */
- any_deferred = true;
- variants.safe_push (attr);
- defer.safe_push (true);
- break;
- default:
- variants.safe_push (attr);
- defer.safe_push (false);
- break;
- }
- }
- if (variants.length () == 0)
- return base;
-
- if (any_deferred)
- {
- score_wide_int max_score1 = 0;
- score_wide_int max_score2 = 0;
- bool first = true;
- unsigned int i;
- tree attr1, attr2;
- omp_declare_variant_base_entry entry;
- entry.base = cgraph_node::get_create (base);
- entry.node = NULL;
- vec_alloc (entry.variants, variants.length ());
- FOR_EACH_VEC_ELT (variants, i, attr1)
- {
- score_wide_int score1;
- score_wide_int score2;
- bool need_two;
- tree ctx = TREE_VALUE (TREE_VALUE (attr1));
- need_two = omp_context_compute_score (ctx, &score1, false);
- if (need_two)
- omp_context_compute_score (ctx, &score2, true);
- else
- score2 = score1;
- if (first)
- {
- first = false;
- max_score1 = score1;
- max_score2 = score2;
- if (!defer[i])
- {
- variant1 = attr1;
- variant2 = attr1;
- }
- }
- else
- {
- if (max_score1 == score1)
- variant1 = NULL_TREE;
- else if (score1 > max_score1)
- {
- max_score1 = score1;
- variant1 = defer[i] ? NULL_TREE : attr1;
- }
- if (max_score2 == score2)
- variant2 = NULL_TREE;
- else if (score2 > max_score2)
- {
- max_score2 = score2;
- variant2 = defer[i] ? NULL_TREE : attr1;
- }
- }
- omp_declare_variant_entry varentry;
- varentry.variant
- = cgraph_node::get_create (TREE_PURPOSE (TREE_VALUE (attr1)));
- varentry.score = score1;
- varentry.score_in_declare_simd_clone = score2;
- varentry.ctx = ctx;
- varentry.matches = !defer[i];
- entry.variants->quick_push (varentry);
- }
-
- /* If there is a clear winner variant with the score which is not
- deferred, verify it is not a strict subset of any other context
- selector and if it is not, it is the best alternative no matter
- whether the others do or don't match. */
- if (variant1 && variant1 == variant2)
- {
- tree ctx1 = TREE_VALUE (TREE_VALUE (variant1));
- FOR_EACH_VEC_ELT (variants, i, attr2)
- {
- if (attr2 == variant1)
- continue;
- tree ctx2 = TREE_VALUE (TREE_VALUE (attr2));
- int r = omp_context_selector_compare (ctx1, ctx2);
- if (r == -1)
- {
- /* The winner is a strict subset of ctx2, can't
- decide now. */
- variant1 = NULL_TREE;
- break;
- }
- }
- if (variant1)
- {
- vec_free (entry.variants);
- return TREE_PURPOSE (TREE_VALUE (variant1));
- }
- }
-
- static struct cgraph_node_hook_list *node_removal_hook_holder;
- if (!node_removal_hook_holder)
- node_removal_hook_holder
- = symtab->add_cgraph_removal_hook (omp_declare_variant_remove_hook,
- NULL);
-
- if (omp_declare_variants == NULL)
- omp_declare_variants
- = hash_table<omp_declare_variant_hasher>::create_ggc (64);
- omp_declare_variant_base_entry **slot
- = omp_declare_variants->find_slot (&entry, INSERT);
- if (*slot != NULL)
- {
- vec_free (entry.variants);
- return (*slot)->node->decl;
- }
-
- *slot = ggc_cleared_alloc<omp_declare_variant_base_entry> ();
- (*slot)->base = entry.base;
- (*slot)->node = entry.base;
- (*slot)->variants = entry.variants;
- tree alt = build_decl (DECL_SOURCE_LOCATION (base), FUNCTION_DECL,
- DECL_NAME (base), TREE_TYPE (base));
- if (DECL_ASSEMBLER_NAME_SET_P (base))
- SET_DECL_ASSEMBLER_NAME (alt, DECL_ASSEMBLER_NAME (base));
- DECL_ARTIFICIAL (alt) = 1;
- DECL_IGNORED_P (alt) = 1;
- TREE_STATIC (alt) = 1;
- tree attributes = DECL_ATTRIBUTES (base);
- if (lookup_attribute ("noipa", attributes) == NULL)
- {
- attributes = tree_cons (get_identifier ("noipa"), NULL, attributes);
- if (lookup_attribute ("noinline", attributes) == NULL)
- attributes = tree_cons (get_identifier ("noinline"), NULL,
- attributes);
- if (lookup_attribute ("noclone", attributes) == NULL)
- attributes = tree_cons (get_identifier ("noclone"), NULL,
- attributes);
- if (lookup_attribute ("no_icf", attributes) == NULL)
- attributes = tree_cons (get_identifier ("no_icf"), NULL,
- attributes);
- }
- DECL_ATTRIBUTES (alt) = attributes;
- DECL_INITIAL (alt) = error_mark_node;
- (*slot)->node = cgraph_node::create (alt);
- (*slot)->node->declare_variant_alt = 1;
- (*slot)->node->create_reference (entry.base, IPA_REF_ADDR);
- omp_declare_variant_entry *varentry;
- FOR_EACH_VEC_SAFE_ELT (entry.variants, i, varentry)
- (*slot)->node->create_reference (varentry->variant, IPA_REF_ADDR);
- if (omp_declare_variant_alt == NULL)
- omp_declare_variant_alt
- = hash_table<omp_declare_variant_alt_hasher>::create_ggc (64);
- *omp_declare_variant_alt->find_slot_with_hash (*slot, DECL_UID (alt),
- INSERT) = *slot;
- return alt;
- }
-
- if (variants.length () == 1)
- return TREE_PURPOSE (TREE_VALUE (variants[0]));
-
- /* A context selector that is a strict subset of another context selector
- has a score of zero. */
- tree attr1, attr2;
- unsigned int i, j;
- FOR_EACH_VEC_ELT (variants, i, attr1)
- if (attr1)
- {
- tree ctx1 = TREE_VALUE (TREE_VALUE (attr1));
- FOR_EACH_VEC_ELT_FROM (variants, j, attr2, i + 1)
- if (attr2)
- {
- tree ctx2 = TREE_VALUE (TREE_VALUE (attr2));
- int r = omp_context_selector_compare (ctx1, ctx2);
- if (r == -1)
- {
- /* ctx1 is a strict subset of ctx2, remove
- attr1 from the vector. */
- variants[i] = NULL_TREE;
- break;
- }
- else if (r == 1)
- /* ctx2 is a strict subset of ctx1, remove attr2
- from the vector. */
- variants[j] = NULL_TREE;
- }
- }
- score_wide_int max_score1 = 0;
- score_wide_int max_score2 = 0;
- bool first = true;
- FOR_EACH_VEC_ELT (variants, i, attr1)
- if (attr1)
- {
- if (variant1)
- {
- score_wide_int score1;
- score_wide_int score2;
- bool need_two;
- tree ctx;
- if (first)
- {
- first = false;
- ctx = TREE_VALUE (TREE_VALUE (variant1));
- need_two = omp_context_compute_score (ctx, &max_score1, false);
- if (need_two)
- omp_context_compute_score (ctx, &max_score2, true);
- else
- max_score2 = max_score1;
- }
- ctx = TREE_VALUE (TREE_VALUE (attr1));
- need_two = omp_context_compute_score (ctx, &score1, false);
- if (need_two)
- omp_context_compute_score (ctx, &score2, true);
- else
- score2 = score1;
- if (score1 > max_score1)
- {
- max_score1 = score1;
- variant1 = attr1;
- }
- if (score2 > max_score2)
- {
- max_score2 = score2;
- variant2 = attr1;
- }
- }
- else
- {
- variant1 = attr1;
- variant2 = attr1;
- }
- }
- /* If there is a disagreement on which variant has the highest score
- depending on whether it will be in a declare simd clone or not,
- punt for now and defer until after IPA where we will know that. */
- return ((variant1 && variant1 == variant2)
- ? TREE_PURPOSE (TREE_VALUE (variant1)) : base);
-}
-#endif
-
-void
-omp_lto_output_declare_variant_alt (lto_simple_output_block *ob,
- cgraph_node *node,
- lto_symtab_encoder_t encoder)
-{
- gcc_assert (node->declare_variant_alt);
-
- omp_declare_variant_base_entry entry;
- entry.base = NULL;
- entry.node = node;
- entry.variants = NULL;
- omp_declare_variant_base_entry *entryp
- = omp_declare_variant_alt->find_with_hash (&entry, DECL_UID (node->decl));
- gcc_assert (entryp);
-
- int nbase = lto_symtab_encoder_lookup (encoder, entryp->base);
- gcc_assert (nbase != LCC_NOT_FOUND);
- streamer_write_hwi_stream (ob->main_stream, nbase);
-
- streamer_write_hwi_stream (ob->main_stream, entryp->variants->length ());
-
- unsigned int i;
- omp_declare_variant_entry *varentry;
- FOR_EACH_VEC_SAFE_ELT (entryp->variants, i, varentry)
- {
- int nvar = lto_symtab_encoder_lookup (encoder, varentry->variant);
- gcc_assert (nvar != LCC_NOT_FOUND);
- streamer_write_hwi_stream (ob->main_stream, nvar);
-
- for (score_wide_int *w = &varentry->score; ;
- w = &varentry->score_in_declare_simd_clone)
- {
- unsigned len = w->get_len ();
- streamer_write_hwi_stream (ob->main_stream, len);
- const HOST_WIDE_INT *val = w->get_val ();
- for (unsigned j = 0; j < len; j++)
- streamer_write_hwi_stream (ob->main_stream, val[j]);
- if (w == &varentry->score_in_declare_simd_clone)
- break;
- }
-
- HOST_WIDE_INT cnt = -1;
- HOST_WIDE_INT i = varentry->matches ? 1 : 0;
- for (tree attr = DECL_ATTRIBUTES (entryp->base->decl);
- attr; attr = TREE_CHAIN (attr), i += 2)
- {
- attr = lookup_attribute ("omp declare variant base", attr);
- if (attr == NULL_TREE)
- break;
-
- if (varentry->ctx == TREE_VALUE (TREE_VALUE (attr)))
- {
- cnt = i;
- break;
- }
- }
-
- gcc_assert (cnt != -1);
- streamer_write_hwi_stream (ob->main_stream, cnt);
- }
-}
-
-void
-omp_lto_input_declare_variant_alt (lto_input_block *ib, cgraph_node *node,
- vec<symtab_node *> nodes)
-{
- gcc_assert (node->declare_variant_alt);
- omp_declare_variant_base_entry *entryp
- = ggc_cleared_alloc<omp_declare_variant_base_entry> ();
- entryp->base = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
- entryp->node = node;
- unsigned int len = streamer_read_hwi (ib);
- vec_alloc (entryp->variants, len);
-
- for (unsigned int i = 0; i < len; i++)
- {
- omp_declare_variant_entry varentry;
- varentry.variant
- = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
- for (score_wide_int *w = &varentry.score; ;
- w = &varentry.score_in_declare_simd_clone)
- {
- unsigned len2 = streamer_read_hwi (ib);
- HOST_WIDE_INT arr[WIDE_INT_MAX_HWIS (1024)];
- gcc_assert (len2 <= WIDE_INT_MAX_HWIS (1024));
- for (unsigned int j = 0; j < len2; j++)
- arr[j] = streamer_read_hwi (ib);
- *w = score_wide_int::from_array (arr, len2, true);
- if (w == &varentry.score_in_declare_simd_clone)
- break;
- }
-
- HOST_WIDE_INT cnt = streamer_read_hwi (ib);
- HOST_WIDE_INT j = 0;
- varentry.ctx = NULL_TREE;
- varentry.matches = (cnt & 1) ? true : false;
- cnt &= ~HOST_WIDE_INT_1;
- for (tree attr = DECL_ATTRIBUTES (entryp->base->decl);
- attr; attr = TREE_CHAIN (attr), j += 2)
- {
- attr = lookup_attribute ("omp declare variant base", attr);
- if (attr == NULL_TREE)
- break;
-
- if (cnt == j)
- {
- varentry.ctx = TREE_VALUE (TREE_VALUE (attr));
- break;
- }
- }
- gcc_assert (varentry.ctx != NULL_TREE);
- entryp->variants->quick_push (varentry);
- }
- if (omp_declare_variant_alt == NULL)
- omp_declare_variant_alt
- = hash_table<omp_declare_variant_alt_hasher>::create_ggc (64);
- *omp_declare_variant_alt->find_slot_with_hash (entryp, DECL_UID (node->decl),
- INSERT) = entryp;
-}
-
/* Comparison function for sorting routines, to sort OpenMP metadirective
variants by decreasing score. */
}
}
-#include "gt-omp-general.h"