[mlir] Update Ch-2.md (#121379)
[llvm-project.git] / flang / test / Lower / OpenMP / flush.f90
blob8438fdba4ee4c2a3daa845ab6f2f5602a68de259
1 ! This test checks lowering of OpenMP Flush Directive.
3 !RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
5 !CHECK-LABEL: func.func @_QPflush_standalone
6 !CHECK-SAME: %[[ARG_A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"}, %[[ARG_B:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}, %[[ARG_C:.*]]: !fir.ref<i32> {fir.bindc_name = "c"})
7 subroutine flush_standalone(a, b, c)
8 integer, intent(inout) :: a, b, c
10 !CHECK: %[[A:.*]]:2 = hlfir.declare %[[ARG_A]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFflush_standaloneEa"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
11 !CHECK: %[[B:.*]]:2 = hlfir.declare %[[ARG_B]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFflush_standaloneEb"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
12 !CHECK: %[[C:.*]]:2 = hlfir.declare %[[ARG_C]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFflush_standaloneEc"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
13 !CHECK: omp.flush(%[[A]]#1, %[[B]]#1, %[[C]]#1 : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
14 !CHECK: omp.flush
15 !$omp flush(a,b,c)
16 !$omp flush
18 end subroutine flush_standalone
20 !CHECK-LABEL: func.func @_QPflush_parallel
21 !CHECK-SAME: %[[ARG_A:.*]]: !fir.ref<i32> {fir.bindc_name = "a"}, %[[ARG_B:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}, %[[ARG_C:.*]]: !fir.ref<i32> {fir.bindc_name = "c"})
22 subroutine flush_parallel(a, b, c)
23 integer, intent(inout) :: a, b, c
24 !CHECK: %[[A:.*]]:2 = hlfir.declare %[[ARG_A]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFflush_parallelEa"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
25 !CHECK: %[[B:.*]]:2 = hlfir.declare %[[ARG_B]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFflush_parallelEb"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
26 !CHECK: %[[C:.*]]:2 = hlfir.declare %[[ARG_C]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFflush_parallelEc"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
28 !$omp parallel
29 !CHECK: omp.parallel
30 !CHECK: omp.flush(%[[A]]#1, %[[B]]#1, %[[C]]#1 : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
31 !CHECK: omp.flush
32 !$omp flush(a,b,c)
33 !$omp flush
35 !CHECK: %[[A_VAL:.*]] = fir.load %[[A]]#0 : !fir.ref<i32>
36 !CHECK: %[[B_VAL:.*]] = fir.load %[[B]]#0 : !fir.ref<i32>
37 !CHECK: %[[C_VAL:.*]] = arith.addi %[[A_VAL]], %[[B_VAL]] : i32
38 !CHECK: hlfir.assign %[[C_VAL]] to %[[C]]#0 : i32, !fir.ref<i32>
39 c = a + b
41 !CHECK: omp.terminator
42 !$omp END parallel
44 end subroutine flush_parallel