[all-commits] [llvm/llvm-project] 5a3571: [flang][OpenMP] Track reachable metadirective repl...

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


  Branch: refs/heads/users/cchen/flang-metadirective-loop-reachable-paths
  Home:   https://github.com/llvm/llvm-project
  Commit: 5a3571228a7f108874b082ae3adfde5abb41c393
      https://github.com/llvm/llvm-project/commit/5a3571228a7f108874b082ae3adfde5abb41c393
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/include/flang/Semantics/openmp-utils.h
    M flang/lib/Semantics/check-omp-structure.cpp
    M flang/lib/Semantics/check-omp-structure.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/lib/Semantics/openmp-utils.cpp
    A flang/test/Semantics/OpenMP/metadirective-loop-applicability-apply.f90
    A flang/test/Semantics/OpenMP/metadirective-loop-applicability-openmp-60.f90
    M flang/test/Semantics/OpenMP/metadirective-loop-applicability.f90

  Log Message:
  -----------
  [flang][OpenMP] Track reachable metadirective replacement paths

The existing semantic checks can validate loop-associated directives in a
METADIRECTIVE against the following loop, but they do not model how the
METADIRECTIVE chooses among its replacements.

Today each WHEN is considered independently: if its selector can match, its
replacement is checked. Selection instead ranks all applicable candidates as
a set. An unguarded higher-ranked candidate makes lower-ranked candidates
unreachable, while a dynamically guarded candidate leaves them reachable
when its condition is false. Treating both cases alike can diagnose loop
requirements on a replacement that can never be selected.

The selected replacement can also affect later selection. Its directive
contributes to the construct context seen by a nested metadirective. The
checker currently retains only syntactic nesting, so nested construct
selectors cannot observe a directive selected by an enclosing
metadirective.

For example, consider an enclosing dynamic choice and a nested construct
selector:

    outer: when(user={condition(flag)}: target) default(parallel)
    inner: when(construct={parallel}: simd) default(nothing)

The enclosing selection creates two mutually exclusive contexts:

                         outer metadirective
                        /                     \
                    flag=true              flag=false
                       |                       |
                    TARGET                 PARALLEL
                       |                       |
            construct={parallel}   construct={parallel}
                   no match                 match
                                               |
                                              SIMD

Dropping selected directives misses the match on the PARALLEL path.
Flattening both paths would instead make the nested selector observe TARGET
and PARALLEL together, a construct context that can never occur.

This PR models each possible selection outcome as a reachable directive path.
For each enclosing path, it uses the existing candidate ranking to retain only
replacements that can win after static and dynamic conditions are considered.
It runs loop checks only for directive specifications present on at least one
reachable path, and propagates the same reachability through APPLY.

Each path is extended with the selected directive while walking its associated
loop or begin/end region. This lets nested construct selectors observe both
syntactic and selected enclosing constructs. The selected context is removed
at its association boundary so it cannot affect later constructs.

When a selector cannot be modeled, all replacements are conservatively
retained so error recovery does not suppress required checks. To control path
growth, this PR collects the construct selectors in the program unit and
merges only paths that none of those selectors can distinguish.

Add coverage for ranked static and dynamic candidates, implicit NOTHING,
nested standalone and begin/end metadirectives, non-NOTHING fallbacks,
context lifetime, and APPLY reachability.

Assisted with codex.


  Commit: e3d0307b4e999c80ce6fee12b0deeca177fe2fe9
      https://github.com/llvm/llvm-project/commit/e3d0307b4e999c80ce6fee12b0deeca177fe2fe9
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/lib/Semantics/check-omp-structure.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/test/Semantics/OpenMP/metadirective-loop-applicability-openmp-60.f90
    M flang/test/Semantics/OpenMP/metadirective-loop-applicability.f90

  Log Message:
  -----------
  Fix metadirective reachable path boundaries

Stop construct trait paths at the innermost target and retain the implicit
nothing fallback during unsupported-selector recovery.

Add coverage for actual and selected target boundaries and for nested
metadirectives reached through implicit fallback.


  Commit: 29d468efdac4f4b0193eb77dcd113703bf769603
      https://github.com/llvm/llvm-project/commit/29d468efdac4f4b0193eb77dcd113703bf769603
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/test/Semantics/OpenMP/metadirective-loop-applicability.f90
    A flang/test/Semantics/OpenMP/metadirective-match-any-paths.f90
    A flang/test/Semantics/OpenMP/metadirective-ordered-paths.f90
    M llvm/lib/Frontend/OpenMP/OMPContext.cpp
    M llvm/unittests/Frontend/OpenMPContextTest.cpp

  Log Message:
  -----------
  Fix extension matching and reachable path merging

Metadirective semantic checking relies on ranked selection to decide which
replacements need validation. With match_any and match_none, a selector can
remain applicable even when some construct traits are absent. The existing
matching and path-merging assumptions do not fully account for this, so
ranking can crash or discard a reachable replacement, allowing invalid loop
nests to pass unchecked.

