[flang-commits] [flang] [flang][OpenMP] Support for nocontext and novariants clauses for dispatch construct (PR #227954)
Sairudra More via flang-commits
flang-commits at lists.llvm.org
Thu Oct 8 05:51:45 PDT 2026
================
@@ -1,39 +1,372 @@
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=51 %s -o - | FileCheck %s --check-prefix=HLFIR
-!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 %s -o - | FileCheck %s --check-prefix=HLFIR
-!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s --check-prefix=HLFIR
-! Dispatch lowers to a no-op omp.dispatch region wrapping the associated call.
-! Variant selection and the nocontext/novariants clauses are added separately;
-! here the call inside the region targets the base procedure unchanged.
+! Variant selection is provided by DECLARE VARIANT with a `construct={dispatch}`
+! match: inside a dispatch region the call to the base procedure `foo_dispatch`
+! is replaced by a call to its variant `foo_variant`. `base_routine` additionally
+! carries a `device={kind(host)}` variant to exercise re-resolution under
+! `nocontext` when more than one variant matches.
module funcs
implicit none
contains
+ !HLFIR-LABEL: func @_QMfuncsPfoo_no_variant
+ subroutine foo_no_variant()
+ end subroutine
+
+ !novariants clause : base & variant subroutines
+ !HLFIR-LABEL: func @_QMfuncsPfoo_variant
+ subroutine foo_variant()
+ print *, "in foo_variant"
+ end subroutine
+
!HLFIR-LABEL: func @_QMfuncsPfoo_dispatch
subroutine foo_dispatch()
+ !$omp declare variant(foo_dispatch:foo_variant) match(construct={dispatch})
print *, "in foo_dispatch"
end subroutine
+ !nocontext clause : base & variant subroutines
+ !HLFIR-LABEL: func @_QMfuncsPdispatch_variant
+ subroutine dispatch_variant()
+ print *, "in dispatch_variant"
+ end subroutine
+
+ !HLFIR-LABEL: func @_QMfuncsPhost_variant
+ subroutine host_variant()
+ print *, "in host_variant"
+ end subroutine
+
+ ! `base_routine` has two variants: `dispatch_variant` matches
+ ! `construct={dispatch}` and `host_variant` matches `device={kind(host)}`.
+ !HLFIR-LABEL: func @_QMfuncsPbase_routine
+ subroutine base_routine()
+ !$omp declare variant(base_routine:dispatch_variant) match(construct={dispatch})
+ !$omp declare variant(base_routine:host_variant) match(device={kind(host)})
----------------
Saieiei wrote:
Thanks, the first pair now works in either declaration order. The other five pairs still depend on the scoring tie: 207/208, 250/251, 262/263 and 340/341 here, and 135/136 in Integration/OpenMP/dispatch.f90. Could they use the same `user={condition(score(2): .true.)}`? With that change, both files pass in either order.
https://github.com/llvm/llvm-project/pull/227954
More information about the flang-commits
mailing list