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

Chi-Chun, Chen via All-commits all-commits at lists.llvm.org
Mon Sep 14 13:45:23 PDT 2026


  Branch: refs/heads/users/cchen/flang-metadirective-loop-reachable-paths
  Home:   https://github.com/llvm/llvm-project
  Commit: 25598f883213ef247ffc573fc7b430818800ff82
      https://github.com/llvm/llvm-project/commit/25598f883213ef247ffc573fc7b430818800ff82
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: 0a9289712c4605bf7cb44bfb7dd64e2202108ba3
      https://github.com/llvm/llvm-project/commit/0a9289712c4605bf7cb44bfb7dd64e2202108ba3
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: a5ac9dc5a144bca19a2e48444ad5e06f8676fa67
      https://github.com/llvm/llvm-project/commit/a5ac9dc5a144bca19a2e48444ad5e06f8676fa67
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: 4c660cdcc1b1818bca2f9e4ca8be502b305a4416
      https://github.com/llvm/llvm-project/commit/4c660cdcc1b1818bca2f9e4ca8be502b305a4416
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: 1d54cac2a5df59a0b6304887c3f0e8da1631ebf8
      https://github.com/llvm/llvm-project/commit/1d54cac2a5df59a0b6304887c3f0e8da1631ebf8
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: b41f01379d9f62713975e8a2f73a02aa6877a095
      https://github.com/llvm/llvm-project/commit/b41f01379d9f62713975e8a2f73a02aa6877a095
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 Sep 2026)

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

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


  Commit: af2ad4bf498951dd9ebd312cf4b5a3e377352def
      https://github.com/llvm/llvm-project/commit/af2ad4bf498951dd9ebd312cf4b5a3e377352def
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: 38a249923841eb5fdef335c5de12f6afac755704
      https://github.com/llvm/llvm-project/commit/38a249923841eb5fdef335c5de12f6afac755704
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: ba70b58cfa9f97b61be5caf146623d7c304f602b
      https://github.com/llvm/llvm-project/commit/ba70b58cfa9f97b61be5caf146623d7c304f602b
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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: 4cecaff63e99a22d7c419bd1008d325474f33483
      https://github.com/llvm/llvm-project/commit/4cecaff63e99a22d7c419bd1008d325474f33483
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-14 (Mon, 14 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.


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

  Changed paths:
    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-device-kind.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 OpenMP variant ranking and reachability

Incorrect scores and premature candidate rejection can change lowering
selection or suppress required metadirective loop diagnostics.

Preserve full score values and context-dependent device weights, retain
paths distinguished by those weights, and let runtime conditions satisfy
match_any despite unknown static properties.


Compare: https://github.com/llvm/llvm-project/compare/22302d52b6a1...7520190aeef4

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