================
@@ -313,91 +333,78 @@ bool llvm::omp::isVariantApplicableInContext(
static APInt getVariantMatchScore(const VariantMatchInfo &VMI,
const OMPContext &Ctx,
SmallVectorImpl<unsigned> &ConstructMatches)
{
- APInt Score(64, 1);
-
- unsigned NoConstructTraits = VMI.ConstructTraits.size();
- for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
- TraitProperty Property = TraitProperty(Bit);
- // If there is a user score attached, use it.
- if (VMI.ScoreMap.count(Property)) {
- const APInt &UserScore = VMI.ScoreMap.lookup(Property);
- assert(UserScore.uge(0) && "Expect non-negative user scores!");
- Score += UserScore.getZExtValue();
- continue;
- }
+ APInt Score(1, 1);
+
+ // A sum of valid scores can exceed the width of any individual score.
+ // Retain all active bits and allow one more bit for each addition's carry.
+ auto AddScore = [&](const APInt &Value) {
+ unsigned Width = std::max(Score.getActiveBits(), Value.getActiveBits()) +
1;
+ Score = Score.zextOrTrunc(Width);
+ Score += Value.zextOrTrunc(Width);
+ };
+ auto AddPowerOfTwo = [&](unsigned Exponent) {
+ AddScore(APInt::getOneBitSet(Exponent + 1, Exponent));
+ };
- switch (getOpenMPContextTraitSetForProperty(Property)) {
- case TraitSet::construct:
- // We handle the construct traits later via the VMI.ConstructTraits
- // container.
- continue;
- case TraitSet::implementation:
- // No effect on the score (implementation defined).
- continue;
- case TraitSet::user:
- // No effect on the score.
- continue;
- case TraitSet::device:
- // Handled separately below.
- break;
- case TraitSet::target_device:
- // TODO: Handling separately.
- break;
- case TraitSet::invalid:
- llvm_unreachable("Unknown trait set is not to be used!");
+ unsigned NoConstructTraits = Ctx.ConstructTraits.size();
----------------
MattPD wrote:
Rebasing this PR onto https://github.com/llvm/llvm-project/pull/233480 makes
sense. I'll recheck my Flang and Clang TARGET-boundary reproducers after the
rebase.
https://github.com/llvm/llvm-project/pull/231668
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits