[all-commits] [llvm/llvm-project] b4782b: [clang][flang][OpenMP] Fix context selector matchi...

Chi-Chun, Chen via All-commits all-commits at lists.llvm.org
Fri Sep 18 11:08:45 PDT 2026


  Branch: refs/heads/users/cchen/openmp-variant-matching-scoring
  Home:   https://github.com/llvm/llvm-project
  Commit: b4782b36c19749fb3f9df1ecec17d3812d91fb04
      https://github.com/llvm/llvm-project/commit/b4782b36c19749fb3f9df1ecec17d3812d91fb04
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 Sep 2026)

  Changed paths:
    M clang/lib/AST/OpenMPClause.cpp
    M clang/lib/Sema/SemaOpenMP.cpp
    M clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
    A clang/test/OpenMP/declare_variant_scoring.c
    A clang/test/OpenMP/dispatch_variant_matching.c
    M flang/lib/Lower/OpenMP/Utils.cpp
    M flang/lib/Lower/OpenMP/Utils.h
    M flang/lib/Semantics/openmp-utils.cpp
    M flang/test/Lower/OpenMP/declare-variant-construct.f90
    M flang/test/Lower/OpenMP/metadirective-device-kind.f90
    M flang/test/Lower/OpenMP/metadirective-implementation.f90
    A flang/test/Lower/OpenMP/metadirective-target-boundary.f90
    M flang/test/Lower/OpenMP/metadirective-user.f90
    A flang/test/Lower/OpenMP/variant-scoring-any-sections.f90
    M llvm/include/llvm/Frontend/OpenMP/OMPContext.h
    M llvm/lib/Frontend/OpenMP/OMPContext.cpp
    M llvm/unittests/Frontend/OpenMPContextTest.cpp

  Log Message:
  -----------
  [clang][flang][OpenMP] Fix context selector matching and scoring

Incorrect context selector matching and scoring can select the wrong
variant function or metadirective replacement.

Compute device-selector weights from the enclosing construct-context
depth. For example, inside a `parallel` region:

| Selector                 | Before | After |
| ------------------------ | ------ | ----- |
| `device={kind(cpu)}`      | 2      | 3     |
| `construct={parallel}`   | 2      | 2     |

Previously, the incorrect tie allowed candidate order to determine the
winner. The device selector now receives the higher score.

Track enclosing constructs even when they have no corresponding selector
property. Stop at and include the innermost `target`, or retain the full
enclosing context when there is no `target`. Exclude `section` separators:
counting the optional first `section` directive would change scores for
equivalent code.

Use the highest-scoring ordered construct match, count each selector's
score once, and use arbitrary-width arithmetic to avoid overflow.

Apply strict-subset zeroing before selecting the highest score:

```text
compatible = candidates matching the context
for each candidate in compatible:
  if candidate is a strict subset of another compatible candidate:
    score[candidate] = 0
  else:
    score[candidate] = compute_score(candidate, context)
select the first maximum-score candidate, or none if compatible is empty
```

For example, consider these two matching selectors:

```text
A: implementation={vendor(score(100): llvm)}
B: implementation={vendor(score(1): llvm)}, user={condition(1)}
```

A has an unadjusted score of 101, while B scores 2. However, A is a strict
subset of B, so A's final score is zero and B wins. Subset checks must
therefore apply even when the unadjusted scores differ.

Preserve construct order and property identity in subset comparisons,
and treat `kind(any)` as an absent kind selector. Retain unknown properties
and their selector scores for `match_any` and `match_none`. Apply the same
ranking rules to Flang's dynamic conditions and implicit `nothing`.

Add shared-context unit tests and Clang C/C++ and Flang regression tests.
This separates the matching and scoring fixes from the Flang lowering
work in #219014.

Assisted with Codex.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list