[flang-commits] [flang] [flang][OpenMP] declare variant (PR #204345)
Abid Qadeer via flang-commits
flang-commits at lists.llvm.org
Wed Jun 17 07:36:51 PDT 2026
abidh wrote:
Heads-up: I have been actively working on declare variant as well, with the explicit goal of sharing the context-selector matching code with metadirective. Both features are really two halves of the same machinery — building a `VariantMatchInfo` from the match/when selector and resolving it against an OMPContext (enclosing construct traits, device/implementation traits, scoring, match_any/none, etc.) via the LLVM OpenMP `getBestVariantMatchForContext` infrastructure.
Looking at this PR, I don't think the current approach is the right direction, mainly because it reimplements selector matching by hand and bypasses that shared infrastructure. A few consequences that I think are structural rather than fixable in review:
- Matching only understands construct and user={condition} (no scoring, no device/implementation/target_device, no match_any/none), and it compares a single directive against a single construct trait, so combined selectors like construct={target teams} and proper enclosing-construct semantics don't work.
- Resolution is wired to a hardcoded {parallel, teams, dispatch} set and only rewrites direct CallStmt children of the construct body, so calls nested more deeply, or under other constructs, aren't handled.
- Variant calls are synthesized as () -> () functions, which drops all arguments/results for any non-trivial procedure (the tests only exercise argument-less subroutines).
We have a series in progress that hoists the shared match-info construction into Semantics (reused by metadirective), records the match selector so it round-trips through module files, and resolves variants at the call site using the common matching path. I'd suggest we coordinate so we converge on a single shared implementation rather than two divergent ones.
https://github.com/llvm/llvm-project/pull/204345
More information about the flang-commits
mailing list