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

Chi-Chun, Chen via All-commits all-commits at lists.llvm.org
Mon Sep 21 23:24:04 PDT 2026


  Branch: refs/heads/users/cchen/flang-metadirective-loop-reachable-paths
  Home:   https://github.com/llvm/llvm-project
  Commit: 2b4a461725bd60c8c007f67561266336715bd02b
      https://github.com/llvm/llvm-project/commit/2b4a461725bd60c8c007f67561266336715bd02b
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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: 59b41983649c45ccbadf5d8c57cce9acd33a8206
      https://github.com/llvm/llvm-project/commit/59b41983649c45ccbadf5d8c57cce9acd33a8206
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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: fe2db482097bf178331e5aa93bb99bd409e3fecb
      https://github.com/llvm/llvm-project/commit/fe2db482097bf178331e5aa93bb99bd409e3fecb
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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

  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: 0da46f182aa3e67790241a3ad5f07f1794edfb95
      https://github.com/llvm/llvm-project/commit/0da46f182aa3e67790241a3ad5f07f1794edfb95
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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

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


  Commit: d6c762fa7efb1bc0e3524d0c56b3f294cf911239
      https://github.com/llvm/llvm-project/commit/d6c762fa7efb1bc0e3524d0c56b3f294cf911239
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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: 6ac00fa75b303328681434a704f562787b509165
      https://github.com/llvm/llvm-project/commit/6ac00fa75b303328681434a704f562787b509165
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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/test/Semantics/OpenMP/metadirective-construct-paths.f90

  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: 32a842c0a59586821dbc3dea76c92de71b7b44b0
      https://github.com/llvm/llvm-project/commit/32a842c0a59586821dbc3dea76c92de71b7b44b0
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 Sep 2026)

  Changed paths:
    M flang/include/flang/Semantics/openmp-utils.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/lib/Semantics/openmp-utils.cpp
    M flang/test/Lower/OpenMP/metadirective-construct.f90
    M flang/test/Lower/OpenMP/metadirective-target-boundary.f90
    M flang/test/Semantics/OpenMP/metadirective-construct-paths.f90

  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: 87a6f66136650cb0714201148db6f650e77dfe08
      https://github.com/llvm/llvm-project/commit/87a6f66136650cb0714201148db6f650e77dfe08
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 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: 8c6b303d4f3aab64db9ef9374533b957ad3d62ed
      https://github.com/llvm/llvm-project/commit/8c6b303d4f3aab64db9ef9374533b957ad3d62ed
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-22 (Tue, 22 Sep 2026)

  Changed paths:
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/test/Semantics/OpenMP/metadirective-construct-paths.f90

  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.


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

  Changed paths:
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/test/Semantics/OpenMP/metadirective-construct-paths.f90

  Log Message:
  -----------
  Count all enclosing leaves in reachable paths

Reachability must use the same construct positions and depth as lowering
when ranking metadirective replacements. Count source constructs without
selector traits, including leaves of combined directives, while keeping
NOTHING transparent.

Add regressions for actual and dynamically selected TASK regions and
DISTRIBUTE within TEAMS DISTRIBUTE PARALLEL DO.


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

  Changed paths:
    A flang/test/Driver/bbc-openmp-target-context.f90
    M flang/tools/bbc/bbc.cpp

  Log Message:
  -----------
  Set bbc target context for semantics


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

  Changed paths:
    M flang/include/flang/Semantics/openmp-utils.h
    M flang/lib/Semantics/check-omp-variant.cpp
    M flang/lib/Semantics/openmp-utils.cpp
    M flang/test/Semantics/OpenMP/metadirective-construct-paths.f90

  Log Message:
  -----------
  Share construct contexts for variant reachability

Use AppendDirectiveContextTraits when building reachable directive paths
so semantic checks and lowering apply the same construct-context rules.
This excludes informational directives such as ASSUME while retaining
executable loop transformations and the source order of combined constructs.

Make AppendConstructTraitsForDirective private again and add semantic
tests for TILE, UNROLL, ASSUME, and TEAMS DISTRIBUTE PARALLEL DO. These
complement the existing lowering tests. The ASSUME case detects the old
collector counting an extra position and skipping a required diagnostic.


Compare: https://github.com/llvm/llvm-project/compare/5d0595161f6d...dd713d4a7165

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