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

Chi-Chun, Chen via All-commits all-commits at lists.llvm.org
Fri Sep 18 16:19:26 PDT 2026


  Branch: refs/heads/users/cchen/flang-metadirective-loop-reachable-paths
  Home:   https://github.com/llvm/llvm-project
  Commit: 6dab091cdefa9734e954006caaf7bc4d12acd179
      https://github.com/llvm/llvm-project/commit/6dab091cdefa9734e954006caaf7bc4d12acd179
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 35d4cc455312a3c2137805fe569fadebd382612d
      https://github.com/llvm/llvm-project/commit/35d4cc455312a3c2137805fe569fadebd382612d
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: e00df19b29d7195ccaf33ea33f58bb23fabd5cfe
      https://github.com/llvm/llvm-project/commit/e00df19b29d7195ccaf33ea33f58bb23fabd5cfe
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 82ae8f823441dcc56ccd4c9bfc5fe19db1389b4c
      https://github.com/llvm/llvm-project/commit/82ae8f823441dcc56ccd4c9bfc5fe19db1389b4c
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 7b27b057a482bbce2b1060bff02853dc2a4972ca
      https://github.com/llvm/llvm-project/commit/7b27b057a482bbce2b1060bff02853dc2a4972ca
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 22a9b0c1061ccb5d3aebc043a30fa1367a03c431
      https://github.com/llvm/llvm-project/commit/22a9b0c1061ccb5d3aebc043a30fa1367a03c431
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 57a328a558352a9d5577a42395c5634b25cf0f8b
      https://github.com/llvm/llvm-project/commit/57a328a558352a9d5577a42395c5634b25cf0f8b
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: c951cdabe5ddb27799e33448473dd00fe2af7aa8
      https://github.com/llvm/llvm-project/commit/c951cdabe5ddb27799e33448473dd00fe2af7aa8
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 609668ca265a41836451640f6bb01e23ec2fd334
      https://github.com/llvm/llvm-project/commit/609668ca265a41836451640f6bb01e23ec2fd334
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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: 9dd52517d5ba6c41a9a206f2154a183937c7552a
      https://github.com/llvm/llvm-project/commit/9dd52517d5ba6c41a9a206f2154a183937c7552a
  Author: Chi-Chun, Chen <chichun.chen at hpe.com>
  Date:   2026-09-18 (Fri, 18 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.


Compare: https://github.com/llvm/llvm-project/compare/7520190aeef4...9dd52517d5ba

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