Files
clang-p2996/flang/test/Lower/OpenMP/FIR/master.f90
Tom Eccles 1f1e0948f2 [flang] run CFG conversion on omp reduction declare ops (#84953)
Most FIR passes only look for FIR operations inside of functions (either
because they run only on func.func or they run on the module but iterate
over functions internally). But there can also be FIR operations inside
of fir.global, some OpenMP and OpenACC container operations.

This has worked so far for fir.global and OpenMP reductions because they
only contained very simple FIR code which doesn't need most passes to be
lowered into LLVM IR. I am not sure how OpenACC works.

In the long run, I hope to see a more systematic approach to making sure
that every pass runs on all of these container operations. I will write
an RFC for this soon.

In the meantime, this pass duplicates the CFG conversion pass to also
run on omp reduction operations. This is similar to how the
AbstractResult pass is already duplicated for fir.global operations.

OpenMP array reductions 2/6
Previous PR: https://github.com/llvm/llvm-project/pull/84952
Next PR: https://github.com/llvm/llvm-project/pull/84954

---------

Co-authored-by: Mats Petersson <mats.petersson@arm.com>
2024-03-20 09:47:49 +00:00

101 lines
2.9 KiB
Fortran

!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion-on-func-opt | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect"
!===============================================================================
! parallel construct with function call which has master construct internally
!===============================================================================
!FIRDialect-LABEL: func @_QPomp_master
subroutine omp_master()
!OMPDialect: omp.master {
!$omp master
!FIRDialect: fir.call @_QPmaster() {{.*}}: () -> ()
call master()
!OMPDialect: omp.terminator
!$omp end master
end subroutine omp_master
!FIRDialect-LABEL: func @_QPparallel_function_master
subroutine parallel_function_master()
!OMPDialect: omp.parallel {
!$omp parallel
!FIRDialect: fir.call @_QPfoo() {{.*}}: () -> ()
call foo()
!OMPDialect: omp.terminator
!$omp end parallel
end subroutine parallel_function_master
!===============================================================================
! master construct nested inside parallel construct
!===============================================================================
!FIRDialect-LABEL: func @_QPomp_parallel_master
subroutine omp_parallel_master()
!OMPDialect: omp.parallel {
!$omp parallel
!FIRDialect: fir.call @_QPparallel() {{.*}}: () -> ()
call parallel()
!OMPDialect: omp.master {
!$omp master
!FIRDialect: fir.call @_QPparallel_master() {{.*}}: () -> ()
call parallel_master()
!OMPDialect: omp.terminator
!$omp end master
!OMPDialect: omp.terminator
!$omp end parallel
end subroutine omp_parallel_master
!===============================================================================
! master construct nested inside parallel construct with conditional flow
!===============================================================================
!FIRDialect-LABEL: func @_QPomp_master_parallel
subroutine omp_master_parallel()
integer :: alpha, beta, gama
alpha = 4
beta = 5
gama = 6
!OMPDialect: omp.master {
!$omp master
!FIRDialect: %{{.*}} = fir.load %{{.*}}
!FIRDialect: %{{.*}} = fir.load %{{.*}}
!FIRDialect: %[[RESULT:.*]] = arith.cmpi sge, %{{.*}}, %{{.*}}
!FIRDialect: fir.if %[[RESULT]] {
if (alpha .ge. gama) then
!OMPDialect: omp.parallel {
!$omp parallel
!FIRDialect: fir.call @_QPinside_if_parallel() {{.*}}: () -> ()
call inside_if_parallel()
!OMPDialect: omp.terminator
!$omp end parallel
!FIRDialect: %{{.*}} = fir.load %{{.*}}
!FIRDialect: %{{.*}} = fir.load %{{.*}}
!FIRDialect: %{{.*}} = arith.addi %{{.*}}, %{{.*}}
!FIRDialect: fir.store %{{.*}} to %{{.*}}
beta = alpha + gama
end if
!FIRDialect: else
!OMPDialect: omp.terminator
!$omp end master
end subroutine omp_master_parallel