Make applicability, scoring, and reachable-path merging agree on what these
matching extensions can observe. Preserve enough construct context to rank
partially matching selectors and distinguish paths whose nesting changes
the selected replacement. That context must also remain visible inside a
BLOCK associated with a selected directive, so nested metadirectives are
checked against the context in which they can execute.


  Commit: b7b55b09eeea27455c37e2e358779f4e6541122c
      https://github.com/llvm/llvm-project/commit/b7b55b09eeea27455c37e2e358779f4e6541122c
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/lib/Semantics/check-omp-structure.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/test/Semantics/OpenMP/metadirective-loop-applicability.f90
    M llvm/lib/Frontend/OpenMP/OMPContext.cpp

  Log Message:
  -----------
  Remove redundant handling, improve style, and add documentation


  Commit: 7b1ee06bf87a8b01016b732be3a9df78efe50e60
      https://github.com/llvm/llvm-project/commit/7b1ee06bf87a8b01016b732be3a9df78efe50e60
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/include/flang/Semantics/openmp-utils.h
    M flang/lib/Lower/OpenMP/OpenMP.cpp
    M flang/lib/Semantics/check-omp-structure.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/lib/Semantics/openmp-utils.cpp
    A flang/test/Lower/OpenMP/Todo/metadirective-nothing-apply.f90
    M flang/test/Lower/OpenMP/metadirective-construct.f90
    A flang/test/Semantics/OpenMP/metadirective-construct-paths.f90
    R flang/test/Semantics/OpenMP/metadirective-loop-applicability-apply.f90
    M flang/test/Semantics/OpenMP/metadirective-loop-applicability-openmp-60.f90
    R flang/test/Semantics/OpenMP/metadirective-match-any-paths.f90
    R flang/test/Semantics/OpenMP/metadirective-ordered-paths.f90

  Log Message:
  -----------
  Preserve metadirective selection semantics

Reachability checks can miss required loop diagnostics when selection
drops SIMD traits or treats NOTHING with APPLY as a no-op.

Preserve those distinctions in the shared selection plan so semantic
checks retain reachable transformations and lowering diagnoses
unsupported cases.


  Commit: 2e29ccbbd0c35327ff015995b53b4077620b5cc3
      https://github.com/llvm/llvm-project/commit/2e29ccbbd0c35327ff015995b53b4077620b5cc3
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M llvm/lib/Frontend/OpenMP/OMPContext.cpp

  Log Message:
  -----------
  Simplify construct match scoring


  Commit: 17755921c1ee27a42346d29faa2b8567598c225e
      https://github.com/llvm/llvm-project/commit/17755921c1ee27a42346d29faa2b8567598c225e
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/lib/Lower/OpenMP/Utils.cpp
    M flang/test/Lower/OpenMP/declare-variant-construct.f90

  Log Message:
  -----------
  Preserve SIMD context for variant selection

SIMD selectors cannot match when lowering omits the enclosing SIMD trait.
Collect it so calls inside SIMD and DO SIMD select the correct variant.


  Commit: f1e90900fa1cfd9157cda3cfb1b022b1bf63c5e3
      https://github.com/llvm/llvm-project/commit/f1e90900fa1cfd9157cda3cfb1b022b1bf63c5e3
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/lib/Semantics/check-omp-structure.cpp
    M flang/lib/Semantics/check-omp-structure.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/lib/Semantics/openmp-utils.cpp
    M flang/test/Lower/OpenMP/declare-variant-construct.f90
    M flang/test/Lower/OpenMP/metadirective-implementation.f90
    M flang/test/Lower/OpenMP/metadirective-user.f90
    M flang/test/Semantics/OpenMP/metadirective-construct-paths.f90
    M llvm/lib/Frontend/OpenMP/OMPContext.cpp
    M llvm/unittests/Frontend/OpenMPContextTest.cpp

  Log Message:
  -----------
  Preserve reachable metadirective variants across ranking and scopes

Incorrect candidate scores and stale scope boundaries can suppress required
loop diagnostics or let directives associate with loops outside their region.

Keep pending scopes consistent as directives are consumed, and preserve
candidate scores and highest-valued ordered matches when selecting and
merging reachable paths. Handle unknown properties without aborting ranking.


  Commit: 839abb70937289212bd0acb5d7662d056ed78aef
      https://github.com/llvm/llvm-project/commit/839abb70937289212bd0acb5d7662d056ed78aef
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/include/flang/Semantics/openmp-utils.h
    M flang/lib/Lower/OpenMP/Utils.cpp
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/lib/Semantics/openmp-utils.cpp
    M flang/test/Lower/OpenMP/declare-variant-construct.f90
    M flang/test/Lower/OpenMP/metadirective-construct.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
    M flang/test/Semantics/OpenMP/metadirective-construct-paths.f90
    M llvm/lib/Frontend/OpenMP/OMPContext.cpp

  Log Message:
  -----------
  Respect target boundaries during OpenMP variant lowering

Stop collecting construct traits at the innermost TARGET so lowering
agrees with semantic analysis when selecting metadirective replacements
and DECLARE VARIANT callees.


  Commit: 398137ee50c7291a24752e7411b081c6250382f2
      https://github.com/llvm/llvm-project/commit/398137ee50c7291a24752e7411b081c6250382f2
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-11 (Fri, 11 Sep 2026)

  Changed paths:
    M flang/lib/Semantics/openmp-utils.cpp
    M flang/test/Semantics/OpenMP/metadirective-common.f90

  Log Message:
  -----------
  Reject negative trait scores during metadirective recovery

Reachability analysis can rank candidates before CheckTraitScore diagnoses
invalid scores. A score of -1 wraps the initial unsigned score to zero,
causing selection to dereference a null best candidate.

Treat negative scores as absent during recovery while preserving the
existing diagnostic.


Compare: https://github.com/llvm/llvm-project/compare/df55412c76eb...398137ee50c7

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